fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Jian Linmu: add package option (#4325)a8f8f483

master
2.0 KiB63 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7  cfg = config.programs.mu;
8
9  # Used to generate command line arguments that mu can operate with.
10  genCmdMaildir = path: "--maildir=" + path;
11
12  # Takes the list of accounts with mu.enable = true, and generates a
13  # command-line flag for initializing the mu database.
14  myAddresses = let
15    # Set of email account sets where mu.enable = true.
16    muAccounts =
17      filter (a: a.mu.enable) (attrValues config.accounts.email.accounts);
18    addrs = map (a: a.address) muAccounts;
19    # Construct list of lists containing email aliases, and flatten
20    aliases = flatten (map (a: a.aliases) muAccounts);
21    # Prefix --my-address= to each account's address AND all defined aliases
22    addMyAddress = map (addr: "--my-address=" + addr) (addrs ++ aliases);
23  in concatStringsSep " " addMyAddress;
24
25in {
26  meta.maintainers = [ maintainers.KarlJoad ];
27
28  options = {
29    programs.mu = {
30      enable = mkEnableOption "mu, a maildir indexer and searcher";
31
32      package = mkPackageOption pkgs "mu" { };
33
34      # No options/config file present for mu, and program author will not be
35      # adding one soon. See https://github.com/djcb/mu/issues/882 for more
36      # information about this.
37    };
38
39    accounts.email.accounts = mkOption {
40      type = with types;
41        attrsOf
42        (submodule { options.mu.enable = mkEnableOption "mu indexing"; });
43    };
44  };
45
46  config = mkIf cfg.enable {
47    home.packages = [ cfg.package ];
48
49    home.activation.runMuInit = let
50      maildirOption = genCmdMaildir config.accounts.email.maildirBasePath;
51      dbLocation = config.xdg.cacheHome + "/mu";
52    in hm.dag.entryAfter [ "writeBoundary" ] ''
53      # If the database directory exists, then `mu init` should NOT be run.
54      # In theory, mu is the only thing that creates that directory, and it is
55      # only created during the initial index.
56      if [[ ! -d "${dbLocation}" ]]; then
57        $DRY_RUN_CMD ${
58          getExe cfg.package
59        } init ${maildirOption} ${myAddresses} $VERBOSE_ARG;
60      fi
61    '';
62  };
63}