From 310b9fe58d34a4d655778bf561e8fb021e2d4b70 Mon Sep 17 00:00:00 2001 From: Erik Arvstedt Date: Mon, 5 Sep 2022 10:03:59 +0200 Subject: [PATCH 1/2] nixos/paperless: extract variable `pkg` --- nixos/modules/services/misc/paperless.nix | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/nixos/modules/services/misc/paperless.nix b/nixos/modules/services/misc/paperless.nix index b1cf72258d17..c29824ee8345 100644 --- a/nixos/modules/services/misc/paperless.nix +++ b/nixos/modules/services/misc/paperless.nix @@ -3,6 +3,7 @@ with lib; let cfg = config.services.paperless; + pkg = cfg.package; defaultUser = "paperless"; @@ -27,7 +28,7 @@ let setupEnv = lib.concatStringsSep "\n" (mapAttrsToList (name: val: "export ${name}=\"${val}\"") env); in pkgs.writeShellScript "manage" '' ${setupEnv} - exec ${cfg.package}/bin/paperless-ngx "$@" + exec ${pkg}/bin/paperless-ngx "$@" ''; # Secure the services @@ -213,7 +214,7 @@ in description = "Paperless scheduler"; serviceConfig = defaultServiceConfig // { User = cfg.user; - ExecStart = "${cfg.package}/bin/paperless-ngx qcluster"; + ExecStart = "${pkg}/bin/paperless-ngx qcluster"; Restart = "on-failure"; # The `mbind` syscall is needed for running the classifier. SystemCallFilter = defaultServiceConfig.SystemCallFilter ++ [ "mbind" ]; @@ -229,9 +230,9 @@ in # Auto-migrate on first run or if the package has changed versionFile="${cfg.dataDir}/src-version" - if [[ $(cat "$versionFile" 2>/dev/null) != ${cfg.package} ]]; then - ${cfg.package}/bin/paperless-ngx migrate - echo ${cfg.package} > "$versionFile" + if [[ $(cat "$versionFile" 2>/dev/null) != ${pkg} ]]; then + ${pkg}/bin/paperless-ngx migrate + echo ${pkg} > "$versionFile" fi '' + optionalString (cfg.passwordFile != null) '' @@ -241,7 +242,7 @@ in superuserStateFile="${cfg.dataDir}/superuser-state" if [[ $(cat "$superuserStateFile" 2>/dev/null) != $superuserState ]]; then - ${cfg.package}/bin/paperless-ngx manage_superuser + ${pkg}/bin/paperless-ngx manage_superuser echo "$superuserState" > "$superuserStateFile" fi ''; @@ -266,7 +267,7 @@ in description = "Paperless document consumer"; serviceConfig = defaultServiceConfig // { User = cfg.user; - ExecStart = "${cfg.package}/bin/paperless-ngx document_consumer"; + ExecStart = "${pkg}/bin/paperless-ngx document_consumer"; Restart = "on-failure"; }; environment = env; @@ -282,7 +283,7 @@ in User = cfg.user; ExecStart = '' ${pkgs.python3Packages.gunicorn}/bin/gunicorn \ - -c ${cfg.package}/lib/paperless-ngx/gunicorn.conf.py paperless.asgi:application + -c ${pkg}/lib/paperless-ngx/gunicorn.conf.py paperless.asgi:application ''; Restart = "on-failure"; @@ -295,8 +296,8 @@ in CapabilityBoundingSet = [ "CAP_NET_BIND_SERVICE" ]; }; environment = env // { - PATH = mkForce cfg.package.path; - PYTHONPATH = "${cfg.package.pythonPath}:${cfg.package}/lib/paperless-ngx/src"; + PATH = mkForce pkg.path; + PYTHONPATH = "${pkg.pythonPath}:${pkg}/lib/paperless-ngx/src"; }; # Allow the web interface to access the private /tmp directory of the server. # This is required to support uploading files via the web interface. From 783f8f16c16ba47daffff2c6b92a96eb8bb5d363 Mon Sep 17 00:00:00 2001 From: Erik Arvstedt Date: Mon, 5 Sep 2022 10:12:39 +0200 Subject: [PATCH 2/2] paperless: move `PYTHONPATH` definition to module `paperless-ngx.pythonPath` was incomplete due to the missing paperless-ngx source, so it had to be amended in the service. Instead of amending it, define it entirely in the service. This allows an override of `paperless-ngx.propagatedBuildInputs` to be reflected in the service's PYTHONPATH. --- nixos/modules/services/misc/paperless.nix | 2 +- pkgs/applications/office/paperless-ngx/default.nix | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/nixos/modules/services/misc/paperless.nix b/nixos/modules/services/misc/paperless.nix index c29824ee8345..0a62af95f8f1 100644 --- a/nixos/modules/services/misc/paperless.nix +++ b/nixos/modules/services/misc/paperless.nix @@ -297,7 +297,7 @@ in }; environment = env // { PATH = mkForce pkg.path; - PYTHONPATH = "${pkg.pythonPath}:${pkg}/lib/paperless-ngx/src"; + PYTHONPATH = "${pkg.python.pkgs.makePythonPath pkg.propagatedBuildInputs}:${pkg}/lib/paperless-ngx/src"; }; # Allow the web interface to access the private /tmp directory of the server. # This is required to support uploading files via the web interface. diff --git a/pkgs/applications/office/paperless-ngx/default.nix b/pkgs/applications/office/paperless-ngx/default.nix index a42ec844d115..1deb8e7efe6e 100644 --- a/pkgs/applications/office/paperless-ngx/default.nix +++ b/pkgs/applications/office/paperless-ngx/default.nix @@ -207,11 +207,7 @@ python.pkgs.pythonPackages.buildPythonApplication rec { ''; passthru = { - inherit python; - # PYTHONPATH of all dependencies used by the package - pythonPath = python3.pkgs.makePythonPath propagatedBuildInputs; - inherit path; - + inherit python path; tests = { inherit (nixosTests) paperless; }; };