2023-07-18 12:31:48 +03:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
myData,
|
|
|
|
...
|
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
|
|
|
|
fs_zfs = lib.filterAttrs (n: v: v.fsType == "zfs") config.fileSystems;
|
|
|
|
mountpoint2fs =
|
|
|
|
builtins.listToAttrs
|
|
|
|
(map (mountpoint: {
|
|
|
|
name = mountpoint;
|
|
|
|
value = builtins.getAttr mountpoint fs_zfs;
|
|
|
|
})
|
|
|
|
config.mj.base.snapshot.mountpoints);
|
|
|
|
s_datasets =
|
|
|
|
lib.mapAttrs' (mountpoint: fs: {
|
|
|
|
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
|
|
|
}
|