base sort of working

This commit is contained in:
John Lancaster
2025-07-28 17:43:45 -05:00
parent 2b2e4ca76a
commit 29a1ee26cf
3 changed files with 38 additions and 21 deletions

View File

@@ -23,8 +23,6 @@
};
vendorHash = "sha256-M9S6F/Csz7HnOq8PSWjpENKm1704kVx9zDts1ieraTE="; # Correct vendor hash
goPackagePath = "github.com/creativeprojects/resticprofile";
# (Optional) Include restic in checkInputs if tests require it:
# checkInputs = [ pkgs.restic ];
doCheck = false; # Disable tests due to sandboxed build environment
meta = with lib; {
description = "Configuration profiles manager and scheduler for restic backup";

View File

@@ -0,0 +1,27 @@
{ lib, ... }:
{
base = lib.mkDefault {
repository = "local:/mnt/backup";
passwordFile = "password.txt";
source = [ "/home/john/Documents" ];
status-file = "{{ .ConfigDir }}/backup-status.json";
retention = {
after-backup = true;
keep-last = "10";
keep-hourly = "8";
keep-daily = "14";
keep-weekly = "8";
};
backup = {
verbose = true;
exclude-file = "{{ .ConfigDir }}/profiles/excludes";
schedule-permission = "system";
schedule-priority = "background";
check-after = true;
};
prune = {
schedule-permission = "user";
schedule-lock-wait = "1h";
};
};
}

View File

@@ -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
]);
};
}