mirror of
https://github.com/foo-dogsquared/nixos-config.git
synced 2025-01-30 22:57:55 +00:00
home-manager/programs/borgmatic: init replacement module
This commit is contained in:
parent
86157bc1a2
commit
d6a634f50a
@ -5,6 +5,7 @@
|
||||
./programs/pipewire.nix
|
||||
./programs/pop-launcher.nix
|
||||
./programs/zed-editor.nix
|
||||
./programs/borgmatic.nix
|
||||
./services/archivebox.nix
|
||||
./services/bleachbit.nix
|
||||
./services/distant.nix
|
||||
|
117
modules/home-manager/programs/borgmatic.nix
Normal file
117
modules/home-manager/programs/borgmatic.nix
Normal file
@ -0,0 +1,117 @@
|
||||
# A replacement module for the Borgmatic home-manager module. It is quite
|
||||
# limited and also feels janky to use.
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
let
|
||||
cfg = config.programs.borgmatic;
|
||||
|
||||
settingsFormat = pkgs.formats.yaml { };
|
||||
|
||||
borgmaticBackupsModule = { name, lib, ... }: {
|
||||
options = {
|
||||
settings = lib.mkOption {
|
||||
type = settingsFormat.type;
|
||||
default = { };
|
||||
example = lib.literalExpression ''
|
||||
{
|
||||
source_directories = [
|
||||
"''${config.xdg.configHome}"
|
||||
"''${config.xdg.userDirs.extraConfig.XDG_PROJECTS_DIR}"
|
||||
"''${config.home.homeDirectory}/.thunderbird"
|
||||
"''${config.home.homeDirectory}/Zotero"
|
||||
];
|
||||
|
||||
repositories = [
|
||||
{
|
||||
path = "ssh://k8pDxu32@k8pDxu32.repo.borgbase.com/./repo";
|
||||
label = "borgbase";
|
||||
}
|
||||
|
||||
{
|
||||
path = "/var/lib/backups/local.borg";
|
||||
label = "local";
|
||||
}
|
||||
];
|
||||
|
||||
keep_daily = 7;
|
||||
keep_weekly = 4;
|
||||
keep_monthly = 6;
|
||||
|
||||
checks = [
|
||||
{ name = "repository"; }
|
||||
{ name = "archives"; frequency = "2 weeks"; }
|
||||
];
|
||||
}
|
||||
'';
|
||||
};
|
||||
|
||||
validateConfig =
|
||||
lib.mkEnableOption "validation step for the resulting configuration" // {
|
||||
default = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
mkBorgmaticConfig = n: v:
|
||||
lib.nameValuePair "borgmatic.d/${n}.yaml" {
|
||||
source = let
|
||||
settingsFile = settingsFormat.generate "borgmatic-config-${n}" v.settings;
|
||||
|
||||
borgmaticValidateCmd =
|
||||
if lib.versionOlder cfg.package.version "1.7.15" then
|
||||
"borgmatic config validate --config ${settingsFile}"
|
||||
else
|
||||
"validate-borgmatic-config --config ${settingsFile}";
|
||||
in
|
||||
if v.validateConfig then
|
||||
pkgs.runCommand "generate-borgmatic-config-with-validation" {
|
||||
buildInputs = [ cfg.package ];
|
||||
preferLocalBuild = true;
|
||||
} ''
|
||||
${borgmaticValidateCmd} && install ${settingsFile} $out
|
||||
''
|
||||
else
|
||||
settingsFile;
|
||||
};
|
||||
in
|
||||
{
|
||||
disabledModules = [ "programs/borgmatic.nix" ];
|
||||
options.programs.borgmatic = {
|
||||
enable = lib.mkEnableOption "configuring Borg backups with Borgmatic";
|
||||
|
||||
package = lib.mkPackageOption pkgs "borgmatic" { };
|
||||
|
||||
backups = lib.mkOption {
|
||||
type = with lib.types; attrsOf (submodule borgmaticBackupsModule);
|
||||
default = { };
|
||||
example = lib.literalExpression ''
|
||||
{
|
||||
personal = {
|
||||
validateConfig = true;
|
||||
settings = {
|
||||
source_directories = [
|
||||
config.xdg.configHome
|
||||
config.xdg.userDirs.documents
|
||||
config.xdg.userDirs.photos
|
||||
];
|
||||
|
||||
repositories = lib.singleton {
|
||||
path = "ssh://alskdjalskdjalsdkj";
|
||||
label = "remote-hetzner-box";
|
||||
};
|
||||
|
||||
keep_daily = 7;
|
||||
keep_weekly = 6;
|
||||
keep_monthly = 6;
|
||||
}
|
||||
};
|
||||
}
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
home.packages = [ cfg.package ];
|
||||
xdg.configFile = lib.mapAttrs' mkBorgmaticConfig cfg.backups;
|
||||
};
|
||||
}
|
@ -51,7 +51,9 @@ in
|
||||
import nmt {
|
||||
inherit pkgs lib modules;
|
||||
testedAttrPath = [ "home" "activationPackage" ];
|
||||
# TODO: Fix nmt to accept specialArgs or something.
|
||||
tests = builtins.foldl' (a: b: a // (import b)) { } ([
|
||||
#./programs/borgmatic
|
||||
./programs/neovide
|
||||
./programs/pipewire
|
||||
./programs/pop-launcher
|
||||
|
23
tests/modules/home-manager/programs/borgmatic/basic.nix
Normal file
23
tests/modules/home-manager/programs/borgmatic/basic.nix
Normal file
@ -0,0 +1,23 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
{
|
||||
programs.borgmatic = {
|
||||
enable = true;
|
||||
backups = {
|
||||
personal.settings = {
|
||||
hello = "WORLD";
|
||||
};
|
||||
|
||||
bizness.settings = {
|
||||
hello = "MONEY";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
test.stubs.borgmatic = { };
|
||||
|
||||
nmt.script = ''
|
||||
assertFileExists home-files/.config/borgmatic.d/personal.yaml
|
||||
assertFileExists home-files/.config/borgmatic.d/bizness.yaml
|
||||
'';
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
{
|
||||
borgmatic-basic = ./basic.nix;
|
||||
borgmatic-multiple-configurations = ./multiple-configurations.nix;
|
||||
}
|
Loading…
Reference in New Issue
Block a user