From a739323b411167bccbb491e99fad0553b655d565 Mon Sep 17 00:00:00 2001 From: Fabian Montero Date: Thu, 28 Aug 2025 14:41:54 -0600 Subject: [PATCH] general: modularize borg/rsync config --- sys/modules/borgsync.nix | 63 ++++++++++++++++++++++++ sys/modules/default.nix | 1 + sys/platforms/posixlycorrect/borg.nix | 49 ------------------ sys/platforms/posixlycorrect/default.nix | 11 ++++- sys/platforms/vps/borg.nix | 48 ------------------ sys/platforms/vps/default.nix | 11 ++++- 6 files changed, 84 insertions(+), 99 deletions(-) create mode 100644 sys/modules/borgsync.nix delete mode 100644 sys/platforms/posixlycorrect/borg.nix delete mode 100644 sys/platforms/vps/borg.nix diff --git a/sys/modules/borgsync.nix b/sys/modules/borgsync.nix new file mode 100644 index 0000000..c5eeddc --- /dev/null +++ b/sys/modules/borgsync.nix @@ -0,0 +1,63 @@ +{ + config, + lib, + pkgs, + ... +}: +with lib; let + cfg = config.local.sys.borgsync; +in { + options.local.sys.borgsync = { + enable = mkEnableOption "borg backup to an rsync.net repo"; + paths = mkOption { + type = with types; nullOr (coercedTo str singleton (listOf str)); + default = null; + description = "Paths to back up."; + }; + exclude = mkOption { + type = with types; listOf str; + description = "Exclude paths."; + default = []; + }; + repoName = mkOption { + type = types.str; + description = "Remote rsync repository to back up to."; + }; + }; + + config = mkIf cfg.enable { + services.borgbackup.jobs.rsync = { + paths = cfg.paths; + exclude = cfg.exclude; + user = "root"; + group = "root"; + doInit = true; + startAt = [ + "hourly" + ]; + inhibitsSleep = true; + persistentTimer = true; + + repo = "zh5777@zh5777.rsync.net:${cfg.repoName}"; + encryption = { + mode = "repokey-blake2"; + passCommand = "cat /var/trust/borg/${cfg.repoName}_passphrase"; + }; + compression = "auto,lz4"; + prune = { + keep = { + hourly = 24; + daily = 7; + weekly = 4; + monthly = 12; + yearly = 99; + }; + }; + extraArgs = [ + "--remote-path=borg14" + ]; + }; + + environment.sessionVariables.BORG_REMOTE_PATH = "borg14"; + }; +} diff --git a/sys/modules/default.nix b/sys/modules/default.nix index 00f03d1..75e442d 100644 --- a/sys/modules/default.nix +++ b/sys/modules/default.nix @@ -16,6 +16,7 @@ ./net.nix ./steam.nix ./gtklock.nix + ./borgsync.nix ]; fonts.packages = with pkgs; [ diff --git a/sys/platforms/posixlycorrect/borg.nix b/sys/platforms/posixlycorrect/borg.nix deleted file mode 100644 index dca14d3..0000000 --- a/sys/platforms/posixlycorrect/borg.nix +++ /dev/null @@ -1,49 +0,0 @@ -{ - config, - pkgs, - lib, - flakes, - ... -}: { - services.borgbackup.jobs = { - rsync = { - paths = [ - "/home/fabian/nix" - "/home/fabian/safe" - "/extern/var/media" - "/extern/var/fsociety_backup" - ]; - exclude = [ - ]; - user = "root"; - group = "root"; - doInit = true; - startAt = [ - "hourly" - ]; - inhibitsSleep = true; - persistentTimer = true; - - repo = "zh5777@zh5777.rsync.net:posixlycorrect"; - encryption = { - mode = "repokey-blake2"; - passCommand = "cat /var/trust/borg/posixlycorrect_passphrase"; - }; - compression = "auto,lz4"; - prune = { - keep = { - hourly = 24; - daily = 7; - weekly = 4; - monthly = 12; - yearly = 99; - }; - }; - extraArgs = [ - "--remote-path=borg14" - ]; - }; - }; - - environment.sessionVariables.BORG_REMOTE_PATH = "borg14"; -} diff --git a/sys/platforms/posixlycorrect/default.nix b/sys/platforms/posixlycorrect/default.nix index f0d0f63..cf91bc2 100644 --- a/sys/platforms/posixlycorrect/default.nix +++ b/sys/platforms/posixlycorrect/default.nix @@ -9,7 +9,6 @@ flakes.home-manager.nixosModules.home-manager flakes.impermanence.nixosModule ./hardware-configuration.nix - ./borg.nix ]; local.sys = { @@ -22,6 +21,16 @@ androidSupport.enable = true; steam.enable = true; gtklock.enable = true; + borgsync = { + enable = true; + paths = [ + "/home/fabian/nix" + "/home/fabian/safe" + "/extern/var/media" + "/extern/var/fsociety_backup" + ]; + repoName = "posixlycorrect"; + }; users = { fabian = { diff --git a/sys/platforms/vps/borg.nix b/sys/platforms/vps/borg.nix deleted file mode 100644 index 9d9b0e7..0000000 --- a/sys/platforms/vps/borg.nix +++ /dev/null @@ -1,48 +0,0 @@ -{ - config, - pkgs, - lib, - flakes, - ... -}: { - services.borgbackup.jobs = { - rsync = { - paths = [ - "/var/lib/forgejo" - "/var/lib/mealie" - "/var/lib/trilium" - ]; - exclude = [ - ]; - user = "root"; - group = "root"; - doInit = true; - startAt = [ - "hourly" - ]; - inhibitsSleep = true; - persistentTimer = true; - - repo = "zh5777@zh5777.rsync.net:vps"; - encryption = { - mode = "repokey-blake2"; - passCommand = "cat /var/trust/borg/vps_passphrase"; - }; - compression = "auto,lz4"; - prune = { - keep = { - hourly = 24; - daily = 7; - weekly = 4; - monthly = 12; - yearly = 99; - }; - }; - extraArgs = [ - "--remote-path=borg14" - ]; - }; - }; - - environment.sessionVariables.BORG_REMOTE_PATH = "borg14"; -} diff --git a/sys/platforms/vps/default.nix b/sys/platforms/vps/default.nix index 4020acc..e96c67d 100644 --- a/sys/platforms/vps/default.nix +++ b/sys/platforms/vps/default.nix @@ -15,11 +15,20 @@ with lib; { ./hardware-configuration.nix ./srv ./networkMap.nix - ./borg.nix ]; local.sys = { baseline.enable = true; + + borgsync = { + enable = true; + paths = [ + "/var/lib/forgejo" + "/var/lib/mealie" + "/var/lib/trilium" + ]; + repoName = "vps"; + }; users.fabian = { enable = true;