2025-05-29 16:34:24 +02:00
|
|
|
{ lib, config, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.modules.impermanence;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.modules.impermanence = {
|
|
|
|
enable = mkEnableOption "Impermanence";
|
|
|
|
directories = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ ];
|
|
|
|
description = ''
|
|
|
|
Directories that should be stored in persistent storage.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
files = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ ];
|
|
|
|
description = ''
|
|
|
|
Files that should be stored in persistent storage.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
resetScript = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
description = ''
|
2025-06-11 11:58:54 +02:00
|
|
|
Script to run in order to reset the system to a clean state.
|
2025-05-29 16:34:24 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2025-06-11 11:58:54 +02:00
|
|
|
# Filesystem setup
|
2025-05-29 17:05:15 +02:00
|
|
|
fileSystems."/persist".neededForBoot = true;
|
2025-06-11 11:58:54 +02:00
|
|
|
# boot.initrd.postResumeCommands = mkAfter cfg.resetScript;
|
|
|
|
# TODO: Reduce dependency on the root filesystem being ZFS?
|
|
|
|
boot.initrd.systemd.services.impermanence-rollback = {
|
|
|
|
description = "Rollback filesystem to clean state.";
|
|
|
|
wantedBy = [ "initrd.target" ];
|
|
|
|
after = [ "zfs-import.target" ];
|
|
|
|
before = [ "sysroot.mount" ];
|
|
|
|
unitConfig.DefaultDependencies = "no";
|
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
script = cfg.resetScript;
|
|
|
|
};
|
2025-05-29 16:34:24 +02:00
|
|
|
|
2025-05-29 17:05:15 +02:00
|
|
|
# For home-manager persistence
|
|
|
|
programs.fuse.userAllowOther = true;
|
|
|
|
|
2025-06-11 11:58:54 +02:00
|
|
|
# For testing purposes with VM
|
|
|
|
virtualisation.vmVariantWithDisko.virtualisation.fileSystems."/persist".neededForBoot = true;
|
|
|
|
|
2025-05-29 16:34:24 +02:00
|
|
|
environment.persistence."/persist/system" = {
|
|
|
|
enable = true;
|
|
|
|
hideMounts = true;
|
|
|
|
directories = cfg.directories;
|
|
|
|
files = cfg.files;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|