Skip to content

Commit

Permalink
nixos/paperless: convert extraConfig to freeform
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperSandro2000 committed Dec 27, 2023
1 parent 3c92c7f commit f852884
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions nixos/modules/services/misc/paperless.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let
defaultFont = "${pkgs.liberation_ttf}/share/fonts/truetype/LiberationSerif-Regular.ttf";

# Don't start a redis instance if the user sets a custom redis connection
enableRedis = !hasAttr "PAPERLESS_REDIS" cfg.extraConfig;
enableRedis = !(cfg.settings ? PAPERLESS_REDIS);
redisServer = config.services.redis.servers.paperless;

env = {
Expand All @@ -24,9 +24,11 @@ let
PAPERLESS_TIME_ZONE = config.time.timeZone;
} // optionalAttrs enableRedis {
PAPERLESS_REDIS = "unix://${redisServer.unixSocket}";
} // (
lib.mapAttrs (_: toString) cfg.extraConfig
);
} // (lib.mapAttrs (_: s:
if (lib.isAttrs s || lib.isList s) then builtins.toJSON s
else if lib.isBool s then lib.boolToString s
else toString s
) cfg.settings);

manage = pkgs.writeShellScript "manage" ''
set -o allexport # Export the following env vars
Expand Down Expand Up @@ -82,6 +84,7 @@ in

imports = [
(mkRenamedOptionModule [ "services" "paperless-ng" ] [ "services" "paperless" ])
(mkRemovedOptionModule [ "services" "paperless" "extraConfig" ] "services.paperless.extraConfig has been replaced by freeform setting services.paperless.settings")
];

options.services.paperless = {
Expand Down Expand Up @@ -160,9 +163,10 @@ in
description = lib.mdDoc "Web interface port.";
};

# FIXME this should become an RFC42-style settings attr
extraConfig = mkOption {
type = types.attrs;
settings = mkOption {
type = lib.types.submodule {
freeformType = with lib.types; attrsOf (oneOf [ attrs bool int (listOf anything) str path package ]);
};
default = { };
description = lib.mdDoc ''
Extra paperless config options.
Expand All @@ -172,20 +176,15 @@ in
Note that some options such as `PAPERLESS_CONSUMER_IGNORE_PATTERN` expect JSON values. Use `builtins.toJSON` to ensure proper quoting.
'';
example = literalExpression ''
{
PAPERLESS_OCR_LANGUAGE = "deu+eng";
PAPERLESS_DBHOST = "/run/postgresql";
PAPERLESS_CONSUMER_IGNORE_PATTERN = builtins.toJSON [ ".DS_STORE/*" "desktop.ini" ];
PAPERLESS_OCR_USER_ARGS = builtins.toJSON {
optimize = 1;
pdfa_image_compression = "lossless";
};
example = {
PAPERLESS_OCR_LANGUAGE = "deu+eng";
PAPERLESS_DBHOST = "/run/postgresql";
PAPERLESS_CONSUMER_IGNORE_PATTERN = [ ".DS_STORE/*" "desktop.ini" ];
PAPERLESS_OCR_USER_ARGS = {
optimize = 1;
pdfa_image_compression = "lossless";
};
'';
};
};

user = mkOption {
Expand Down

0 comments on commit f852884

Please sign in to comment.