284 current 2025-10-11 08:13:32 25.05.20251006.20c4598 6.12.50 *
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# flake for blakes nixos config
|
||||
# define new devices in outputs
|
||||
# generation: 283 current 2025-10-11 06:19:49 25.05.20251006.20c4598 6.12.50 *
|
||||
# generation: 284 current 2025-10-11 08:13:32 25.05.20251006.20c4598 6.12.50 *
|
||||
{
|
||||
description = "blakes nix config";
|
||||
inputs = {
|
||||
|
||||
@@ -5,6 +5,11 @@ 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 = {
|
||||
@@ -37,7 +42,6 @@ in
|
||||
path = [ pkgs.borgbackup ];
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
EnvironmentFile = config.modules.system.backups.passphraseFile;
|
||||
# the actual script borg is using
|
||||
ExecStart = pkgs.writeShellScript "borg-backup" ''
|
||||
set -euo pipefail
|
||||
@@ -47,30 +51,38 @@ in
|
||||
|
||||
# Initialize repo if it doesn't exist
|
||||
if ! borg info "$BORG_REPO" >/dev/null 2>&1; then
|
||||
echo "init borg repo at $BORG_REPO"
|
||||
echo "Initializing Borg repo at $BORG_REPO"
|
||||
borg init --encryption=repokey "$BORG_REPO"
|
||||
fi
|
||||
|
||||
# Create backup
|
||||
echo "starting backup..."
|
||||
borg create \
|
||||
--verbose \
|
||||
--filter AME \
|
||||
--list \
|
||||
--stats \
|
||||
--show-rc \
|
||||
--compression lzma,9 \
|
||||
"$BORG_REPO::${toString config.networking.hostName}-$timestamp" \
|
||||
${lib.concatStringsSep " " cfg.paths}
|
||||
echo "Starting backup run at $timestamp"
|
||||
|
||||
# Prune old backups according to retention policy
|
||||
echo "Pruning old backups..."
|
||||
borg prune -v --list "$BORG_REPO" \
|
||||
--keep-daily=7 \
|
||||
--keep-weekly=52 \
|
||||
--keep-monthly=-1
|
||||
# Loop over all jobs (attribute set keys)
|
||||
${lib.concatStringsSep "\n\n" (lib.mapAttrsToList (jobName: jobCfg:
|
||||
''
|
||||
echo "=== Backing up ${jobName} ==="
|
||||
archive="${jobName}-$timestamp"
|
||||
echo "Backing up paths: ${lib.concatStringsSep " " jobCfg.paths} → $archive"
|
||||
borg create \
|
||||
--verbose \
|
||||
--filter AME \
|
||||
--list \
|
||||
--stats \
|
||||
--show-rc \
|
||||
--compression lzma,9 \
|
||||
"$BORG_REPO::$archive" \
|
||||
${lib.concatStringsSep " " jobCfg.paths}
|
||||
|
||||
echo "$timestamp - backup completed successfully."
|
||||
echo "Pruning old backups for ${jobName}..."
|
||||
borg prune -v --list "$BORG_REPO" \
|
||||
--prefix "${jobName}-" \
|
||||
--keep-daily=7 \
|
||||
--keep-weekly=52 \
|
||||
--keep-monthly=-1
|
||||
''
|
||||
) jobs)}
|
||||
|
||||
echo "Backup run complete at $timestamp."
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
@@ -28,13 +28,14 @@ map ] half-down
|
||||
# files & archives
|
||||
map ad mkdir
|
||||
map af mkfile
|
||||
map ab mkbak
|
||||
map ae extract
|
||||
map aa archive
|
||||
|
||||
# trash
|
||||
map gt cd ~/.local/share/Trash/files
|
||||
map <delete> trash
|
||||
map <s-delete> $trash-restore
|
||||
map <s-delete> $trash restore
|
||||
|
||||
# --- functions ---
|
||||
|
||||
@@ -78,7 +79,7 @@ cmd archive %{{
|
||||
}}
|
||||
|
||||
# move files to trash
|
||||
cmd trash %IFS="$(printf '\n\t')"; trash-put $fx
|
||||
cmd trash %IFS="$(printf '\n\t')"; trash put $fx
|
||||
|
||||
# make a directory
|
||||
cmd mkdir %{{
|
||||
@@ -100,4 +101,10 @@ cmd mkfile %{{
|
||||
fi
|
||||
}}
|
||||
|
||||
# make backup
|
||||
cmd mkbak %{{
|
||||
for x in $fx; do
|
||||
cp $x $x.bak
|
||||
done
|
||||
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user