|
32 | 32 | else toString s |
33 | 33 | ) cfg.settings); |
34 | 34 |
|
35 | | - manage = pkgs.writeShellScript "manage" '' |
| 35 | + manage = pkgs.writeShellScriptBin "paperless-manage" '' |
36 | 36 | set -o allexport # Export the following env vars |
37 | 37 | ${lib.toShellVars env} |
38 | 38 | ${lib.optionalString (cfg.environmentFile != null) "source ${cfg.environmentFile}"} |
39 | | - exec ${cfg.package}/bin/paperless-ngx "$@" |
| 39 | +
|
| 40 | + cd '${cfg.dataDir}' |
| 41 | + sudo=exec |
| 42 | + if [[ "$USER" != ${cfg.user} ]]; then |
| 43 | + ${ |
| 44 | + if config.security.sudo.enable then |
| 45 | + "sudo='exec ${config.security.wrapperDir}/sudo -u ${cfg.user} -E'" |
| 46 | + else |
| 47 | + ">&2 echo 'Aborting, paperless-manage must be run as user `${cfg.user}`!'; exit 2" |
| 48 | + } |
| 49 | + fi |
| 50 | + $sudo ${lib.getExe cfg.package} "$@" |
40 | 51 | ''; |
41 | 52 |
|
42 | 53 | defaultServiceConfig = { |
|
94 | 105 | type = lib.types.bool; |
95 | 106 | default = false; |
96 | 107 | description = '' |
97 | | - Enable Paperless. |
| 108 | + Whether to enable Paperless-ngx. |
98 | 109 |
|
99 | | - When started, the Paperless database is automatically created if it doesn't |
100 | | - exist and updated if the Paperless package has changed. |
| 110 | + When started, the Paperless database is automatically created if it doesn't exist |
| 111 | + and updated if the Paperless package has changed. |
101 | 112 | Both tasks are achieved by running a Django migration. |
102 | 113 |
|
103 | | - A script to manage the Paperless instance (by wrapping Django's manage.py) is linked to |
104 | | - `''${dataDir}/paperless-manage`. |
| 114 | + A script to manage the Paperless-ngx instance (by wrapping Django's manage.py) is available as `paperless-manage`. |
105 | 115 | ''; |
106 | 116 | }; |
107 | 117 |
|
|
139 | 149 | A file containing the superuser password. |
140 | 150 |
|
141 | 151 | A superuser is required to access the web interface. |
142 | | - If unset, you can create a superuser manually by running |
143 | | - `''${dataDir}/paperless-manage createsuperuser`. |
| 152 | + If unset, you can create a superuser manually by running `paperless-manage createsuperuser`. |
144 | 153 |
|
145 | 154 | The default superuser name is `admin`. To change it, set |
146 | 155 | option {option}`settings.PAPERLESS_ADMIN_USER`. |
|
288 | 297 | }; |
289 | 298 |
|
290 | 299 | config = lib.mkIf cfg.enable (lib.mkMerge [ { |
| 300 | + environment.systemPackages = [ manage ]; |
| 301 | + |
291 | 302 | services.redis.servers.paperless.enable = lib.mkIf enableRedis true; |
292 | 303 |
|
293 | 304 | services.postgresql = lib.mkIf cfg.database.createLocally { |
|
336 | 347 | environment = env; |
337 | 348 |
|
338 | 349 | preStart = '' |
339 | | - ln -sf ${manage} ${cfg.dataDir}/paperless-manage |
| 350 | + # remove old papaerless-manage symlink |
| 351 | + # TODO: drop with NixOS 25.11 |
| 352 | + [[ -L '${cfg.dataDir}/paperless-manage' ]] && rm '${cfg.dataDir}/paperless-manage' |
340 | 353 |
|
341 | 354 | # Auto-migrate on first run or if the package has changed |
342 | 355 | versionFile="${cfg.dataDir}/src-version" |
|
504 | 517 | OnSuccess = services; |
505 | 518 | }; |
506 | 519 | enableStrictShellChecks = true; |
| 520 | + path = [ manage ]; |
507 | 521 | script = '' |
508 | | - ./paperless-manage document_exporter ${cfg.exporter.directory} ${lib.cli.toGNUCommandLineShell {} cfg.exporter.settings} |
| 522 | + paperless-manage document_exporter ${cfg.exporter.directory} ${lib.cli.toGNUCommandLineShell {} cfg.exporter.settings} |
509 | 523 | ''; |
510 | 524 | }; |
511 | | - }) |
512 | | - ]); |
| 525 | + })]); |
513 | 526 | } |
0 commit comments