nixos-config/linux/quasar/zfs.nix

103 lines
2.5 KiB
Nix
Raw Normal View History

2024-12-09 04:12:16 +00:00
{
config,
lib,
...
}: {
2024-12-09 15:39:16 +00:00
boot = {
loader.grub.zfsSupport = true;
zfs = {
extraPools = ["zarchive"];
requestEncryptionCredentials = ["zactive/main"];
};
};
2024-12-09 04:12:16 +00:00
services.zfs = {
autoScrub.enable = true;
trim.enable = true;
};
services.zrepl = {
enable = true;
settings = {
global = {
logging = [
{
type = "syslog";
level = "info";
format = "human";
}
];
};
jobs = let
2025-08-09 13:05:23 -05:00
archiveBaseName = "archive";
backupBaseName = "backup";
pushConfig = name: grid: {
2024-12-09 04:12:16 +00:00
type = "push";
2025-08-09 13:05:23 -05:00
name = "push-${name}";
2024-12-09 04:12:16 +00:00
connect = {
type = "local";
2025-08-09 13:05:23 -05:00
listener_name = "${name}-listener";
2024-12-09 04:12:16 +00:00
client_identity = config.networking.hostName;
};
filesystems."zactive/main/home" = true;
send.encrypted = true;
2025-08-09 13:05:23 -05:00
snapshotting.type = "manual";
2024-12-09 04:12:16 +00:00
pruning = {
keep_sender = [
{
2025-08-09 13:05:23 -05:00
type = "regex";
2024-12-09 04:12:16 +00:00
regex = "^zrepl-.*";
}
];
keep_receiver = [
{
type = "grid";
regex = "^zrepl-.*";
2025-08-09 13:05:23 -05:00
grid = lib.concatStringsSep " | " grid;
2024-12-09 04:12:16 +00:00
}
];
};
replication.protection = {
initial = "guarantee_resumability";
incremental = "guarantee_incremental";
};
2025-08-09 13:05:23 -05:00
};
sinkConfig = name: dataset: {
2024-12-09 04:12:16 +00:00
type = "sink";
2025-08-09 13:05:23 -05:00
name = "sink-${name}";
2024-12-09 04:12:16 +00:00
serve = {
type = "local";
2025-08-09 13:05:23 -05:00
listener_name = "${name}-listener";
2024-12-09 04:12:16 +00:00
};
2025-08-09 13:05:23 -05:00
root_fs = dataset;
2024-12-09 08:09:38 +00:00
recv.placeholder.encryption = "off";
2025-08-09 13:05:23 -05:00
};
in [
{
type = "snap";
name = "snapshot";
filesystems."zactive/main/home" = true;
snapshotting = {
type = "periodic";
prefix = "zrepl-";
interval = "1h";
};
pruning = {
keep = [
{
type = "grid";
regex = "^zrepl-.*";
grid = lib.concatStringsSep " | " ["1x1h(keep=all)" "24x1h" "7x1d" "4x1w"];
}
];
};
2024-12-09 04:12:16 +00:00
}
2025-08-09 13:05:23 -05:00
(pushConfig archiveBaseName ["1x1h(keep=all)" "30x1d" "52x1w"])
(pushConfig backupBaseName ["8x13w"])
(sinkConfig archiveBaseName "zarchive/snapshot")
(sinkConfig backupBaseName "zbackup/snapshot")
2024-12-09 04:12:16 +00:00
];
};
};
}