From 44f637aa8d933ec682b461877f12125d5857657c Mon Sep 17 00:00:00 2001 From: Atemu Date: Fri, 7 Jul 2023 17:48:48 +0200 Subject: [PATCH 1/2] nixos/paperless: use toShellVars for paperless-manage The homebrewed snippet didn't escape vars properly which is an issue because PAPERLESS_OCR_USER_ARGS requires a JSON string. This also meant a discrepancy between the services' env vars and paperless-manage's. Just use the correctly functioning library function for this instead. --- nixos/modules/services/misc/paperless.nix | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/nixos/modules/services/misc/paperless.nix b/nixos/modules/services/misc/paperless.nix index 8fe628a4088..313d18d72bd 100644 --- a/nixos/modules/services/misc/paperless.nix +++ b/nixos/modules/services/misc/paperless.nix @@ -26,14 +26,11 @@ let lib.mapAttrs (_: toString) cfg.extraConfig ); - manage = - let - setupEnv = lib.concatStringsSep "\n" (mapAttrsToList (name: val: "export ${name}=\"${val}\"") env); - in - pkgs.writeShellScript "manage" '' - ${setupEnv} - exec ${pkg}/bin/paperless-ngx "$@" - ''; + manage = pkgs.writeShellScript "manage" '' + set -o allexport # Export the following env vars + ${lib.toShellVars env} + exec ${pkg}/bin/paperless-ngx "$@" + ''; # Secure the services defaultServiceConfig = { From 2616bb762b6834a2f20109aebab2c29317084469 Mon Sep 17 00:00:00 2001 From: Atemu Date: Sun, 9 Jul 2023 19:47:58 +0200 Subject: [PATCH 2/2] nixos/paperless: explain how to set JSON env vars Co-authored-by: Christian Theune Co-authored-by: Erik Arvstedt --- nixos/modules/services/misc/paperless.nix | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/nixos/modules/services/misc/paperless.nix b/nixos/modules/services/misc/paperless.nix index 313d18d72bd..84c06bae6cd 100644 --- a/nixos/modules/services/misc/paperless.nix +++ b/nixos/modules/services/misc/paperless.nix @@ -169,6 +169,7 @@ in description = lib.mdDoc "Web interface port."; }; + # FIXME this should become an RFC42-style settings attr extraConfig = mkOption { type = types.attrs; default = { }; @@ -177,11 +178,23 @@ in See [the documentation](https://paperless-ngx.readthedocs.io/en/latest/configuration.html) for available options. + + 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"; - }; }; user = mkOption {