1
0
Fork 0

allow to stagger backup jobs

This commit is contained in:
ibizaman 2023-12-08 10:44:47 -08:00 committed by Pierre Penninckx
parent c2ac071c72
commit 3c9f71da0e
2 changed files with 55 additions and 17 deletions

View file

@ -25,12 +25,32 @@ let
ghRoot = (gitHubDeclaration "ibizaman" "selfhostblocks" "").url;
buildOptionsDocs = args@{ modules, includeModuleSystemOptions ? true, ... }:
let options = (lib.evalModules { inherit modules; }).options;
let
config = {
_module.check = false;
_module.args = {};
system.stateVersion = "22.11";
};
utils = import "${pkgs.path}/nixos/lib/utils.nix" {
inherit config lib;
pkgs = null;
};
eval = lib.evalModules {
inherit modules;
specialArgs = {
inherit utils;
};
};
options = if includeModuleSystemOptions
then eval.options
else builtins.removeAttrs eval.options [ "_module" ];
in buildPackages.nixosOptionsDoc ({
options = if includeModuleSystemOptions then
options
else
builtins.removeAttrs options [ "_module" ];
inherit options;
transformOptions = opt:
opt // {
# Clean up declaration sites to not refer to the Home Manager

View file

@ -1,4 +1,4 @@
{ config, pkgs, lib, ... }:
{ config, pkgs, lib, utils, ... }:
let
cfg = config.shb.backup;
@ -37,7 +37,28 @@ let
repositories = lib.mkOption {
description = "Repositories to back this instance to.";
type = lib.types.nonEmptyListOf lib.types.str;
type = lib.types.nonEmptyListOf (lib.types.submodule {
options = {
path = lib.mkOption {
type = lib.types.str;
description = "Repository location";
};
timerConfig = lib.mkOption {
type = lib.types.attrsOf utils.systemdUtils.unitOptions.unitOption;
default = {
OnCalendar = "daily";
Persistent = true;
};
description = ''When to run the backup. See {manpage}`systemd.timer(5)` for details.'';
example = {
OnCalendar = "00:05";
RandomizedDelaySec = "5h";
Persistent = true;
};
};
};
});
};
retention = lib.mkOption {
@ -191,15 +212,15 @@ in
group = cfg.group;
};
}
] ++ lib.optional ((lib.filter (lib.strings.hasPrefix "s3") instance.repositories) != []) {
] ++ lib.optional ((lib.filter ({path, ...}: lib.strings.hasPrefix "s3" path) instance.repositories) != []) {
"${instance.backend}/environmentfiles/${if isNull instance.secretName then name else instance.secretName}" = {
sopsFile = instance.keySopsFile;
mode = "0440";
owner = cfg.user;
group = cfg.group;
};
} ++ lib.optionals (instance.backend == "borgmatic") (lib.flatten (map (repository: {
"${instance.backend}/keys/${repoSlugName repository}" = {
} ++ lib.optionals (instance.backend == "borgmatic") (lib.flatten (map ({path, ...}: {
"${instance.backend}/keys/${repoSlugName path}" = {
key = "${instance.backend}/keys/${if isNull instance.secretName then name else instance.secretName}";
sopsFile = instance.keySopsFile;
mode = "0440";
@ -244,7 +265,7 @@ in
location =
{
source_directories = instance.sourceDirectories;
repositories = instance.repositories;
repositories = map ({path, ...}: path) instance.repositories;
}
// (lib.attrsets.optionalAttrs (builtins.length instance.excludePatterns > 0) {
excludePatterns = instance.excludePatterns;
@ -284,9 +305,9 @@ in
services.restic.backups =
let
mkRepositorySettings = name: instance: repository: {
"${name}_${repoSlugName repository}" = {
"${name}_${repoSlugName repository.path}" = {
inherit (cfg) user;
inherit repository;
repository = repository.path;
paths = instance.sourceDirectories;
@ -294,10 +315,7 @@ in
initialize = true;
timerConfig = {
OnCalendar = "00,12:00:00";
RandomizedDelaySec = "5m";
};
inherit (repository) timerConfig;
pruneOpts = lib.mapAttrsToList (name: value:
"--${builtins.replaceStrings ["_"] ["-"] name} ${builtins.toString value}"