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

@ -42,6 +42,7 @@
zfs = { zfs = {
enable = true; enable = true;
rootDataset = "zroot/local/root"; rootDataset = "zroot/local/root";
rootPool = "zroot";
}; };
}; };
}; };

View file

@ -31,6 +31,7 @@
} }
]; ];
rootDataset = "rpool/local/root"; rootDataset = "rpool/local/root";
rootPool = "rpool";
}; };
}; };
development = { development = {

View file

@ -68,6 +68,7 @@
} }
]; ];
rootDataset = "zroot/local/root"; rootDataset = "zroot/local/root";
rootPool = "zroot";
}; };
}; };
games = { games = {

View file

@ -30,6 +30,7 @@
zfs = { zfs = {
enable = true; enable = true;
rootDataset = "zroot/local/root"; rootDataset = "zroot/local/root";
rootPool = "zroot";
}; };
}; };
}; };

View file

@ -55,6 +55,7 @@
} }
]; ];
rootDataset = "zroot/local/root"; rootDataset = "zroot/local/root";
rootPool = "zroot";
}; };
}; };
services = { services = {

View file

@ -1,4 +1,4 @@
{ config, lib, ... }: { config, lib, pkgs, ... }:
{ {
config = lib.mkIf config.chvp.base.zfs.enable { config = lib.mkIf config.chvp.base.zfs.enable {
@ -8,9 +8,21 @@
boot = { boot = {
supportedFilesystems = [ "zfs" ]; supportedFilesystems = [ "zfs" ];
zfs.requestEncryptionCredentials = config.chvp.base.zfs.encrypted; zfs.requestEncryptionCredentials = config.chvp.base.zfs.encrypted;
initrd.postDeviceCommands = lib.mkAfter '' initrd.systemd = {
zfs rollback -r ${config.chvp.base.zfs.rootDataset}@blank 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 = { services = {

View file

@ -45,5 +45,8 @@
rootDataset = lib.mkOption { rootDataset = lib.mkOption {
example = "rpool/local/root"; example = "rpool/local/root";
}; };
rootPool = lib.mkOption {
example = "rpool";
};
}; };
} }