commit ce935087647d16d27dce16e7507904210699eaf0 parent 3ce02ded020d83272ecad74b1415f0c30e67c5f6 Author: breadcat <breadcat@users.noreply.github.com> Date: Wed, 30 Jul 2025 18:37:44 +0100 Add backup-cloud restic script Depends on restic.env which contains RESTIC_REPOSITORY and RESTIC_PASSWORD_FILE Diffstat:
A | common/restic.nix | | | 40 | ++++++++++++++++++++++++++++++++++++++++ |
M | machines/ilias.nix | | | 1 | + |
2 files changed, 41 insertions(+), 0 deletions(-)
diff --git a/common/restic.nix b/common/restic.nix @@ -0,0 +1,40 @@ +{ pkgs, username, ... }: + +let + backup-cloud = pkgs.writeShellScriptBin "backup-cloud" '' + # variables + directories=( "$HOME/docker/" "$HOME/vault/" ) + # process + source "$HOME/vault/docs/secure/restic.env" + # Directory loop + for dir in "''${directories[@]}"; do + if [[ -d "$dir" ]]; then + echo "Directory exists: $dir" + ${pkgs.restic}/bin/restic backup "$dir" + else + echo "Directory does not exist: $dir" + fi + done + ''; +in { + environment.systemPackages = [ backup-cloud ]; + + systemd.services.restic-backup = { + description = "Backup specific directories to BorgBase"; + script = "backup-cloud"; + serviceConfig = { + Type = "oneshot"; + User = "${username}"; + # ExecStart = "${backup-cloud}/bin/backup-cloud"; + }; + }; + + systemd.timers.restic-backup = { + description = "Timer to run Restic backup"; + wantedBy = [ "timers.target" ]; + timerConfig = { + OnActiveSec = "12h"; + Persistent = true; + }; + }; +} diff --git a/machines/ilias.nix b/machines/ilias.nix @@ -18,6 +18,7 @@ in { imports = [ ./${machine}-hardware.nix # Include the results of the hardware scan. (import "${home-manager}/nixos") # Home-Manager + (import ../common/restic.nix {inherit pkgs username;}) ../common/flakes.nix ../common/garbage.nix ../common/locale.nix