fork/home-manager
git clone https://git.julia.blue/fork/home-manager
05649393
master
1{ config , options , lib , pkgs , ...} : 2 3with lib ; 4 5# TODO: Fix the formatting of the resulting config. 6let 7cfg = config . services . recoll ; 8 9# The key-value generator for Recoll config format. For future references, 10# see the example configuration from the package (i.e., 11# `$out/share/recoll/examples/recoll.conf`). 12mkRecollConfKeyValue = generators . mkKeyValueDefault { 13mkValueString = let mkQuoted = v :''" ${ escape [ ''"'' ] v } "'' ; 14in v : 15if v == true then 16"1" 17else if v == false then 18"0" 19else if isList v then 20concatMapStringsSep " " mkQuoted v 21else 22generators . mkValueStringDefault { } v ; 23} " = " ; 24 25# A modified version of 'lib.generators.toINI' that also accepts top-level 26# attributes as non-attrsets. 27toRecollConf = { listsAsDuplicateKeys ? false } : 28attr : 29let 30toKeyValue = generators . toKeyValue { 31inherit listsAsDuplicateKeys ; 32mkKeyValue = mkRecollConfKeyValue ; 33}; 34mkSectionName = name :strings . escape [ "[" "]" ] name ; 35convert = k :v : 36if isAttrs v then 37'' 38[ ${ mkSectionName k } ] 39'' + toKeyValue v 40else 41toKeyValue { " ${ k } " = v ; }; 42 43# TODO: Improve this chunk of code, pls. 44# There's a possibility of attributes with attrsets overriding other 45# top-level attributes with non-attrsets so we're forcing the attrsets to 46# come last. 47_config = mapAttrsToList convert ( filterAttrs ( k :v :! isAttrs v ) attr ); 48_config' = mapAttrsToList convert ( filterAttrs ( k :v :isAttrs v ) attr ); 49config = _config ++ _config' ; 50in concatStringsSep "\n" config ; 51 52# A specific type for Recoll config format. Taken from `pkgs.formats` 53# implementation from nixpkgs. See the 'Nix-representable formats' from the 54# NixOS manual for more information. 55recollConfFormat = { } :{ 56type = with types ; 57let 58valueType = nullOr ( oneOf [ 59bool 60float 61int 62path 63str 64( attrsOf valueType ) 65( listOf valueType ) 66]) // { 67description = "Recoll config value" ; 68}; 69in attrsOf valueType ; 70 71generate = name :value :pkgs . writeText name ( toRecollConf { } value ); 72}; 73 74# The actual object we're going to use for this module. This is for the sake 75# of consistency (and dogfooding the settings format implementation). 76settingsFormat = recollConfFormat { }; 77in { 78meta . maintainers = [ maintainers . foo-dogsquared ]; 79 80options . services . recoll = { 81enable = mkEnableOption "Recoll file index service" ; 82 83package = mkOption { 84type = types . package ; 85default = pkgs . recoll ; 86defaultText = literalExpression "pkgs.recoll" ; 87description = '' 88Package providing the {command}`recoll` binary. 89'' ; 90example = literalExpression "(pkgs.recoll.override { withGui = false; })" ; 91}; 92 93startAt = mkOption { 94type = types . str ; 95default = "hourly" ; 96example = "00/2:00" ; 97description = '' 98When or how often the periodic update should run. Must be the format 99described from {manpage}`systemd.time(7)`. 100'' ; 101}; 102 103settings = mkOption { 104type = settingsFormat . type ; 105default = { }; 106description = '' 107The configuration to be written at {file}`$RECOLL_CONFDIR/recoll.conf`. 108 109See {manpage}`recoll.conf(5)` for more details about the configuration. 110'' ; 111example = literalExpression '' 112{ 113nocjk = true; 114loglevel = 5; 115topdirs = [ "~/Downloads" "~/Documents" "~/projects" ]; 116 117"~/Downloads" = { 118"skippedNames+" = [ "*.iso" ]; 119}; 120 121"~/projects" = { 122"skippedNames+" = [ "node_modules" "target" "result" ]; 123}; 124} 125'' ; 126}; 127 128configDir = mkOption { 129type = types . str ; 130default = " ${ config . home . homeDirectory } /.recoll" ; 131defaultText = literalExpression "\${config.home.homeDirectory}/.recoll" ; 132example = literalExpression "\${config.xdg.configHome}/recoll" ; 133description = '' 134The directory to contain Recoll configuration files. This will be set 135as {env}`RECOLL_CONFDIR`. 136'' ; 137}; 138}; 139 140config = mkIf cfg . enable { 141assertions = [ 142( lib . hm . assertions . assertPlatform "services.recoll" pkgs 143lib . platforms . linux ) 144]; 145 146home . packages = [ cfg . package ]; 147 148home . sessionVariables = { RECOLL_CONFDIR = cfg . configDir ; }; 149 150home . file . " ${ cfg . configDir } /recoll.conf" . source = 151settingsFormat . generate "recoll-conf- ${ config . home . username } " 152cfg . settings ; 153 154systemd . user . services . recollindex = { 155Unit = { 156Description = "Recoll index update" ; 157Documentation = [ 158"man:recoll" 159"man:recollindex" 160"https://www.lesbonscomptes.com/recoll/usermanual/" 161]; 162}; 163 164Service = { 165ExecStart = " ${ cfg . package } /bin/recollindex" ; 166Environment = [ "RECOLL_CONFDIR= ${ escapeShellArg cfg . configDir } " ]; 167}; 168}; 169 170systemd . user . timers . recollindex = { 171Unit = { 172Description = "Recoll index update" ; 173PartOf = [ "default.target" ]; 174}; 175 176Timer = { 177Persistent = true ; 178OnCalendar = cfg . startAt ; 179}; 180 181Install . WantedBy = [ "timers.target" ]; 182}; 183}; 184}