# 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; }; }; }