-
-
Notifications
You must be signed in to change notification settings - Fork 14.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nixos/restic: add option to inhibit going to sleep #296691
nixos/restic: add option to inhibit going to sleep #296691
Conversation
@@ -394,6 +394,8 @@ The pre-existing [services.ankisyncd](#opt-services.ankisyncd.enable) has been m | |||
|
|||
`redirectCode`. | |||
|
|||
- `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). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this documents the option more clearly than the option's actual documentation, although false = don't inhibit
should probably be obvious from the option name, so i its probably fine as-is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about the updated option description?
inhibitCmd = concatStringsSep " " [ | ||
"${pkgs.systemd}/bin/systemd-inhibit" | ||
"--mode='block'" | ||
"--who='restic'" | ||
"--what='sleep'" | ||
"--why='Scheduled backup ${name}' " | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why split the string beforhand?
inhibitCmd = concatStringsSep " " [ | |
"${pkgs.systemd}/bin/systemd-inhibit" | |
"--mode='block'" | |
"--who='restic'" | |
"--what='sleep'" | |
"--why='Scheduled backup ${name}' " | |
]; | |
inhibitCmd = "${pkgs.systemd}/bin/systemd-inhibit --mode='block' --who='restic' --what='sleep' --why='Scheduled backup ${name}' "; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I split it up for readability, no other reason. I could change it, but the next reviewer would probably tell me to split it up as it is too long:D
65a3e3c
to
4a21ed6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, needs another rebase though
6301ecc
to
ae98b63
Compare
ae98b63
to
a803869
Compare
@ofborg test restic |
The newly added VM test section for this seems to fail, but the VM test itself reports as successful anyway.
See https://logs.ofborg.org/?key=nixos/nixpkgs.296691&attempt_id=d81aedde-c33a-40c0-9060-b638f8a1048a Also, what is the benefit of wrapping the command with diff --git a/nixos/modules/services/backup/restic.nix b/nixos/modules/services/backup/restic.nix
index 7b10d7d38d20..903eb9ceeafc 100644
--- a/nixos/modules/services/backup/restic.nix
+++ b/nixos/modules/services/backup/restic.nix
@@ -308,14 +308,7 @@ in
(name: backup:
let
extraOptions = concatMapStrings (arg: " -o ${arg}") backup.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}";
+ resticCmd = "${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 != []);
@@ -353,6 +346,18 @@ in
restartIfChanged = false;
wants = [ "network-online.target" ];
after = [ "network-online.target" ];
+ before = optionals backup.inhibitsSleep [
+ "suspend.target"
+ "hibernate.target"
+ "hybrid-sleep.target"
+ "suspend-then-hibernate.target"
+ ];
+ wantedBy = optionals backup.inhibitsSleep [
+ "suspend.target"
+ "hibernate.target"
+ "hybrid-sleep.target"
+ "suspend-then-hibernate.target"
+ ];
serviceConfig = {
Type = "oneshot";
ExecStart = (optionals doBackup [ "${resticCmd} backup ${concatStringsSep " " (backup.extraBackupArgs ++ excludeFlags)} --files-from=${filesFromTmpFile}" ]) I would assume it does not show up in |
Another benefit is, that if I execute Thanks for pointing out the issue with the test, I was only seeing the succeeded test tbh. |
The current wrapped version is silently failing the test, so I wanted to provide another approach that I know works.
Hmm I see. That's a solid reason. Keep your Feel free to undraft and ping when you fixed the VM test :) |
Okay, after some debugging I found the cause of the exit 1 output...
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see, this is a misunderstanding then.
The error line comes from resticCmd snapshot
(which is intended) and just happens to be the last line the VM test prints.
Makes sense to me now!
server.systemctl("start --no-block restic-backups-inhibit-test.service") | ||
server.wait_until_succeeds( | ||
"systemd-inhibit --no-legend --no-pager | grep -q restic", | ||
5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering if a 5 second timeout is too low for hydra.nixos.org.
I suppose we will see how it goes and can create a follow-up PR if needed :)
@ofborg test restic |
Description of changes
Things done
nix.conf
? (See Nix manual)sandbox = relaxed
sandbox = true
nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)Add a 👍 reaction to pull requests you find important.