fork/home-manager
git clone https://git.julia.blue/fork/home-manager
a8f8f483
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7cfg = config . programs . mu ; 8 9# Used to generate command line arguments that mu can operate with. 10genCmdMaildir = 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. 14myAddresses = let 15# Set of email account sets where mu.enable = true. 16muAccounts = 17filter ( a :a . mu . enable ) ( attrValues config . accounts . . accounts ); 18addrs = map ( a :a . address ) muAccounts ; 19# Construct list of lists containing email aliases, and flatten 20aliases = flatten ( map ( a :a . aliases ) muAccounts ); 21# Prefix --my-address= to each account's address AND all defined aliases 22addMyAddress = map ( addr :"--my-address=" + addr ) ( addrs ++ aliases ); 23in concatStringsSep " " addMyAddress ; 24 25in { 26meta . maintainers = [ maintainers . KarlJoad ]; 27 28options = { 29programs . mu = { 30enable = mkEnableOption "mu, a maildir indexer and searcher" ; 31 32package = 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 39accounts . . accounts = mkOption { 40type = with types ; 41attrsOf 42( submodule { options . mu . enable = mkEnableOption "mu indexing" ; }); 43}; 44}; 45 46config = mkIf cfg . enable { 47home . packages = [ cfg . package ]; 48 49home . activation . runMuInit = let 50maildirOption = genCmdMaildir config . accounts . . maildirBasePath ; 51dbLocation = config . xdg . cacheHome + "/mu" ; 52in 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. 56if [[ ! -d " ${ dbLocation } " ]]; then 57$DRY_RUN_CMD ${ 58getExe cfg . package 59} init ${ maildirOption } ${ myAddresses } $VERBOSE_ARG; 60fi 61'' ; 62}; 63}