storage-refactor #9

Open
jan-leila wants to merge 40 commits from storage-refactor into main
3 changed files with 73 additions and 51 deletions
Showing only changes of commit f8edad75bf - Show all commits

View file

@ -10,6 +10,16 @@
lib.mkIf config.storage.zfs.enable (lib.mkMerge [ lib.mkIf config.storage.zfs.enable (lib.mkMerge [
{ {
storage.zfs.datasets = { storage.zfs.datasets = {
"persist" = {
type = "zfs_fs";
};
"persist/local" = {
type = "zfs_fs";
};
"persist/replicate" = {
type = "zfs_fs";
};
"persist/local/nix" = { "persist/local/nix" = {
type = "zfs_fs"; type = "zfs_fs";
mount = { mount = {
@ -22,6 +32,7 @@
atime = "off"; atime = "off";
relatime = "off"; relatime = "off";
}; };
"persist/replicate/system/var/log" = { "persist/replicate/system/var/log" = {
type = "zfs_fs"; type = "zfs_fs";
mount = { mount = {
@ -54,6 +65,9 @@
''; '';
storage.zfs.datasets = { storage.zfs.datasets = {
"ephemeral" = {
type = "zfs_fs";
};
"ephemeral/system/root" = { "ephemeral/system/root" = {
type = "zfs_fs"; type = "zfs_fs";
mount = { mount = {

View file

@ -73,11 +73,7 @@
snapshot = { snapshot = {
# This option should set this option flag # This option should set this option flag
# "com.sun:auto-snapshot" = "false"; # "com.sun:auto-snapshot" = "false";
autoSnapshot = lib.mkOption { autoSnapshot = lib.mkEnableOption "Enable automatic snapshots for this dataset";
type = lib.types.bool;
default = false;
description = "Enable automatic snapshots for this dataset";
};
# Creates a blank snapshot in the post create hook for rollback purposes # Creates a blank snapshot in the post create hook for rollback purposes
blankSnapshot = lib.mkEnableOption "Should a blank snapshot be auto created in the post create hook"; blankSnapshot = lib.mkEnableOption "Should a blank snapshot be auto created in the post create hook";
}; };

View file

@ -399,13 +399,10 @@ in {
}; };
}; };
} }
(lib.mkIf config.storage.impermanence.enable (lib.mkMerge [
(lib.mkIf config.storage.zfs.enable (lib.mkMerge [ (lib.mkIf config.storage.zfs.enable (lib.mkMerge [
{ {
# sops age key needs to be available to pre persist for user generation # sops age key needs to be available to pre persist for user generation
storage.zfs.datasets = lib.mkMerge [ storage.zfs.datasets."persist/local/system/sops" = {
{
"persist/local/system/sops" = {
type = "zfs_fs"; type = "zfs_fs";
mount = { mount = {
enable = true; enable = true;
@ -415,7 +412,23 @@ in {
relatime = "off"; relatime = "off";
}; };
} }
(lib.mkMerge ( (lib.mkIf (!config.storage.impermanence.enable) {
storage.zfs.datasets = lib.mkMerge (
builtins.map (user: {
"persist/replicate/home/${user.name}" = {
type = "zfs_fs";
mount = {
enable = true;
mountPoint = "/home/${user.name}";
};
snapshot.autoSnapshot = true;
};
})
normalUsers
);
})
(lib.mkIf config.storage.impermanence.enable {
storage.zfs.datasets = lib.mkMerge (
builtins.map (user: { builtins.map (user: {
"ephemeral/home/${user.name}" = { "ephemeral/home/${user.name}" = {
type = "zfs_fs"; type = "zfs_fs";
@ -427,8 +440,7 @@ in {
}; };
}) })
normalUsers normalUsers
)) );
];
# Post resume commands to rollback user home datasets to blank snapshots # Post resume commands to rollback user home datasets to blank snapshots
boot.initrd.postResumeCommands = lib.mkAfter ( boot.initrd.postResumeCommands = lib.mkAfter (
@ -436,16 +448,16 @@ in {
normalUsers) normalUsers)
); );
# TODO: I don't think we need this anymore but I have not tested it
# Create persist home directories with proper permissions # Create persist home directories with proper permissions
systemd = { # systemd = {
tmpfiles.rules = # tmpfiles.rules =
builtins.map ( # builtins.map (
user: "d /persist/replicate/home/${user.name} 700 ${user.name} ${user.name} -" # user: "d /persist/replicate/home/${user.name} 700 ${user.name} ${user.name} -"
) # )
normalUsers; # normalUsers;
}; # };
} })
]))
])) ]))
]; ];
} }