From 9e30589699317e71ba353c0bd4ea6c4a3b450f37 Mon Sep 17 00:00:00 2001 From: blake Date: Sat, 11 Oct 2025 09:15:18 -0500 Subject: [PATCH] 285 current 2025-10-11 08:57:30 25.05.20251006.20c4598 6.12.50 * --- flake.nix | 2 +- modules/system/backups.nix | 41 +++++++++++++++++++++++++------------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/flake.nix b/flake.nix index b6f88ce..1d12e29 100644 --- a/flake.nix +++ b/flake.nix @@ -1,6 +1,6 @@ # flake for blakes nixos config # define new devices in outputs -# generation: 284 current 2025-10-11 08:13:32 25.05.20251006.20c4598 6.12.50 * +# generation: 285 current 2025-10-11 08:57:30 25.05.20251006.20c4598 6.12.50 * { description = "blakes nix config"; inputs = { diff --git a/modules/system/backups.nix b/modules/system/backups.nix index 6d81eda..eae5f51 100644 --- a/modules/system/backups.nix +++ b/modules/system/backups.nix @@ -5,11 +5,6 @@ let borg = "${pkgs.borgbackup}/bin/borg"; backup_paths = lib.unique config.modules.system.backups.paths; passwd_file = config.sops.secrets."borg_passwd".path; - jobs = { - sungger = { paths = [ "/var/lib/radarr" "/var/lib/sonarr" ]; }; - hoass = { paths = [ "/var/lib/zigbee2mqtt" "/var/lib/hass" "/var/lib/mosquitto" ]; }; - huh = { paths = [ "/home/blake/.nix" ]; }; - }; in { options.modules.system.backups = { @@ -19,6 +14,17 @@ in default = []; description = "list of directories to back up"; }; + jobs = lib.mkOption { + type = lib.types.nullOr ( + lib.types.attrsOf ( # the set up backup jobs + lib.types.attrsOf ( # the set of paths + lib.types.listOf lib.types.path # the paths + ) + ) + ); + default = null; + description = "Borg backup jobs; each job has a list of paths."; + }; repo = lib.mkOption { type = lib.types.path; default = "/holocron/borg"; @@ -37,6 +43,13 @@ in # "d ${cfg.repo} 0755 root root" # ]; + + cfg.jobs = { + sungger = { paths = [ "/var/lib/radarr" "/var/lib/sonarr" ]; }; + hoass = { paths = [ "/var/lib/zigbee2mqtt" "/var/lib/hass" "/var/lib/mosquitto" ]; }; + huh = { paths = [ "/home/blake/.nix" ]; }; + }; + systemd.services.backups = { description = "backup service with borg!"; path = [ pkgs.borgbackup ]; @@ -55,14 +68,14 @@ in borg init --encryption=repokey "$BORG_REPO" fi - echo "Starting backup run at $timestamp" + echo "starting backup run at $timestamp" # Loop over all jobs (attribute set keys) - ${lib.concatStringsSep "\n\n" (lib.mapAttrsToList (jobName: jobCfg: + ${lib.concatStringsSep "\n\n" (lib.mapAttrsToList (bak_name: bak_paths: '' - echo "=== Backing up ${jobName} ===" - archive="${jobName}-$timestamp" - echo "Backing up paths: ${lib.concatStringsSep " " jobCfg.paths} → $archive" + echo "------------- Backing up ${bak_name} -------------" + archive="${bak_name}-$timestamp" + echo "backing up paths: ${lib.concatStringsSep " " bak_paths.paths} → $archive" borg create \ --verbose \ --filter AME \ @@ -71,18 +84,18 @@ in --show-rc \ --compression lzma,9 \ "$BORG_REPO::$archive" \ - ${lib.concatStringsSep " " jobCfg.paths} + ${lib.concatStringsSep " " bak_paths.paths} - echo "Pruning old backups for ${jobName}..." + echo "pruning old backups for ${bak_name}..." borg prune -v --list "$BORG_REPO" \ - --prefix "${jobName}-" \ + --prefix "${bak_name}-" \ --keep-daily=7 \ --keep-weekly=52 \ --keep-monthly=-1 '' ) jobs)} - echo "Backup run complete at $timestamp." + echo "finshed backup at \"$BORG_REPO::$archive\" ''; }; };