50 lines
1 KiB
Nix
50 lines
1 KiB
Nix
|
{ config, lib, ... }:
|
||
|
let
|
||
|
cfg = config.custom.impermanence;
|
||
|
in
|
||
|
{
|
||
|
options.custom.impermanence.enable = lib.mkOption {
|
||
|
type = lib.types.bool;
|
||
|
default = false;
|
||
|
};
|
||
|
|
||
|
config = lib.mkIf cfg.enable {
|
||
|
# Default set of directories we always want to persist
|
||
|
environment.persistence."/persist" = {
|
||
|
enable = true;
|
||
|
hideMounts = true;
|
||
|
|
||
|
files = [
|
||
|
"/etc/machine-id"
|
||
|
"/etc/ssh/ssh_host_rsa_key"
|
||
|
"/etc/ssh/ssh_host_ed25519_key"
|
||
|
];
|
||
|
|
||
|
directories = [
|
||
|
"/var/lib/systemd/timers"
|
||
|
"/var/lib/nixos"
|
||
|
"/var/log"
|
||
|
];
|
||
|
};
|
||
|
|
||
|
fileSystems."/persist".neededForBoot = true;
|
||
|
|
||
|
services = {
|
||
|
fstrim.interval = "daily";
|
||
|
zfs = {
|
||
|
autoScrub.enable = true;
|
||
|
autoSnapshot = {
|
||
|
enable = true;
|
||
|
flags = "-k -p --utc";
|
||
|
};
|
||
|
trim.interval = "daily";
|
||
|
};
|
||
|
};
|
||
|
|
||
|
boot.initrd.postResumeCommands = lib.mkAfter ''
|
||
|
zfs rollback -r zroot/root@blank
|
||
|
zfs rollback -r zroot/home@blank
|
||
|
'';
|
||
|
};
|
||
|
}
|