diff --git a/homeManagerModules/restic/flake.nix b/homeManagerModules/restic/flake.nix index c35bfe1..ec84df1 100644 --- a/homeManagerModules/restic/flake.nix +++ b/homeManagerModules/restic/flake.nix @@ -23,8 +23,6 @@ }; vendorHash = "sha256-M9S6F/Csz7HnOq8PSWjpENKm1704kVx9zDts1ieraTE="; # Correct vendor hash goPackagePath = "github.com/creativeprojects/resticprofile"; - # (Optional) Include restic in checkInputs if tests require it: - # checkInputs = [ pkgs.restic ]; doCheck = false; # Disable tests due to sandboxed build environment meta = with lib; { description = "Configuration profiles manager and scheduler for restic backup"; diff --git a/homeManagerModules/restic/resticprofile-base.nix b/homeManagerModules/restic/resticprofile-base.nix new file mode 100644 index 0000000..e1b7447 --- /dev/null +++ b/homeManagerModules/restic/resticprofile-base.nix @@ -0,0 +1,27 @@ +{ lib, ... }: +{ + base = lib.mkDefault { + repository = "local:/mnt/backup"; + passwordFile = "password.txt"; + source = [ "/home/john/Documents" ]; + status-file = "{{ .ConfigDir }}/backup-status.json"; + retention = { + after-backup = true; + keep-last = "10"; + keep-hourly = "8"; + keep-daily = "14"; + keep-weekly = "8"; + }; + backup = { + verbose = true; + exclude-file = "{{ .ConfigDir }}/profiles/excludes"; + schedule-permission = "system"; + schedule-priority = "background"; + check-after = true; + }; + prune = { + schedule-permission = "user"; + schedule-lock-wait = "1h"; + }; + }; +} diff --git a/homeManagerModules/restic/resticprofile.nix b/homeManagerModules/restic/resticprofile.nix index 50075c1..4605c9a 100644 --- a/homeManagerModules/restic/resticprofile.nix +++ b/homeManagerModules/restic/resticprofile.nix @@ -3,17 +3,7 @@ let inherit (lib) mkEnableOption mkOption mkPackageOption mkIf types; cfg = config.programs.resticprofile; - - yamlFormat = pkgs.formats.yaml { }; - - # Function to generate xdg.configFile entries from an attrset of YAML configs - resticprofileConfigFilesToXdg = files: - lib.mapAttrs' (name: value: { - name = "resticprofile/${name}"; - value.source = yamlFormat.generate name value; - }) files; - in { options.programs.resticprofile = { enable = mkEnableOption "Enable resticprofile (Restic backup profile manager)"; @@ -21,16 +11,17 @@ in { package = mkPackageOption pkgs "resticprofile" { }; # Multiple configuration files support - configFiles = mkOption { + profiles = mkOption { type = types.attrsOf yamlFormat.type; default = { }; description = '' Multiple configuration files for resticprofile. Each attribute name becomes a YAML file under `$XDG_CONFIG_HOME/resticprofile/`. This allows creating multiple files that can reference each other. + The contents of each profile will be merged with the base profile using `lib.mkMerge`. ''; example = { - "profiles.yaml" = { + common = { repository = "local:/backup"; passwordFile = "password.txt"; includes = [ "common.yaml" ]; @@ -38,8 +29,6 @@ in { source = [ "/home/user/Documents" ]; schedule = "12:30"; }; - }; - "common.yaml" = { forget = { keep-daily = 7; keep-weekly = 4; @@ -52,10 +41,13 @@ in { config = mkIf cfg.enable { home.packages = [ cfg.package ]; - - # Use the function to generate xdg.configFile entries - xdg.configFile = lib.mkMerge [ - (resticprofileConfigFilesToXdg cfg.configFiles) - ]; + xdg.configFile."resticprofile/profiles.yaml".source = + let + baseProfile = import ./resticprofile-base.nix { inherit lib; }; + in + yamlFormat.generate "profiles" (lib.mkMerge [ + baseProfile + cfg.profiles + ]); }; }