Skip to content

Commit

Permalink
nixos/paperless: move paperless-manage to proper systemPackage
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperSandro2000 committed Jan 13, 2025
1 parent 7490faa commit 0675cbe
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions nixos/modules/services/misc/paperless.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,17 @@ let
else toString s
) cfg.settings);

manage = pkgs.writeShellScript "manage" ''
manage = pkgs.writeShellScriptBin "paperless-manage" ''
set -o allexport # Export the following env vars
${lib.toShellVars env}
${lib.optionalString (cfg.environmentFile != null) "source ${cfg.environmentFile}"}
exec ${cfg.package}/bin/paperless-ngx "$@"
cd ${cfg.dataDir}
sudo=exec
if [[ "$USER" != ${cfg.user} ]]; then
${if config.security.sudo.enable then "sudo='exec /run/wrappers/bin/sudo -u ${cfg.user} -E'" else "echo 'Aborting, paperless-manage must be run as ${cfg.user}!'; exit 2"}
fi
$sudo ${cfg.package}/bin/paperless-ngx "$@"
'';

defaultServiceConfig = {
Expand Down Expand Up @@ -94,14 +100,13 @@ in
type = lib.types.bool;
default = false;
description = ''
Enable Paperless.
Whether to enable Paperless-ngx.
When started, the Paperless database is automatically created if it doesn't
exist and updated if the Paperless package has changed.
When started, the Paperless database is automatically created if it doesn't exist
and updated if the Paperless package has changed.
Both tasks are achieved by running a Django migration.
A script to manage the Paperless instance (by wrapping Django's manage.py) is linked to
`''${dataDir}/paperless-manage`.
A script to manage the Paperless-ngx instance (by wrapping Django's manage.py) is available as paperless-manage.
'';
};

Expand Down Expand Up @@ -139,8 +144,7 @@ in
A file containing the superuser password.
A superuser is required to access the web interface.
If unset, you can create a superuser manually by running
`''${dataDir}/paperless-manage createsuperuser`.
If unset, you can create a superuser manually by running `paperless-manage createsuperuser`.
The default superuser name is `admin`. To change it, set
option {option}`settings.PAPERLESS_ADMIN_USER`.
Expand Down Expand Up @@ -288,6 +292,8 @@ in
};

config = lib.mkIf cfg.enable (lib.mkMerge [ {
environment.systemPackages = [ manage ];

services.redis.servers.paperless.enable = lib.mkIf enableRedis true;

services.postgresql = lib.mkIf cfg.database.createLocally {
Expand Down Expand Up @@ -335,8 +341,6 @@ in
environment = env;

preStart = ''
ln -sf ${manage} ${cfg.dataDir}/paperless-manage
# Auto-migrate on first run or if the package has changed
versionFile="${cfg.dataDir}/src-version"
version=$(cat "$versionFile" 2>/dev/null || echo 0)
Expand Down Expand Up @@ -503,9 +507,8 @@ in
};
enableStrictShellChecks = true;
script = ''
./paperless-manage document_exporter ${cfg.exporter.directory} ${lib.cli.toGNUCommandLineShell {} cfg.exporter.settings}
paperless-manage document_exporter ${cfg.exporter.directory} ${lib.cli.toGNUCommandLineShell {} cfg.exporter.settings}
'';
};
})
]);
})]);
}

0 comments on commit 0675cbe

Please sign in to comment.