mirror of
https://codeberg.org/privacy1st/nix-git
synced 2024-11-22 22:09:34 +01:00
74 lines
2.1 KiB
Nix
74 lines
2.1 KiB
Nix
|
{ lib, config, options, pkgs, modulesPath, ... }:
|
||
|
with lib;
|
||
|
let
|
||
|
cfg = config.yoda.btrbkBackups;
|
||
|
daily = {
|
||
|
preserve-min = "no";
|
||
|
preserve = "7d 4w 6m";
|
||
|
};
|
||
|
in
|
||
|
{
|
||
|
options = {
|
||
|
yoda.btrbkBackups = mkOption {
|
||
|
type = types.listOf types.attrs;
|
||
|
default = [];
|
||
|
example = [{
|
||
|
# Optional.
|
||
|
# If this is `true` and `volume` starts with `ssh://`, `lz4` transport compression is enabled.
|
||
|
lz4 = true;
|
||
|
instance = "local-backup-ssd";
|
||
|
volume = "/jc-data";
|
||
|
snapshot_dir = "/snap";
|
||
|
target = "/mnt/backup/snap";
|
||
|
subvolume = {
|
||
|
"arch.p1st.de" = {};
|
||
|
};
|
||
|
}];
|
||
|
description = ''
|
||
|
List containing attrsets.
|
||
|
Each attrset is used to create one btrbk instance.
|
||
|
'';
|
||
|
};
|
||
|
};
|
||
|
|
||
|
# lib.forEach:
|
||
|
# https://github.com/NixOS/nixpkgs/blob/54f00576aa6139a9d54062d0edc2fb31423f0ffb/lib/lists.nix#L36
|
||
|
# lib.attrsets.mergeAttrsList:
|
||
|
# https://github.com/NixOS/nixpkgs/blob/54f00576aa6139a9d54062d0edc2fb31423f0ffb/lib/attrsets.nix#L786
|
||
|
config = {
|
||
|
services.btrbk.instances =
|
||
|
# Merge list of attr sets into one attr set.
|
||
|
attrsets.mergeAttrsList (
|
||
|
forEach
|
||
|
cfg
|
||
|
(x:
|
||
|
# `services.btrbk.instances` template.
|
||
|
{
|
||
|
"${x.instance}" = {
|
||
|
#onCalendar = null;
|
||
|
onCalendar = "00:05";
|
||
|
settings = {
|
||
|
timestamp_format = "long";
|
||
|
stream_compress = mkIf ((x.lz4 or false) && strings.hasPrefix "ssh://" x.volume) "lz4";
|
||
|
|
||
|
# Create backups.
|
||
|
target_preserve_min = daily.preserve-min;
|
||
|
target_preserve = daily.preserve;
|
||
|
|
||
|
# Don't create or delete snapshots.
|
||
|
snapshot_preserve_min = "all";
|
||
|
snapshot_create = "no";
|
||
|
|
||
|
volume."${x.volume}" = {
|
||
|
snapshot_dir = x.snapshot_dir;
|
||
|
target = x.target;
|
||
|
subvolume = x.subvolume;
|
||
|
};
|
||
|
};
|
||
|
};
|
||
|
}
|
||
|
)
|
||
|
);
|
||
|
};
|
||
|
}
|