285 current 2025-10-11 08:57:30 25.05.20251006.20c4598 6.12.50 *
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
# flake for blakes nixos config
|
# flake for blakes nixos config
|
||||||
# define new devices in outputs
|
# 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";
|
description = "blakes nix config";
|
||||||
inputs = {
|
inputs = {
|
||||||
|
|||||||
@@ -5,11 +5,6 @@ let
|
|||||||
borg = "${pkgs.borgbackup}/bin/borg";
|
borg = "${pkgs.borgbackup}/bin/borg";
|
||||||
backup_paths = lib.unique config.modules.system.backups.paths;
|
backup_paths = lib.unique config.modules.system.backups.paths;
|
||||||
passwd_file = config.sops.secrets."borg_passwd".path;
|
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
|
in
|
||||||
{
|
{
|
||||||
options.modules.system.backups = {
|
options.modules.system.backups = {
|
||||||
@@ -19,6 +14,17 @@ in
|
|||||||
default = [];
|
default = [];
|
||||||
description = "list of directories to back up";
|
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 {
|
repo = lib.mkOption {
|
||||||
type = lib.types.path;
|
type = lib.types.path;
|
||||||
default = "/holocron/borg";
|
default = "/holocron/borg";
|
||||||
@@ -37,6 +43,13 @@ in
|
|||||||
# "d ${cfg.repo} 0755 root root"
|
# "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 = {
|
systemd.services.backups = {
|
||||||
description = "backup service with borg!";
|
description = "backup service with borg!";
|
||||||
path = [ pkgs.borgbackup ];
|
path = [ pkgs.borgbackup ];
|
||||||
@@ -55,14 +68,14 @@ in
|
|||||||
borg init --encryption=repokey "$BORG_REPO"
|
borg init --encryption=repokey "$BORG_REPO"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Starting backup run at $timestamp"
|
echo "starting backup run at $timestamp"
|
||||||
|
|
||||||
# Loop over all jobs (attribute set keys)
|
# 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} ==="
|
echo "------------- Backing up ${bak_name} -------------"
|
||||||
archive="${jobName}-$timestamp"
|
archive="${bak_name}-$timestamp"
|
||||||
echo "Backing up paths: ${lib.concatStringsSep " " jobCfg.paths} → $archive"
|
echo "backing up paths: ${lib.concatStringsSep " " bak_paths.paths} → $archive"
|
||||||
borg create \
|
borg create \
|
||||||
--verbose \
|
--verbose \
|
||||||
--filter AME \
|
--filter AME \
|
||||||
@@ -71,18 +84,18 @@ in
|
|||||||
--show-rc \
|
--show-rc \
|
||||||
--compression lzma,9 \
|
--compression lzma,9 \
|
||||||
"$BORG_REPO::$archive" \
|
"$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" \
|
borg prune -v --list "$BORG_REPO" \
|
||||||
--prefix "${jobName}-" \
|
--prefix "${bak_name}-" \
|
||||||
--keep-daily=7 \
|
--keep-daily=7 \
|
||||||
--keep-weekly=52 \
|
--keep-weekly=52 \
|
||||||
--keep-monthly=-1
|
--keep-monthly=-1
|
||||||
''
|
''
|
||||||
) jobs)}
|
) jobs)}
|
||||||
|
|
||||||
echo "Backup run complete at $timestamp."
|
echo "finshed backup at \"$BORG_REPO::$archive\"
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user