285 current 2025-10-11 08:57:30 25.05.20251006.20c4598 6.12.50 *

This commit is contained in:
2025-10-11 09:15:18 -05:00
parent e6039316db
commit 9e30589699
2 changed files with 28 additions and 15 deletions

View File

@@ -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 = {

View File

@@ -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\"
'';
};
};