62 lines
1.7 KiB
Nix
62 lines
1.7 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
|
|
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" { };
|
|
|
|
# Multiple configuration files support
|
|
configFiles = 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.
|
|
'';
|
|
example = {
|
|
"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;
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
|
|
config = mkIf cfg.enable {
|
|
home.packages = [ cfg.package ];
|
|
|
|
# Use the function to generate xdg.configFile entries
|
|
xdg.configFile = lib.mkMerge [
|
|
(resticprofileConfigFilesToXdg cfg.configFiles)
|
|
];
|
|
};
|
|
}
|