From 12ac5f45aa0660d67acdb98b673122024be5f377 Mon Sep 17 00:00:00 2001 From: Ryan Yin Date: Mon, 21 Sep 2026 19:04:58 +0800 Subject: [PATCH] feat(idols-ai): restic backup to a local repository Allowlist of the irreplaceable directories (Documents, work, Pictures, nix-config, .local/state); project checkouts under ~/codes live in git and are not backed up. Kept the excludes generic, since this repo is public. Also move the restic-password secret to a desktop.enable || server.storage gate so desktops get it without enabling a server group. --- hosts/idols-ai/restic.nix | 40 +++++++++++++++++++++++++++++++++++++++ secrets/nixos.nix | 18 ++++++++++++------ 2 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 hosts/idols-ai/restic.nix diff --git a/hosts/idols-ai/restic.nix b/hosts/idols-ai/restic.nix new file mode 100644 index 00000000..87b807aa --- /dev/null +++ b/hosts/idols-ai/restic.nix @@ -0,0 +1,40 @@ +{ + ... +}: +{ + # Part 1 of the backup plan: a local restic repository on this machine. + # The off-machine target (youko, or a cloud) is a later step. + # + # Be specific here and keep `exclude` minimal: an allowlist of the few + # directories that are actually irreplaceable beats backing up a broad tree + # and excluding half of it. Project checkouts under ~/codes are tracked in + # git (or have remotes), so they are not backed up at all. + modules.restic-backup = { + enable = true; + repository = "/var/lib/backups/restic/idols-ai"; + + paths = [ + "/home/ryan/Documents" + "/home/ryan/work" + "/home/ryan/Pictures" + "/home/ryan/nix-config" + "/home/ryan/.local/state" + ]; + + exclude = [ + # generic patterns only; this repository is public + "**/node_modules" + "**/target" + "**/.venv" + "**/venv" + "**/.next" + "**/dist" + "**/build" + "**/.direnv" + "**/result*" + "**/__pycache__" + "**/.pytest_cache" + "**/.ruff_cache" + ]; + }; +} diff --git a/secrets/nixos.nix b/secrets/nixos.nix index 63e10cd2..b159d8e7 100644 --- a/secrets/nixos.nix +++ b/secrets/nixos.nix @@ -213,6 +213,16 @@ in }; }) + (mkIf (cfg.desktop.enable || cfg.server.storage.enable) { + # the restic repository password, needed by modules.restic-backup on both + # the homelab servers and the desktops + age.secrets."restic-password" = { + file = "${mysecrets}/restic-password.age"; + mode = "0400"; + owner = "root"; + }; + }) + (mkIf cfg.server.storage.enable { age.secrets = { "hdd-luks-crypt-key" = { @@ -220,12 +230,8 @@ in mode = "0400"; owner = "root"; }; - # restic repository password (used by modules.restic-backup) - "restic-password" = { - file = "${mysecrets}/restic-password.age"; - mode = "0400"; - owner = "root"; - }; + # restic repository password (used by modules.restic-backup). Gated + # separately below so desktops get it without enabling a server group. }; # place secrets in /etc/