95 lines
2.7 KiB
Nix
95 lines
2.7 KiB
Nix
{
|
|
lib,
|
|
config,
|
|
...
|
|
}: {
|
|
# TODO: create all of the datasets from option and home-manager datasets
|
|
# TODO: set up datasets for systemd services that want a dataset created
|
|
config = lib.mkMerge [
|
|
(
|
|
lib.mkIf config.storage.zfs.enable (lib.mkMerge [
|
|
{
|
|
storage.zfs.datasets = {
|
|
"persist/system/nix" = {
|
|
type = "zfs_fs";
|
|
mount = {
|
|
enable = true;
|
|
mountPoint = "/nix";
|
|
};
|
|
snapshot = {
|
|
autoSnapshot = false;
|
|
};
|
|
atime = "off";
|
|
relatime = "off";
|
|
};
|
|
"persist/system/var/log" = {
|
|
type = "zfs_fs";
|
|
mount = {
|
|
enable = true;
|
|
mountPoint = "/var/log";
|
|
};
|
|
snapshot = {
|
|
autoSnapshot = false;
|
|
};
|
|
};
|
|
};
|
|
}
|
|
(lib.mkIf (!config.storage.impermanence.enable) {
|
|
# TODO: create datasets for systemd.services.<name>.storage.impermanence.datasets
|
|
storage.zfs.datasets = {
|
|
"persist/system/root" = {
|
|
type = "zfs_fs";
|
|
mount = {
|
|
enable = false;
|
|
mountPoint = "/";
|
|
};
|
|
snapshot = {
|
|
autoSnapshot = true;
|
|
};
|
|
};
|
|
};
|
|
})
|
|
(lib.mkIf config.storage.impermanence.enable {
|
|
boot.initrd.postResumeCommands = lib.mkAfter ''
|
|
zfs rollback -r rpool/local/system/root@blank
|
|
'';
|
|
|
|
storage.zfs.datasets = {
|
|
"local/system/root" = {
|
|
type = "zfs_fs";
|
|
mount = {
|
|
enable = true;
|
|
mountPoint = "/";
|
|
};
|
|
snapshot = {
|
|
blankSnapshot = true;
|
|
};
|
|
};
|
|
};
|
|
|
|
storage.impermanence.datasets = {
|
|
"persist/system/root" = {
|
|
mount = {
|
|
enable = false;
|
|
mountPoint = "/";
|
|
};
|
|
directories = {
|
|
"/var/lib/nixos".enable = true;
|
|
"/var/lib/systemd/coredump".enable = true;
|
|
};
|
|
files = {
|
|
"/etc/machine-id".enable = true;
|
|
};
|
|
};
|
|
};
|
|
|
|
# TODO: home-manager.users.<user>.storage.impermanence.enable
|
|
# is false then persist the entire directory of the user
|
|
# if true persist home-manager.users.<user>.storage.impermanence.datasets
|
|
# TODO: systemd.services.<name>.storage.datasets persists
|
|
})
|
|
])
|
|
)
|
|
# TODO: configure other needed storage modes here
|
|
];
|
|
}
|