mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-13 05:05:29 +03:00
nixos/paperless: move paperless-manage to proper systemPackage (#367496)
This commit is contained in:
commit
73f3c9bdce
3 changed files with 30 additions and 14 deletions
|
@ -223,6 +223,9 @@
|
||||||
- The `services.locate` module does no longer support findutil's `locate` due to its inferior performance compared to `mlocate` and `plocate`. The new default is `plocate`.
|
- The `services.locate` module does no longer support findutil's `locate` due to its inferior performance compared to `mlocate` and `plocate`. The new default is `plocate`.
|
||||||
As the `service.locate.localuser` option only applied when using findutil's `locate`, it has also been removed.
|
As the `service.locate.localuser` option only applied when using findutil's `locate`, it has also been removed.
|
||||||
|
|
||||||
|
- `services.paperless` now installs `paperless-manage` as a normal system package instead of creating a symlink in `/var/lib/paperless`.
|
||||||
|
`paperless-manage` now also changes to the appropriate user when being executed.
|
||||||
|
|
||||||
- `kmonad` is now hardened by default using common `systemd` settings.
|
- `kmonad` is now hardened by default using common `systemd` settings.
|
||||||
If KMonad is used to execute shell commands, hardening may make some of them fail. In that case, you can disable hardening using {option}`services.kmonad.keyboards.<name>.enableHardening` option.
|
If KMonad is used to execute shell commands, hardening may make some of them fail. In that case, you can disable hardening using {option}`services.kmonad.keyboards.<name>.enableHardening` option.
|
||||||
|
|
||||||
|
|
|
@ -32,11 +32,22 @@ let
|
||||||
else toString s
|
else toString s
|
||||||
) cfg.settings);
|
) cfg.settings);
|
||||||
|
|
||||||
manage = pkgs.writeShellScript "manage" ''
|
manage = pkgs.writeShellScriptBin "paperless-manage" ''
|
||||||
set -o allexport # Export the following env vars
|
set -o allexport # Export the following env vars
|
||||||
${lib.toShellVars env}
|
${lib.toShellVars env}
|
||||||
${lib.optionalString (cfg.environmentFile != null) "source ${cfg.environmentFile}"}
|
${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 ${config.security.wrapperDir}/sudo -u ${cfg.user} -E'"
|
||||||
|
else
|
||||||
|
">&2 echo 'Aborting, paperless-manage must be run as user `${cfg.user}`!'; exit 2"
|
||||||
|
}
|
||||||
|
fi
|
||||||
|
$sudo ${lib.getExe cfg.package} "$@"
|
||||||
'';
|
'';
|
||||||
|
|
||||||
defaultServiceConfig = {
|
defaultServiceConfig = {
|
||||||
|
@ -94,14 +105,13 @@ in
|
||||||
type = lib.types.bool;
|
type = lib.types.bool;
|
||||||
default = false;
|
default = false;
|
||||||
description = ''
|
description = ''
|
||||||
Enable Paperless.
|
Whether to enable Paperless-ngx.
|
||||||
|
|
||||||
When started, the Paperless database is automatically created if it doesn't
|
When started, the Paperless database is automatically created if it doesn't exist
|
||||||
exist and updated if the Paperless package has changed.
|
and updated if the Paperless package has changed.
|
||||||
Both tasks are achieved by running a Django migration.
|
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
|
A script to manage the Paperless-ngx instance (by wrapping Django's manage.py) is available as `paperless-manage`.
|
||||||
`''${dataDir}/paperless-manage`.
|
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -139,8 +149,7 @@ in
|
||||||
A file containing the superuser password.
|
A file containing the superuser password.
|
||||||
|
|
||||||
A superuser is required to access the web interface.
|
A superuser is required to access the web interface.
|
||||||
If unset, you can create a superuser manually by running
|
If unset, you can create a superuser manually by running `paperless-manage createsuperuser`.
|
||||||
`''${dataDir}/paperless-manage createsuperuser`.
|
|
||||||
|
|
||||||
The default superuser name is `admin`. To change it, set
|
The default superuser name is `admin`. To change it, set
|
||||||
option {option}`settings.PAPERLESS_ADMIN_USER`.
|
option {option}`settings.PAPERLESS_ADMIN_USER`.
|
||||||
|
@ -288,6 +297,8 @@ in
|
||||||
};
|
};
|
||||||
|
|
||||||
config = lib.mkIf cfg.enable (lib.mkMerge [ {
|
config = lib.mkIf cfg.enable (lib.mkMerge [ {
|
||||||
|
environment.systemPackages = [ manage ];
|
||||||
|
|
||||||
services.redis.servers.paperless.enable = lib.mkIf enableRedis true;
|
services.redis.servers.paperless.enable = lib.mkIf enableRedis true;
|
||||||
|
|
||||||
services.postgresql = lib.mkIf cfg.database.createLocally {
|
services.postgresql = lib.mkIf cfg.database.createLocally {
|
||||||
|
@ -336,7 +347,9 @@ in
|
||||||
environment = env;
|
environment = env;
|
||||||
|
|
||||||
preStart = ''
|
preStart = ''
|
||||||
ln -sf ${manage} ${cfg.dataDir}/paperless-manage
|
# remove old papaerless-manage symlink
|
||||||
|
# TODO: drop with NixOS 25.11
|
||||||
|
[[ -L '${cfg.dataDir}/paperless-manage' ]] && rm '${cfg.dataDir}/paperless-manage'
|
||||||
|
|
||||||
# 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"
|
||||||
|
@ -504,10 +517,10 @@ in
|
||||||
OnSuccess = services;
|
OnSuccess = services;
|
||||||
};
|
};
|
||||||
enableStrictShellChecks = true;
|
enableStrictShellChecks = true;
|
||||||
|
path = [ manage ];
|
||||||
script = ''
|
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}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
})
|
})]);
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,7 +99,7 @@ import ./make-test-python.nix ({ lib, ... }: {
|
||||||
# Double check that our attrset option override works as expected
|
# Double check that our attrset option override works as expected
|
||||||
cmdline = node.succeed("grep 'paperless-manage' $(systemctl cat paperless-exporter | grep ExecStart | cut -f 2 -d=)")
|
cmdline = node.succeed("grep 'paperless-manage' $(systemctl cat paperless-exporter | grep ExecStart | cut -f 2 -d=)")
|
||||||
print(f"Exporter command line {cmdline!r}")
|
print(f"Exporter command line {cmdline!r}")
|
||||||
assert cmdline.strip() == "./paperless-manage document_exporter /var/lib/paperless/export --compare-checksums --delete --no-progress-bar --no-thumbnail", "Unexpected exporter command line"
|
assert cmdline.strip() == "paperless-manage document_exporter /var/lib/paperless/export --compare-checksums --delete --no-progress-bar --no-thumbnail", "Unexpected exporter command line"
|
||||||
|
|
||||||
test_paperless(simple)
|
test_paperless(simple)
|
||||||
simple.send_monitor_command("quit")
|
simple.send_monitor_command("quit")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue