nixos/paperless: extract variable pkg

This commit is contained in:
Erik Arvstedt 2022-09-05 10:03:59 +02:00
parent 2f8b455b00
commit 310b9fe58d
No known key found for this signature in database
GPG key ID: 33312B944DD97846

View file

@ -3,6 +3,7 @@
with lib; with lib;
let let
cfg = config.services.paperless; cfg = config.services.paperless;
pkg = cfg.package;
defaultUser = "paperless"; defaultUser = "paperless";
@ -27,7 +28,7 @@ let
setupEnv = lib.concatStringsSep "\n" (mapAttrsToList (name: val: "export ${name}=\"${val}\"") env); setupEnv = lib.concatStringsSep "\n" (mapAttrsToList (name: val: "export ${name}=\"${val}\"") env);
in pkgs.writeShellScript "manage" '' in pkgs.writeShellScript "manage" ''
${setupEnv} ${setupEnv}
exec ${cfg.package}/bin/paperless-ngx "$@" exec ${pkg}/bin/paperless-ngx "$@"
''; '';
# Secure the services # Secure the services
@ -213,7 +214,7 @@ in
description = "Paperless scheduler"; description = "Paperless scheduler";
serviceConfig = defaultServiceConfig // { serviceConfig = defaultServiceConfig // {
User = cfg.user; User = cfg.user;
ExecStart = "${cfg.package}/bin/paperless-ngx qcluster"; ExecStart = "${pkg}/bin/paperless-ngx qcluster";
Restart = "on-failure"; Restart = "on-failure";
# The `mbind` syscall is needed for running the classifier. # The `mbind` syscall is needed for running the classifier.
SystemCallFilter = defaultServiceConfig.SystemCallFilter ++ [ "mbind" ]; SystemCallFilter = defaultServiceConfig.SystemCallFilter ++ [ "mbind" ];
@ -229,9 +230,9 @@ in
# Auto-migrate on first run or if the package has changed # Auto-migrate on first run or if the package has changed
versionFile="${cfg.dataDir}/src-version" versionFile="${cfg.dataDir}/src-version"
if [[ $(cat "$versionFile" 2>/dev/null) != ${cfg.package} ]]; then if [[ $(cat "$versionFile" 2>/dev/null) != ${pkg} ]]; then
${cfg.package}/bin/paperless-ngx migrate ${pkg}/bin/paperless-ngx migrate
echo ${cfg.package} > "$versionFile" echo ${pkg} > "$versionFile"
fi fi
'' ''
+ optionalString (cfg.passwordFile != null) '' + optionalString (cfg.passwordFile != null) ''
@ -241,7 +242,7 @@ in
superuserStateFile="${cfg.dataDir}/superuser-state" superuserStateFile="${cfg.dataDir}/superuser-state"
if [[ $(cat "$superuserStateFile" 2>/dev/null) != $superuserState ]]; then if [[ $(cat "$superuserStateFile" 2>/dev/null) != $superuserState ]]; then
${cfg.package}/bin/paperless-ngx manage_superuser ${pkg}/bin/paperless-ngx manage_superuser
echo "$superuserState" > "$superuserStateFile" echo "$superuserState" > "$superuserStateFile"
fi fi
''; '';
@ -266,7 +267,7 @@ in
description = "Paperless document consumer"; description = "Paperless document consumer";
serviceConfig = defaultServiceConfig // { serviceConfig = defaultServiceConfig // {
User = cfg.user; User = cfg.user;
ExecStart = "${cfg.package}/bin/paperless-ngx document_consumer"; ExecStart = "${pkg}/bin/paperless-ngx document_consumer";
Restart = "on-failure"; Restart = "on-failure";
}; };
environment = env; environment = env;
@ -282,7 +283,7 @@ in
User = cfg.user; User = cfg.user;
ExecStart = '' ExecStart = ''
${pkgs.python3Packages.gunicorn}/bin/gunicorn \ ${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"; Restart = "on-failure";
@ -295,8 +296,8 @@ in
CapabilityBoundingSet = [ "CAP_NET_BIND_SERVICE" ]; CapabilityBoundingSet = [ "CAP_NET_BIND_SERVICE" ];
}; };
environment = env // { environment = env // {
PATH = mkForce cfg.package.path; PATH = mkForce pkg.path;
PYTHONPATH = "${cfg.package.pythonPath}:${cfg.package}/lib/paperless-ngx/src"; PYTHONPATH = "${pkg.pythonPath}:${pkg}/lib/paperless-ngx/src";
}; };
# Allow the web interface to access the private /tmp directory of the server. # Allow the web interface to access the private /tmp directory of the server.
# This is required to support uploading files via the web interface. # This is required to support uploading files via the web interface.