Move shared btrbk config into btrbkModule function

This commit is contained in:
asonix 2023-01-26 12:42:15 -06:00
parent 918a5a9d12
commit 563f43c5d1

View file

@ -84,21 +84,21 @@
sopsFile = ./secrets/whitestormKeyFile.bin;
};
};
});
services.btrbk = {
sshAccess = [
{
key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHTqU3EvTgY5/e9m6YyQWypQPK58t9iPmPnPYAvnODGB asonix@lionheart";
roles = [ "source" "info" "send" ];
}
];
extraPackages = with pkgs; [ gzip ];
instances.primary.settings = {
btrbkModule = ({ primaryIp ? null, mountDir, subvolumes }: { config, ... }:
let
primary = {
snapshot_preserve_min = "2d";
snapshot_preserve = "35d 20w 12m";
transaction_log = "/var/log/btrbk.log";
volume = {
"${mountDir}" = btrbkPrimary {
inherit subvolumes;
};
};
};
instances.secondary.settings = {
secondary = {
backend_remote = "btrfs-progs-sudo";
ssh_identity = config.sops.secrets.private_key.path;
ssh_user = "btrbk";
@ -109,35 +109,30 @@
target_preserve = "24h 7d";
target_preserve_min = "24h";
transaction_log = "/var/log/btrbk.log";
};
};
});
btrbkModule = ({ primaryIp ? null, mountDir, subvolumes }:
let
primary = {
services.btrbk.instances.primary = {
onCalendar = "hourly";
settings.volume = {
"${mountDir}" = btrbkPrimary {
inherit subvolumes;
};
};
};
};
secondary = {
services.btrbk.instances.secondary = {
onCalendar = "hourly";
settings.volume = {
"ssh://${primaryIp}${mountDir}" = btrbkSecondary {
target-dir = "${mountDir}/@snapshots";
inherit subvolumes;
};
volume = {
"ssh://${primaryIp}${mountDir}" = btrbkSecondary {
target-dir = "${mountDir}/@snapshots";
inherit subvolumes;
};
};
};
selected = if primaryIp == null then primary else secondary;
in
if primaryIp == null then primary else secondary
{
services.btrbk = {
sshAccess = [
{
key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHTqU3EvTgY5/e9m6YyQWypQPK58t9iPmPnPYAvnODGB asonix@lionheart";
roles = [ "source" "info" "send" ];
}
];
extraPackages = with pkgs; [ gzip ];
instances.btrbk = {
onCalendar = "hourly";
settings = selected;
};
};
}
);
makeDockerConfig = { hostname, extraModules ? [ ] }: