From e93369306761124f88fcb4bde02fa6a09bc8c8c5 Mon Sep 17 00:00:00 2001 From: 1sixth <1sixth@azc.moe> Date: Mon, 7 Sep 2026 21:54:20 +0800 Subject: [PATCH] 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). --- nixos/modules/services/backup/restic.nix | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/nixos/modules/services/backup/restic.nix b/nixos/modules/services/backup/restic.nix index 8344fc84246a..65031ad0d077 100644 --- a/nixos/modules/services/backup/restic.nix +++ b/nixos/modules/services/backup/restic.nix @@ -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}