Make rollback datasets configurable.
This commit is contained in:
parent
c542dcdee9
commit
606b952304
@ -32,6 +32,11 @@
|
||||
boot.loader.generic-extlinux-compatible.enable = true;
|
||||
boot.loader.systemd-boot.enable = lib.mkForce false;
|
||||
|
||||
me.rollback.dataset = [
|
||||
"zroot/linux/nix/root@blank"
|
||||
"zroot/linux/nix/home@blank"
|
||||
];
|
||||
|
||||
me.optimizations = {
|
||||
enable = true;
|
||||
arch = "znver4";
|
||||
|
||||
@ -33,6 +33,11 @@
|
||||
boot.loader.generic-extlinux-compatible.enable = true;
|
||||
boot.loader.systemd-boot.enable = lib.mkForce false;
|
||||
|
||||
me.rollback.dataset = [
|
||||
"zroot/linux/nixwork/root@blank"
|
||||
"zroot/linux/nixwork/home@blank"
|
||||
];
|
||||
|
||||
me.optimizations = {
|
||||
enable = true;
|
||||
arch = "znver4";
|
||||
|
||||
@ -30,6 +30,11 @@
|
||||
boot.loader.generic-extlinux-compatible.enable = true;
|
||||
boot.loader.systemd-boot.enable = lib.mkForce false;
|
||||
|
||||
me.rollback.dataset = [
|
||||
"zroot/linux/nix/root@blank"
|
||||
"zroot/linux/nix/home@blank"
|
||||
];
|
||||
|
||||
me.optimizations = {
|
||||
enable = true;
|
||||
arch = "znver4";
|
||||
|
||||
@ -23,6 +23,27 @@
|
||||
example = true;
|
||||
description = "Enable to use secure boot.";
|
||||
};
|
||||
|
||||
rollback.enable = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
example = true;
|
||||
description = "Whether we want to enable rolling back during boot.";
|
||||
};
|
||||
|
||||
rollback.dataset = lib.mkOption {
|
||||
default = { };
|
||||
example = lib.literalExpression ''
|
||||
{
|
||||
"zroot/linux/nix/root@blank" = true;
|
||||
"zroot/linux/nix/home@blank" = lib.mkForce false;
|
||||
}
|
||||
'';
|
||||
type = lib.types.coercedTo (lib.types.listOf lib.types.str) (
|
||||
enabled: lib.listToAttrs (map (fs: lib.nameValuePair fs true) enabled)
|
||||
) (lib.types.attrsOf lib.types.bool);
|
||||
description = "List of ZFS datasets to rollback to during boot.";
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf config.me.boot.enable (
|
||||
@ -51,7 +72,7 @@
|
||||
|
||||
# Check what will be lost with `zfs diff zroot/linux/root@blank`
|
||||
boot.initrd.systemd.enable = lib.mkDefault true;
|
||||
boot.initrd.systemd.services.zfs-rollback = {
|
||||
boot.initrd.systemd.services.zfs-rollback = lib.mkIf config.me.rollback.enable {
|
||||
description = "Rollback ZFS root dataset to blank snapshot";
|
||||
wantedBy = [
|
||||
"initrd.target"
|
||||
@ -64,11 +85,12 @@
|
||||
];
|
||||
unitConfig.DefaultDependencies = "no";
|
||||
serviceConfig.Type = "oneshot";
|
||||
script = ''
|
||||
${config.boot.zfs.package}/sbin/zfs rollback -r zroot/linux/nix/root@blank
|
||||
${config.boot.zfs.package}/sbin/zfs rollback -r zroot/linux/nix/home@blank
|
||||
echo "rollback complete"
|
||||
'';
|
||||
script = lib.concatStringsSep "\n" (
|
||||
(builtins.map (ds: "${config.boot.zfs.package}/sbin/zfs rollback -r '${ds}'") (
|
||||
builtins.attrNames config.me.rollback.dataset
|
||||
))
|
||||
++ [ ''echo "rollback complete"'' ]
|
||||
);
|
||||
};
|
||||
|
||||
# boot.loader.systemd-boot.extraEntries = {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user