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 vendorHash = "sha256-M9S6F/Csz7HnOq8PSWjpENKm1704kVx9zDts1ieraTE="; # Correct vendor hash
goPackagePath = "github.com/creativeprojects/resticprofile"; 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 doCheck = false; # Disable tests due to sandboxed build environment
meta = with lib; { meta = with lib; {
description = "Configuration profiles manager and scheduler for restic backup"; 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 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)";
@@ -21,16 +11,17 @@ in {
package = mkPackageOption pkgs "resticprofile" { }; package = mkPackageOption pkgs "resticprofile" { };
# Multiple configuration files support # Multiple configuration files support
configFiles = mkOption { profiles = mkOption {
type = types.attrsOf yamlFormat.type; type = types.attrsOf yamlFormat.type;
default = { }; default = { };
description = '' description = ''
Multiple configuration files for resticprofile. Each attribute name Multiple configuration files for resticprofile. Each attribute name
becomes a YAML file under `$XDG_CONFIG_HOME/resticprofile/`. becomes a YAML file under `$XDG_CONFIG_HOME/resticprofile/`.
This allows creating multiple files that can reference each other. 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 = { example = {
"profiles.yaml" = { common = {
repository = "local:/backup"; repository = "local:/backup";
passwordFile = "password.txt"; passwordFile = "password.txt";
includes = [ "common.yaml" ]; includes = [ "common.yaml" ];
@@ -38,8 +29,6 @@ in {
source = [ "/home/user/Documents" ]; source = [ "/home/user/Documents" ];
schedule = "12:30"; schedule = "12:30";
}; };
};
"common.yaml" = {
forget = { forget = {
keep-daily = 7; keep-daily = 7;
keep-weekly = 4; keep-weekly = 4;
@@ -52,10 +41,13 @@ in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
home.packages = [ cfg.package ]; home.packages = [ cfg.package ];
xdg.configFile."resticprofile/profiles.yaml".source =
# Use the function to generate xdg.configFile entries let
xdg.configFile = lib.mkMerge [ baseProfile = import ./resticprofile-base.nix { inherit lib; };
(resticprofileConfigFilesToXdg cfg.configFiles) in
]; yamlFormat.generate "profiles" (lib.mkMerge [
baseProfile
cfg.profiles
]);
}; };
} }