|
1 | | -{ config, pkgs, lib, ... }: |
| 1 | +{ config, options, pkgs, lib, ... }: |
2 | 2 | let |
3 | 3 | cfg = config.services.paperless; |
4 | 4 |
|
|
82 | 82 | }; |
83 | 83 | in |
84 | 84 | { |
85 | | - meta.maintainers = with lib.maintainers; [ leona SuperSandro2000 erikarvstedt ]; |
| 85 | + meta.maintainers = with lib.maintainers; [ leona SuperSandro2000 erikarvstedt atemu theuni ]; |
86 | 86 |
|
87 | 87 | imports = [ |
88 | 88 | (lib.mkRenamedOptionModule [ "services" "paperless-ng" ] [ "services" "paperless" ]) |
|
252 | 252 | ''; |
253 | 253 | }; |
254 | 254 | }; |
| 255 | + |
| 256 | + exporter = { |
| 257 | + enable = lib.mkEnableOption "regular automatic document exports"; |
| 258 | + |
| 259 | + directory = lib.mkOption { |
| 260 | + type = lib.types.str; |
| 261 | + default = cfg.dataDir + "/export"; |
| 262 | + defaultText = "\${dataDir}/export"; |
| 263 | + description = "Directory to store export."; |
| 264 | + }; |
| 265 | + |
| 266 | + onCalendar = lib.mkOption { |
| 267 | + type = lib.types.nullOr lib.types.str; |
| 268 | + default = "01:30:00"; |
| 269 | + description = '' |
| 270 | + When to run the exporter. See {manpage}`systemd.time(7)`. |
| 271 | +
|
| 272 | + `null` disables the timer; allowing you to run the |
| 273 | + `paperless-exporter` service through other means. |
| 274 | + ''; |
| 275 | + }; |
| 276 | + |
| 277 | + settings = lib.mkOption { |
| 278 | + type = with lib.types; attrsOf anything; |
| 279 | + default = { |
| 280 | + "no-progress-bar" = true; |
| 281 | + "no-color" = true; |
| 282 | + "compare-checksums" = true; |
| 283 | + "delete" = true; |
| 284 | + }; |
| 285 | + description = "Settings to pass to the document exporter as CLI arguments."; |
| 286 | + }; |
| 287 | + }; |
255 | 288 | }; |
256 | 289 |
|
257 | | - config = lib.mkIf cfg.enable { |
| 290 | + config = lib.mkIf cfg.enable (lib.mkMerge [ { |
258 | 291 | services.redis.servers.paperless.enable = lib.mkIf enableRedis true; |
259 | 292 |
|
260 | 293 | services.postgresql = lib.mkIf cfg.database.createLocally { |
|
439 | 472 | gid = config.ids.gids.paperless; |
440 | 473 | }; |
441 | 474 | }; |
442 | | - }; |
| 475 | + } |
| 476 | + |
| 477 | + (lib.mkIf cfg.exporter.enable { |
| 478 | + systemd.tmpfiles.rules = [ |
| 479 | + "d '${cfg.exporter.directory}' - ${cfg.user} ${config.users.users.${cfg.user}.group} - -" |
| 480 | + ]; |
| 481 | + |
| 482 | + services.paperless.exporter.settings = options.services.paperless.exporter.settings.default; |
| 483 | + |
| 484 | + systemd.services.paperless-exporter = { |
| 485 | + startAt = lib.defaultTo [] cfg.exporter.onCalendar; |
| 486 | + serviceConfig = { |
| 487 | + User = cfg.user; |
| 488 | + WorkingDirectory = cfg.dataDir; |
| 489 | + }; |
| 490 | + unitConfig = let |
| 491 | + services = [ |
| 492 | + "paperless-consumer.service" |
| 493 | + "paperless-scheduler.service" |
| 494 | + "paperless-task-queue.service" |
| 495 | + "paperless-web.service" ]; |
| 496 | + in { |
| 497 | + # Shut down the paperless services while the exporter runs |
| 498 | + Conflicts = services; |
| 499 | + After = services; |
| 500 | + # Bring them back up afterwards, regardless of pass/fail |
| 501 | + OnFailure = services; |
| 502 | + OnSuccess = services; |
| 503 | + }; |
| 504 | + enableStrictShellChecks = true; |
| 505 | + script = '' |
| 506 | + ./paperless-manage document_exporter ${cfg.exporter.directory} ${lib.cli.toGNUCommandLineShell {} cfg.exporter.settings} |
| 507 | + ''; |
| 508 | + }; |
| 509 | + }) |
| 510 | + ]); |
443 | 511 | } |
0 commit comments