Skip to content

Commit

Permalink
Allow to specify a config file with the nixos module
Browse files Browse the repository at this point in the history
  • Loading branch information
eikek committed Feb 10, 2024
1 parent 0a19edc commit 2fd9886
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions nix/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,19 @@ in {
};

docspell-url = mkOption {
type = types.str;
type = types.nullOr types.str;
default = null;
example = "http://localhost:7880";
description = "The base url to the docspell server.";
};

configFile = mkOption {
type = types.nullOr types.path;
default = null;
example = "./docspell-conf.toml";
description = "Config file that can be used to group together multiple options.";
};

watchDirs = mkOption {
type = types.listOf types.str;
description = "The directories to watch for new files.";
Expand Down Expand Up @@ -164,13 +172,29 @@ in {
}
];

argv = builtins.concatLists (builtins.map (a: a.opt)
(builtins.filter (a: a.when) argmap));
globalmap = [
{
when = cfg.verbose;
opt = [ "-vv" ];
}
{
when = cfg.docspell-url != null;
opt = [ "-d" "'${cfg.docspell-url}'" ];
}
{
when = cfg.configFile != null;
opt = [ "-c" "'${cfg.configFile}'" ];
}
];

to_args = m: builtins.concatLists (builtins.map (a: a.opt)
(builtins.filter (a: a.when) m));

argv = builtins.concatStringsSep " " (to_args argmap);
globv = builtins.concatStringsSep " " (to_args globalmap);
dirs = builtins.concatStringsSep " " (builtins.map (d: "'${d}'") cfg.watchDirs);

cmd = "${cfg.package}/bin/dsc " + "-d '${cfg.docspell-url}'"
+ (if cfg.verbose then " -vv " else "") + " watch "
+ (builtins.concatStringsSep " " argv) + " "
+ (builtins.concatStringsSep " " cfg.watchDirs);
cmd = "${cfg.package}/bin/dsc ${globv} watch ${argv} ${dirs}";
in {
description = "Docspell Watch Directory";
after = [ "networking.target" ];
Expand Down

0 comments on commit 2fd9886

Please sign in to comment.