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 = {
enable = true;
rootDataset = "zroot/local/root";
rootPool = "zroot";
};
};
};

View file

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

View file

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

View file

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

View file

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

View file

@ -1,4 +1,4 @@
{ config, lib, ... }:
{ config, lib, pkgs, ... }:
{
config = lib.mkIf config.chvp.base.zfs.enable {
@ -8,10 +8,22 @@
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 = {
znapzend = {

View file

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