diff --git a/machines/elendel/default.nix b/machines/elendel/default.nix index ab7913d1..cc19c703 100644 --- a/machines/elendel/default.nix +++ b/machines/elendel/default.nix @@ -42,6 +42,7 @@ zfs = { enable = true; rootDataset = "zroot/local/root"; + rootPool = "zroot"; }; }; }; diff --git a/machines/kholinar/default.nix b/machines/kholinar/default.nix index 4589de5a..335843be 100644 --- a/machines/kholinar/default.nix +++ b/machines/kholinar/default.nix @@ -31,6 +31,7 @@ } ]; rootDataset = "rpool/local/root"; + rootPool = "rpool"; }; }; development = { diff --git a/machines/lasting-integrity/default.nix b/machines/lasting-integrity/default.nix index 26d9b7d3..73fb0a19 100644 --- a/machines/lasting-integrity/default.nix +++ b/machines/lasting-integrity/default.nix @@ -68,6 +68,7 @@ } ]; rootDataset = "zroot/local/root"; + rootPool = "zroot"; }; }; games = { diff --git a/machines/marabethia/default.nix b/machines/marabethia/default.nix index 680080bd..8622b6fa 100644 --- a/machines/marabethia/default.nix +++ b/machines/marabethia/default.nix @@ -30,6 +30,7 @@ zfs = { enable = true; rootDataset = "zroot/local/root"; + rootPool = "zroot"; }; }; }; diff --git a/machines/urithiru/default.nix b/machines/urithiru/default.nix index ac4d9820..025b118f 100644 --- a/machines/urithiru/default.nix +++ b/machines/urithiru/default.nix @@ -55,6 +55,7 @@ } ]; rootDataset = "zroot/local/root"; + rootPool = "zroot"; }; }; services = { diff --git a/modules/nixos/base/zfs/default.nix b/modules/nixos/base/zfs/default.nix index 0bb3da90..7b744b96 100644 --- a/modules/nixos/base/zfs/default.nix +++ b/modules/nixos/base/zfs/default.nix @@ -1,4 +1,4 @@ -{ config, lib, ... }: +{ config, lib, pkgs, ... }: { config = lib.mkIf config.chvp.base.zfs.enable { @@ -8,9 +8,21 @@ boot = { supportedFilesystems = [ "zfs" ]; zfs.requestEncryptionCredentials = config.chvp.base.zfs.encrypted; - initrd.postDeviceCommands = lib.mkAfter '' - zfs rollback -r ${config.chvp.base.zfs.rootDataset}@blank - ''; + initrd.systemd = { + enable = true; + services.rollback = { + description = "Rollback root filesystem to a pristine state on boot"; + wantedBy = [ "initrd.target" ]; + after = [ "zfs-import-${config.chvp.base.zfs.rootPool}.service" ]; + before = [ "sysroot.mount" ]; + path = with pkgs; [ zfs ]; + unitConfig.DefaultDependencies = "no"; + serviceConfig.Type = "oneshot"; + script = '' + zfs rollback -r ${config.chvp.base.zfs.rootDataset}@blank && echo " >> >> rollback complete << <<" + ''; + }; + }; }; services = { diff --git a/modules/shared/base/zfs/default.nix b/modules/shared/base/zfs/default.nix index bb77e4d1..bec727e4 100644 --- a/modules/shared/base/zfs/default.nix +++ b/modules/shared/base/zfs/default.nix @@ -45,5 +45,8 @@ rootDataset = lib.mkOption { example = "rpool/local/root"; }; + rootPool = lib.mkOption { + example = "rpool"; + }; }; }