multiple config files
This commit is contained in:
@@ -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 = {
|
||||||
repository = "local:/backup";
|
"profiles.yaml" = {
|
||||||
passwordFile = "password.txt";
|
repository = "local:/backup";
|
||||||
backup = {
|
passwordFile = "password.txt";
|
||||||
source = [ "/home/user/Documents" ];
|
includes = [ "common.yaml" ];
|
||||||
schedule = "12:30";
|
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 {
|
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)
|
||||||
|
];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user