diff --git a/nixos/modules/services/backup/restic.nix b/nixos/modules/services/backup/restic.nix index 1e353aeacb185..f71c939e93942 100644 --- a/nixos/modules/services/backup/restic.nix +++ b/nixos/modules/services/backup/restic.nix @@ -161,6 +161,17 @@ in ]; }; + unitConfig = lib.mkOption { + type = lib.types.nullOr (lib.types.attrsOf unitOption); + default = null; + description = '' + Configuration for the systemd unit. + ''; + example = { + OnFailure = "notify-restic-failure.service"; + }; + }; + timerConfig = lib.mkOption { type = lib.types.nullOr (lib.types.attrsOf unitOption); default = { @@ -402,6 +413,7 @@ in EnvironmentFile = backup.environmentFile; }; } + // lib.optionalAttrs (backup.unitConfig != null) backup.unitConfig // lib.optionalAttrs (backup.initialize || doBackup || backup.backupPrepareCommand != null) { preStart = '' ${lib.optionalString (backup.backupPrepareCommand != null) '' diff --git a/nixos/tests/restic.nix b/nixos/tests/restic.nix index 1a66ca7f0d929..3ac4cda4228ee 100644 --- a/nixos/tests/restic.nix +++ b/nixos/tests/restic.nix @@ -137,6 +137,13 @@ import ./make-test-python.nix ( pruneOpts = [ "--keep-last 1" ]; checkOpts = [ "--some-check-option" ]; }; + customUnitConfig = { + inherit passwordFile paths; + repository = remoteRepository; + unitConfig = { + documentation = [ "custom-unit-config-was-written" ]; + }; + }; }; environment.sessionVariables.RCLONE_CONFIG_LOCAL_TYPE = "local"; @@ -228,6 +235,8 @@ import ./make-test-python.nix ( "systemctl start restic-backups-remoteprune.service", 'restic-remotebackup snapshots --json | ${pkgs.jq}/bin/jq "length | . == 1"', + # test that custom unit config is present + "systemctl cat restic-backups-customUnitConfig | grep custom-unit-config-was-written" ) # test that the inhibit option is working