From fe94d7f146875db9bb4640569011388cb906c9f9 Mon Sep 17 00:00:00 2001 From: SebastianStork Date: Mon, 2 Feb 2026 23:43:04 +0100 Subject: [PATCH] restic: Add `restic-backup-all` and `restic-restore-all` scripts --- modules/system/services/restic/backups.nix | 18 +++++++- modules/system/services/restic/restore.nix | 48 +++++++++++++--------- 2 files changed, 46 insertions(+), 20 deletions(-) diff --git a/modules/system/services/restic/backups.nix b/modules/system/services/restic/backups.nix index 1e5a8e5..d0ff1c9 100644 --- a/modules/system/services/restic/backups.nix +++ b/modules/system/services/restic/backups.nix @@ -1,4 +1,9 @@ -{ config, lib, ... }: +{ + config, + pkgs, + lib, + ... +}: let backups = config.custom.services.restic.backups |> lib.attrValues |> lib.filter (backup: backup.enable); @@ -92,5 +97,16 @@ in }; }) |> lib.listToAttrs; + + environment.systemPackages = + let + backupAllScript = pkgs.writeShellApplication { + name = "restic-backup-all"; + text = "systemctl start restic-backups-{${ + backups |> lib.map (backup: backup.name) |> lib.concatStringsSep "," + }}"; + }; + in + [ backupAllScript ]; }; } diff --git a/modules/system/services/restic/restore.nix b/modules/system/services/restic/restore.nix index d5ab77a..c543c9d 100644 --- a/modules/system/services/restic/restore.nix +++ b/modules/system/services/restic/restore.nix @@ -33,24 +33,34 @@ in config = { environment.systemPackages = - backupsWithRestoreCommand - |> lib.map ( - backup: - let - inherit (backup) name conflictingService; - inherit (backup.restoreCommand) preRestore postRestore; - hasConflictingService = conflictingService != null; - in - pkgs.writeShellApplication { - name = "restic-restore-${name}"; - text = '' - ${lib.optionalString hasConflictingService "systemctl stop ${conflictingService}"} - ${preRestore} - restic-${name} restore latest --target / - ${postRestore} - ${lib.optionalString hasConflictingService "systemctl start ${conflictingService}"} - ''; - } - ); + let + restoreScripts = + backupsWithRestoreCommand + |> lib.map ( + backup: + let + inherit (backup) name conflictingService; + inherit (backup.restoreCommand) preRestore postRestore; + hasConflictingService = conflictingService != null; + in + pkgs.writeShellApplication { + name = "restic-restore-${name}"; + text = '' + ${lib.optionalString hasConflictingService "systemctl stop ${conflictingService}"} + ${preRestore} + restic-${name} restore latest --target / + ${postRestore} + ${lib.optionalString hasConflictingService "systemctl start ${conflictingService}"} + ''; + } + ); + + restoreAllScript = pkgs.writeShellApplication { + name = "restic-restore-all"; + text = + backupsWithRestoreCommand |> lib.map (backup: "restic-restore-${backup.name}") |> lib.concatLines; + }; + in + restoreScripts ++ [ restoreAllScript ]; }; }