Skip to content

Commit

Permalink
restic: add unitConfig option
Browse files Browse the repository at this point in the history
  • Loading branch information
jerith666 committed Dec 26, 2024
1 parent 00bcba7 commit fb3a1a4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions nixos/modules/services/backup/restic.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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) ''
Expand Down
9 changes: 9 additions & 0 deletions nixos/tests/restic.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fb3a1a4

Please sign in to comment.