base sort of working
This commit is contained in:
@@ -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
|
||||
]);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user