93 lines
2.2 KiB
Nix
93 lines
2.2 KiB
Nix
|
{ primaryIp ? null
|
||
|
, mountDir
|
||
|
, subvolumes
|
||
|
}:
|
||
|
|
||
|
{ config, pkgs, ... }:
|
||
|
|
||
|
let
|
||
|
btrbkPrimary = { subvolumes ? [ ] }: {
|
||
|
snapshot_dir = "@snapshots";
|
||
|
subvolume = builtins.foldl'
|
||
|
(acc: subvol: acc // {
|
||
|
${subvol} = { };
|
||
|
})
|
||
|
{ }
|
||
|
subvolumes;
|
||
|
};
|
||
|
|
||
|
btrbkSecondary = { targetDir, subvolumes ? [ ] }: {
|
||
|
target = "send-receive ${targetDir}";
|
||
|
subvolume = builtins.foldl'
|
||
|
(acc: subvol: acc // {
|
||
|
${subvol} = {
|
||
|
snapshot_dir = "@snapshots";
|
||
|
snapshot_preserve_min = "all";
|
||
|
snapshot_create = "no";
|
||
|
};
|
||
|
})
|
||
|
{ }
|
||
|
subvolumes;
|
||
|
};
|
||
|
|
||
|
primary = {
|
||
|
snapshot_preserve_min = "2d";
|
||
|
snapshot_preserve = "35d 20w 12m";
|
||
|
transaction_log = "/var/log/btrbk.log";
|
||
|
volume = {
|
||
|
"${mountDir}" = btrbkPrimary {
|
||
|
inherit subvolumes;
|
||
|
};
|
||
|
};
|
||
|
};
|
||
|
|
||
|
secondary = {
|
||
|
backend_remote = "btrfs-progs-sudo";
|
||
|
ssh_identity = config.sops.secrets.private_key.path;
|
||
|
ssh_user = "btrbk";
|
||
|
stream_buffer = "512m";
|
||
|
stream_compress = "gzip";
|
||
|
stream_compress_level = "default";
|
||
|
stream_compress_threads = "default";
|
||
|
target_preserve = "24h 7d";
|
||
|
target_preserve_min = "24h";
|
||
|
transaction_log = "/var/log/btrbk.log";
|
||
|
volume = {
|
||
|
"ssh://${primaryIp}${mountDir}" = btrbkSecondary {
|
||
|
targetDir = "${mountDir}/@snapshots";
|
||
|
inherit subvolumes;
|
||
|
};
|
||
|
};
|
||
|
};
|
||
|
|
||
|
selected = if primaryIp == null then primary else secondary;
|
||
|
in
|
||
|
{
|
||
|
sops.secrets.private_key = {
|
||
|
format = "yaml";
|
||
|
sopsFile = ../../secrets/btrbk.yaml;
|
||
|
owner = config.users.users.btrbk.name;
|
||
|
group = config.users.users.btrbk.group;
|
||
|
};
|
||
|
|
||
|
environment.systemPackages = with pkgs; [
|
||
|
btrbk
|
||
|
(writeShellScriptBin "restore-snapshot" (builtins.readFile ./restore-snapshot))
|
||
|
(writeShellScriptBin "restore-all-snapshots" (builtins.readFile ./restore-all-snapshots))
|
||
|
];
|
||
|
|
||
|
services.btrbk = {
|
||
|
sshAccess = [
|
||
|
{
|
||
|
key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHTqU3EvTgY5/e9m6YyQWypQPK58t9iPmPnPYAvnODGB asonix@lionheart";
|
||
|
roles = [ "source" "info" "send" ];
|
||
|
}
|
||
|
];
|
||
|
extraPackages = with pkgs; [ gzip ];
|
||
|
instances.btrbk = {
|
||
|
onCalendar = "hourly";
|
||
|
settings = selected;
|
||
|
};
|
||
|
};
|
||
|
}
|