Fix restoring snapshot on boot

This commit is contained in:
Charlotte Van Petegem 2024-11-10 15:19:48 +01:00
parent 9a25143a9b
commit 0544defe93
No known key found for this signature in database
GPG key ID: 019E764B7184435A
7 changed files with 24 additions and 4 deletions

View file

@ -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 = {