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";
timeZone = "UTC";
base.initrd = {
base = {
initrd = {
enable = true;
authorizedKeys = builtins.attrValues myData.ssh_pubkeys;
hostKeys = ["/etc/secrets/initrd/ssh_host_ed25519_key"];
};
snapshot = {
enable = true;
mountpoints = ["/var/lib" "/var/log"];
};
};
};
users = {
@ -141,23 +147,6 @@ in {
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 =
lib.mapAttrs' (name: value: let
snapshot = {

View File

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

View File

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