From f0fc2a8702d03211974e597f2f5df1258e6669cb Mon Sep 17 00:00:00 2001 From: Karl Hallsby Date: Tue, 23 Jun 2020 14:56:20 +0200 Subject: [PATCH] mu: add module --- .github/CODEOWNERS | 2 ++ modules/misc/news.nix | 7 +++++ modules/modules.nix | 1 + modules/programs/mu.nix | 57 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+) create mode 100644 modules/programs/mu.nix diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 128ad52e3..998d1fa5b 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -83,6 +83,8 @@ /modules/programs/mpv.nix @tadeokondrak +/modules/programs/mu.nix @KarlJoad + /modules/programs/ncmpcpp.nix @olmokramer /tests/modules/programs/ncmpcpp @olmokramer /tests/modules/programs/ncmpcpp-linux @olmokramer diff --git a/modules/misc/news.nix b/modules/misc/news.nix index de27a8edc..b64300f5b 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1680,6 +1680,13 @@ in A new module is available: 'programs.pet'. ''; } + + { + time = "2020-09-29T21:21:44+00:00"; + message = '' + A new module is available: 'programs.mu'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 66f66f707..717834302 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -90,6 +90,7 @@ let (loadModule ./programs/mercurial.nix { }) (loadModule ./programs/mpv.nix { }) (loadModule ./programs/msmtp.nix { }) + (loadModule ./programs/mu.nix { }) (loadModule ./programs/ncmpcpp.nix { }) (loadModule ./programs/ne.nix { }) (loadModule ./programs/neomutt.nix { }) diff --git a/modules/programs/mu.nix b/modules/programs/mu.nix new file mode 100644 index 000000000..18c3993a1 --- /dev/null +++ b/modules/programs/mu.nix @@ -0,0 +1,57 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.programs.mu; + + # Used to generate command line arguments that mu can operate with. + genCmdMaildir = path: "--maildir=" + path; + + # Takes the list of accounts with mu.enable = true, and generates a + # command-line flag for initializing the mu database. + myAddresses = let + # List of account sets where mu.enable = true. + muAccounts = + filter (a: a.mu.enable) (attrValues config.accounts.email.accounts); + addrs = map (a: a.address) muAccounts; + # Prefix --my-address= to each account's address with mu.enable. + addMyAddress = map (addr: "--my-address=" + addr) addrs; + in concatStringsSep " " addMyAddress; + +in { + meta.maintainers = [ maintainers.KarlJoad ]; + + options = { + programs.mu = { + enable = mkEnableOption "mu, a maildir indexer and searcher"; + + # No options/config file present for mu, and program author will not be + # adding one soon. See https://github.com/djcb/mu/issues/882 for more + # information about this. + }; + + accounts.email.accounts = mkOption { + type = with types; + attrsOf + (submodule { options.mu.enable = mkEnableOption "mu indexing"; }); + }; + }; + + config = mkIf cfg.enable { + home.packages = [ pkgs.mu ]; + + home.activation.runMuInit = let + maildirOption = genCmdMaildir config.accounts.email.maildirBasePath; + dbLocation = config.xdg.cacheHome + "/mu"; + in hm.dag.entryAfter [ "writeBoundary" ] '' + # If the database directory exists, then `mu init` should NOT be run. + # In theory, mu is the only thing that creates that directory, and it is + # only created during the initial index. + if [[ ! -d "${dbLocation}" ]]; then + $DRY_RUN_CMD mu init ${maildirOption} $VERBOSE_ARG; + fi + ''; + }; +}