diff --git a/homeManagerModules/restic/resticprofile.nix b/homeManagerModules/restic/resticprofile.nix index 0163483..50075c1 100644 --- a/homeManagerModules/restic/resticprofile.nix +++ b/homeManagerModules/restic/resticprofile.nix @@ -4,43 +4,58 @@ 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)"; package = mkPackageOption pkgs "resticprofile" { }; - # Config structured as an attrset that maps to resticprofile's YAML format - config = mkOption { - type = yamlFormat.type; + # Multiple configuration files support + configFiles = mkOption { + type = types.attrsOf yamlFormat.type; default = { }; description = '' - Configuration for resticprofile, which will be written as YAML to - `$XDG_CONFIG_HOME/resticprofile/profiles.yaml`. + 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. ''; example = { - repository = "local:/backup"; - passwordFile = "password.txt"; - backup = { - source = [ "/home/user/Documents" ]; - schedule = "12:30"; + "profiles.yaml" = { + repository = "local:/backup"; + passwordFile = "password.txt"; + includes = [ "common.yaml" ]; + backup = { + source = [ "/home/user/Documents" ]; + schedule = "12:30"; + }; + }; + "common.yaml" = { + forget = { + keep-daily = 7; + keep-weekly = 4; + keep-monthly = 6; + }; }; }; }; - - configFile = mkOption { - type = types.str; - default = "profiles.yaml"; - description = "The configuration file name under $XDG_CONFIG_HOME/resticprofile/"; - }; }; config = mkIf cfg.enable { home.packages = [ cfg.package ]; - xdg.configFile."resticprofile/${cfg.configFile}".source = - yamlFormat.generate "resticprofile-config" cfg.config; + # Use the function to generate xdg.configFile entries + xdg.configFile = lib.mkMerge [ + (resticprofileConfigFilesToXdg cfg.configFiles) + ]; }; }