nixos/restic: fix repository initialization checks

1. Add `--no-lock` to `restic cat config`.
2. Run `restic init` only if the exit code is 10 (repository does not exist).
This commit is contained in:
1sixth
2026-09-07 21:54:20 +08:00
parent aa88e342b7
commit e933693067

View File

@@ -478,7 +478,14 @@ in
${pkgs.writeScript "backupPrepareCommand" backup.backupPrepareCommand}
''}
${lib.optionalString backup.initialize ''
${resticCmd} cat config > /dev/null || ${resticCmd} init
${resticCmd} cat config --no-lock > /dev/null || {
status=$?
if [ "$status" -eq 10 ]; then
${resticCmd} init
else
exit "$status"
fi
}
''}
${lib.optionalString (backup.paths != null && backup.paths != [ ]) ''
cat ${pkgs.writeText "staticPaths" (lib.concatLines backup.paths)} >> ${filesFromTmpFile}