multiple config files

This commit is contained in:
John Lancaster
2025-07-28 13:51:42 -05:00
parent 9542980896
commit 2b2e4ca76a

View File

@@ -4,43 +4,58 @@ let
inherit (lib) mkEnableOption mkOption mkPackageOption mkIf types; inherit (lib) mkEnableOption mkOption mkPackageOption mkIf types;
cfg = config.programs.resticprofile; cfg = config.programs.resticprofile;
yamlFormat = pkgs.formats.yaml { }; 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 { in {
options.programs.resticprofile = { options.programs.resticprofile = {
enable = mkEnableOption "Enable resticprofile (Restic backup profile manager)"; enable = mkEnableOption "Enable resticprofile (Restic backup profile manager)";
package = mkPackageOption pkgs "resticprofile" { }; package = mkPackageOption pkgs "resticprofile" { };
# Config structured as an attrset that maps to resticprofile's YAML format # Multiple configuration files support
config = mkOption { configFiles = mkOption {
type = yamlFormat.type; type = types.attrsOf yamlFormat.type;
default = { }; default = { };
description = '' description = ''
Configuration for resticprofile, which will be written as YAML to Multiple configuration files for resticprofile. Each attribute name
`$XDG_CONFIG_HOME/resticprofile/profiles.yaml`. becomes a YAML file under `$XDG_CONFIG_HOME/resticprofile/`.
This allows creating multiple files that can reference each other.
''; '';
example = { example = {
"profiles.yaml" = {
repository = "local:/backup"; repository = "local:/backup";
passwordFile = "password.txt"; passwordFile = "password.txt";
includes = [ "common.yaml" ];
backup = { backup = {
source = [ "/home/user/Documents" ]; source = [ "/home/user/Documents" ];
schedule = "12:30"; 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 { config = mkIf cfg.enable {
home.packages = [ cfg.package ]; home.packages = [ cfg.package ];
xdg.configFile."resticprofile/${cfg.configFile}".source = # Use the function to generate xdg.configFile entries
yamlFormat.generate "resticprofile-config" cfg.config; xdg.configFile = lib.mkMerge [
(resticprofileConfigFilesToXdg cfg.configFiles)
];
}; };
} }