feat(desktop): local restic backup.

This commit is contained in:
CronyAkatsuki 2025-06-22 09:09:36 +02:00
parent 33f606aebf
commit 64a1ecc15e
6 changed files with 144 additions and 71 deletions

View file

@ -18,6 +18,7 @@
./wayland.nix
./river.nix
./pipewire.nix
./secrets.nix
];
crony.river.enable = lib.mkDefault false;
@ -38,4 +39,5 @@
crony.newsboat.enable = lib.mkDefault false;
crony.xdg-user-dirs.enable = lib.mkDefault true;
crony.pipewire.enable = lib.mkDefault true;
crony.home-secrets.enable = lib.mkDefault false;
}

View file

@ -14,79 +14,105 @@
restic
];
# Restic home manager service
services.restic = {
enable = true;
backups = {
local = {
initialize = true;
passwordFile = "/run/user/1000/agenix/restic-local-pass";
paths = [
"/home/crony/.face"
"/home/crony/.librewolf"
"/home/crony/.ssh"
"/home/crony/.config/heroic"
"/home/crony/.config/nbfc.json"
"/home/crony/.config/OpenTabletDriver"
"/home/crony/.config/tridactyl"
"/home/crony/.local/share/gnupg"
"/home/crony/.local/share/osu"
"/home/crony/docs/sync"
"/home/crony/docs/wireguard-keys"
"/home/crony/pics"
];
repository = "/home/crony/.local/backup";
};
};
};
##-- Restic Timers And Services --##
# Restic backup
systemd.user.services = {
restic_backup = {
Unit.Description = "Restic backup service";
Service = {
Type = "oneshot";
ExecStart = toString (pkgs.writeShellScript "restic-backup" ''
. /etc/restic/local
restic backup --files-from /home/crony/.config/restic/list --verbose && restic forget --keep-last 10 --keep-daily 7 --keep-weekly 5 --keep-monthly 12
. /etc/restic/online
restic backup --files-from /home/crony/.config/restic/list --verbose && restic forget --keep-last 10 --keep-daily 7 --keep-weekly 5 --keep-monthly 12
rsync -avP --delete "$HOME/.local/backup/" "$HOME/Documents/Share/backup"
'');
};
};
};
systemd.user.timers = {
restic_backup = {
Unit.Description = "Restic backup timer";
Timer = {
OnBootSec = "5m";
OnUnitActiveSec = "6h";
};
Install.WantedBy = ["timers.target"];
};
};
# Restic check
systemd.user.services = {
restic_check = {
Unit.Description = "Restic check service";
Service = {
Type = "oneshot";
ExecStart = toString (pkgs.writeShellScript "restic-check" ''
. /etc/restic/local
restic check --read-data-subset=10%
. /etc/restic/online
restic check --read-data-subset=10%
'');
};
};
};
systemd.user.timers = {
restic_check = {
Unit.Description = "Restic check timer";
Timer = {OnCalendar = "Thu *-*-* 18:00:00";};
Install.WantedBy = ["timers.target"];
};
};
# Restic prune
systemd.user.services = {
restic_prune = {
Unit.Description = "Restic prune service";
Service = {
Type = "oneshot";
ExecStart = toString (pkgs.writeShellScript "restic-prune" ''
. /etc/restic/local
restic prune
. /etc/restic/online
restic prune
'');
};
};
};
systemd.user.timers = {
restic_prune = {
Unit.Description = "Restic prune timer";
Timer = {OnCalendar = "Fri *-*-* 18:00:00";};
Install.WantedBy = ["timers.target"];
};
};
# systemd.user.services = {
# restic_backup = {
# Unit.Description = "Restic backup service";
# Service = {
# Type = "oneshot";
# ExecStart = toString (pkgs.writeShellScript "restic-backup" ''
# . /etc/restic/local
# restic backup --files-from /home/crony/.config/restic/list --verbose && restic forget --keep-last 10 --keep-daily 7 --keep-weekly 5 --keep-monthly 12
# . /etc/restic/online
# restic backup --files-from /home/crony/.config/restic/list --verbose && restic forget --keep-last 10 --keep-daily 7 --keep-weekly 5 --keep-monthly 12
# rsync -avP --delete "$HOME/.local/backup/" "$HOME/Documents/Share/backup"
# '');
# };
# };
# };
# systemd.user.timers = {
# restic_backup = {
# Unit.Description = "Restic backup timer";
# Timer = {
# OnBootSec = "5m";
# OnUnitActiveSec = "6h";
# };
# Install.WantedBy = ["timers.target"];
# };
# };
#
# # Restic check
# systemd.user.services = {
# restic_check = {
# Unit.Description = "Restic check service";
# Service = {
# Type = "oneshot";
# ExecStart = toString (pkgs.writeShellScript "restic-check" ''
# . /etc/restic/local
# restic check --read-data-subset=10%
# . /etc/restic/online
# restic check --read-data-subset=10%
# '');
# };
# };
# };
# systemd.user.timers = {
# restic_check = {
# Unit.Description = "Restic check timer";
# Timer = {OnCalendar = "Thu *-*-* 18:00:00";};
# Install.WantedBy = ["timers.target"];
# };
# };
#
# # Restic prune
# systemd.user.services = {
# restic_prune = {
# Unit.Description = "Restic prune service";
# Service = {
# Type = "oneshot";
# ExecStart = toString (pkgs.writeShellScript "restic-prune" ''
# . /etc/restic/local
# restic prune
# . /etc/restic/online
# restic prune
# '');
# };
# };
# };
# systemd.user.timers = {
# restic_prune = {
# Unit.Description = "Restic prune timer";
# Timer = {OnCalendar = "Fri *-*-* 18:00:00";};
# Install.WantedBy = ["timers.target"];
# };
# };
};
}

View file

@ -0,0 +1,19 @@
{
config,
lib,
...
}: {
options = {
crony.home-secrets.enable = lib.mkEnableOption "Enable home-manager secrets.";
};
config = lib.mkIf config.crony.home-secrets.enable {
age = {
secrets = {
restic-local-pass = {
file = ../../../secrets/restic-local-pass.age;
};
};
identityPaths = ["/home/crony/.ssh/main" "/root/.ssh/id_ed25519"];
};
};
}