config/modules/base/snapshot/default.nix

45 lines
1.0 KiB
Nix
Raw Normal View History

2023-07-18 12:31:48 +03:00
{
config,
lib,
...
2023-07-18 16:32:45 +03:00
}: {
2023-07-18 12:31:48 +03:00
options.mj.base.snapshot = {
2023-07-18 16:32:45 +03:00
enable = lib.mkEnableOption "Enable zfs snapshots";
2023-07-18 12:31:48 +03:00
2023-07-18 16:32:45 +03:00
mountpoints = lib.mkOption {
2023-07-18 12:31:48 +03:00
default = {};
2023-07-18 16:32:45 +03:00
type = with lib.types; listOf str;
2023-07-18 12:31:48 +03:00
};
};
2023-07-18 16:32:45 +03:00
config = lib.mkIf config.mj.base.snapshot.enable {
services.sanoid = {
enable = true;
templates.prod = {
hourly = 24;
daily = 7;
autosnap = true;
autoprune = true;
};
extraArgs = ["--verbose"];
datasets = let
2023-09-30 17:06:41 +03:00
fs_zfs = lib.filterAttrs (_: v: v.fsType == "zfs") config.fileSystems;
2023-07-18 16:32:45 +03:00
mountpoint2fs =
builtins.listToAttrs
(map (mountpoint: {
name = mountpoint;
value = builtins.getAttr mountpoint fs_zfs;
})
config.mj.base.snapshot.mountpoints);
s_datasets =
2023-09-30 17:06:41 +03:00
lib.mapAttrs' (_mountpoint: fs: {
2023-07-18 16:32:45 +03:00
name = fs.device;
2023-07-18 12:31:48 +03:00
value = {use_template = ["prod"];};
})
2023-07-18 16:32:45 +03:00
mountpoint2fs;
in
s_datasets;
2023-07-18 12:31:48 +03:00
};
2023-07-18 16:32:45 +03:00
};
2023-07-18 12:31:48 +03:00
}