config/modules/base/snapshot/default.nix

42 lines
1.0 KiB
Nix
Raw Permalink Normal View History

2024-07-29 15:39:54 +03:00
{ config, lib, ... }:
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 {
2024-07-29 15:39:54 +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;
};
2024-07-29 15:39:54 +03:00
extraArgs = [ "--verbose" ];
datasets =
let
fs_zfs = lib.filterAttrs (_: v: v.fsType == "zfs") config.fileSystems;
mountpoint2fs = builtins.listToAttrs (
map (mountpoint: {
2023-07-18 16:32:45 +03:00
name = mountpoint;
value = builtins.getAttr mountpoint fs_zfs;
2024-07-29 15:39:54 +03:00
}) config.mj.base.snapshot.mountpoints
);
s_datasets = lib.mapAttrs' (_mountpoint: fs: {
2023-07-18 16:32:45 +03:00
name = fs.device;
2024-07-29 15:39:54 +03:00
value = {
use_template = [ "prod" ];
};
}) mountpoint2fs;
in
2023-07-18 16:32:45 +03:00
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
}