nixos/restic: add option to inhibit going to sleep
This commit is contained in:
parent
e86fd8c2ee
commit
a8038698d3
@ -211,6 +211,8 @@
|
||||
- Nemo is now built with gtk-layer-shell support, note that for now it will be expected to see nemo-desktop
|
||||
listed as a regular entry in Cinnamon Wayland session's window list applet.
|
||||
|
||||
- `restic` module now has an option for inhibiting system sleep while backups are running, defaulting to off (not inhibiting sleep), available as [`services.restic.backups.<name>.inhibitsSleep`](#opt-services.restic.backups._name_.inhibitsSleep).
|
||||
|
||||
- Support for *runner registration tokens* has been [deprecated](https://gitlab.com/gitlab-org/gitlab/-/issues/380872)
|
||||
in `gitlab-runner` 15.6 and is expected to be removed in `gitlab-runner` 18.0. Configuration of existing runners
|
||||
should be changed to using *runner authentication tokens* by configuring
|
||||
|
@ -83,6 +83,15 @@ in
|
||||
'';
|
||||
};
|
||||
|
||||
inhibitsSleep = mkOption {
|
||||
default = false;
|
||||
type = types.bool;
|
||||
example = true;
|
||||
description = ''
|
||||
Prevents the system from sleeping while backing up.
|
||||
'';
|
||||
};
|
||||
|
||||
repository = mkOption {
|
||||
type = with types; nullOr str;
|
||||
default = null;
|
||||
@ -299,7 +308,14 @@ in
|
||||
(name: backup:
|
||||
let
|
||||
extraOptions = concatMapStrings (arg: " -o ${arg}") backup.extraOptions;
|
||||
resticCmd = "${backup.package}/bin/restic${extraOptions}";
|
||||
inhibitCmd = concatStringsSep " " [
|
||||
"${pkgs.systemd}/bin/systemd-inhibit"
|
||||
"--mode='block'"
|
||||
"--who='restic'"
|
||||
"--what='sleep'"
|
||||
"--why=${escapeShellArg "Scheduled backup ${name}"} "
|
||||
];
|
||||
resticCmd = "${optionalString backup.inhibitsSleep inhibitCmd}${backup.package}/bin/restic${extraOptions}";
|
||||
excludeFlags = optional (backup.exclude != []) "--exclude-file=${pkgs.writeText "exclude-patterns" (concatStringsSep "\n" backup.exclude)}";
|
||||
filesFromTmpFile = "/run/restic-backups-${name}/includes";
|
||||
doBackup = (backup.dynamicFilesFrom != null) || (backup.paths != null && backup.paths != []);
|
||||
|
@ -4,6 +4,7 @@ import ./make-test-python.nix (
|
||||
let
|
||||
remoteRepository = "/root/restic-backup";
|
||||
remoteFromFileRepository = "/root/restic-backup-from-file";
|
||||
remoteInhibitTestRepository = "/root/restic-backup-inhibit-test";
|
||||
remoteNoInitRepository = "/root/restic-backup-no-init";
|
||||
rcloneRepository = "rclone:local:/root/restic-rclone-backup";
|
||||
|
||||
@ -66,6 +67,12 @@ import ./make-test-python.nix (
|
||||
find /opt -mindepth 1 -maxdepth 1 ! -name a_dir # all files in /opt except for a_dir
|
||||
'';
|
||||
};
|
||||
inhibit-test = {
|
||||
inherit passwordFile paths exclude pruneOpts;
|
||||
repository = remoteInhibitTestRepository;
|
||||
initialize = true;
|
||||
inhibitsSleep = true;
|
||||
};
|
||||
remote-noinit-backup = {
|
||||
inherit passwordFile exclude pruneOpts paths;
|
||||
initialize = false;
|
||||
@ -190,6 +197,13 @@ import ./make-test-python.nix (
|
||||
'restic-remotebackup snapshots --json | ${pkgs.jq}/bin/jq "length | . == 1"',
|
||||
|
||||
)
|
||||
|
||||
# test that the inhibit option is working
|
||||
server.systemctl("start --no-block restic-backups-inhibit-test.service")
|
||||
server.wait_until_succeeds(
|
||||
"systemd-inhibit --no-legend --no-pager | grep -q restic",
|
||||
5
|
||||
)
|
||||
'';
|
||||
}
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user