Files
sydnix/modules/nixos/impermanence.nix
Madeleine Sydney 0350752a50 Use impermanence
2024-12-12 13:54:46 -07:00

67 lines
1.4 KiB
Nix

# Requires boot.initrd.enable = true and boot.initrd.systemd.enable = true!
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.sydnix.impermanence;
in {
options = {
sydnix.impermanence = {
enable = mkOption {
description = "Enable Impermanence";
type = types.bool;
default = false;
};
directories = mkOption {
description = "";
type = with types; listOf anything;
default = [];
};
files = mkOption {
description = "";
type = with types; listOf anything;
default = [];
};
};
};
config = mkIf cfg.enable {
boot.initrd.systemd.initrdBin = with pkgs; [
zfs
];
boot.initrd.systemd.services.erase-darlings = {
description = "Rollback filesystem to a blank state on boot";
wantedBy = [
"initrd.target"
];
after = [
# "zfs-import.service"
"zfs-import-rpool.service"
];
before = [
"sysroot.mount"
];
path = [ pkgs.zfs ];
unitConfig.DefaultDependencies = "no";
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
};
script = /* bash */ ''
zfs rollback -r rpool/local/root@blank \
&& echo ">> >> rollback complete << <<"
'';
};
environment.persistence."/persist" = {
directories = cfg.directories;
files = cfg.files;
};
};
}