base/snapshot: move sanoid there

This commit is contained in:
Motiejus Jakštys 2023-07-18 16:32:45 +03:00
parent 46e2d86918
commit 97f720558d
3 changed files with 40 additions and 62 deletions

View File

@ -67,11 +67,17 @@ in {
stateVersion = "22.11"; stateVersion = "22.11";
timeZone = "UTC"; timeZone = "UTC";
base.initrd = { base = {
initrd = {
enable = true; enable = true;
authorizedKeys = builtins.attrValues myData.ssh_pubkeys; authorizedKeys = builtins.attrValues myData.ssh_pubkeys;
hostKeys = ["/etc/secrets/initrd/ssh_host_ed25519_key"]; hostKeys = ["/etc/secrets/initrd/ssh_host_ed25519_key"];
}; };
snapshot = {
enable = true;
mountpoints = ["/var/lib" "/var/log"];
};
};
}; };
users = { users = {
@ -141,23 +147,6 @@ in {
localuser = null; localuser = null;
}; };
sanoid = {
enable = true;
templates.prod = {
hourly = 24;
daily = 7;
autosnap = true;
autoprune = true;
};
datasets =
lib.mapAttrs' (name: value: {
name = value.zfs_name;
value = {use_template = ["prod"];};
})
backup_paths;
extraArgs = ["--verbose"];
};
borgbackup.jobs = borgbackup.jobs =
lib.mapAttrs' (name: value: let lib.mapAttrs' (name: value: let
snapshot = { snapshot = {

View File

@ -10,16 +10,6 @@ in {
stateVersion = "23.05"; stateVersion = "23.05";
timeZone = "UTC"; timeZone = "UTC";
stubPasswords = true; stubPasswords = true;
base.snapshot = {
enable = true;
pools = {
var_lib = {
mountpoint = "/var/lib";
zfs_name = "rpool/nixos/var/lib";
};
};
};
}; };
environment = { environment = {

View File

@ -3,30 +3,18 @@
lib, lib,
myData, myData,
... ...
}: }: {
with lib; {
options.mj.base.snapshot = { options.mj.base.snapshot = {
enable = mkEnableOption "Enable zfs snapshots"; enable = lib.mkEnableOption "Enable zfs snapshots";
pools = mkOption { mountpoints = lib.mkOption {
default = {}; default = {};
type = with types; type = with lib.types; listOf str;
attrsOf (submodule (
{...}: {
options = {
mountpoint = mkOption {type = str;};
zfs_name = mkOption {type = str;};
#paths = mkOption { type = listOf str; };
#backup_at = mkOption { type = str; };
};
}
));
}; };
}; };
config = with config.mj.base.snapshot; config = lib.mkIf config.mj.base.snapshot.enable {
mkIf enable { services.sanoid = {
sanoid = {
enable = true; enable = true;
templates.prod = { templates.prod = {
hourly = 24; hourly = 24;
@ -34,13 +22,24 @@ with lib; {
autosnap = true; autosnap = true;
autoprune = true; autoprune = true;
}; };
datasets = extraArgs = ["--verbose"];
lib.mapAttrs' (name: value: { datasets = let
name = value.zfs_name; 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;
value = {use_template = ["prod"];}; value = {use_template = ["prod"];};
}) })
pools; mountpoint2fs;
extraArgs = ["--verbose"]; in
s_datasets;
}; };
}; };
} }