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.generic-extlinux-compatible.enable = true;
|
||||||
boot.loader.systemd-boot.enable = lib.mkForce false;
|
boot.loader.systemd-boot.enable = lib.mkForce false;
|
||||||
|
|
||||||
|
me.rollback.dataset = [
|
||||||
|
"zroot/linux/nix/root@blank"
|
||||||
|
"zroot/linux/nix/home@blank"
|
||||||
|
];
|
||||||
|
|
||||||
me.optimizations = {
|
me.optimizations = {
|
||||||
enable = true;
|
enable = true;
|
||||||
arch = "znver4";
|
arch = "znver4";
|
||||||
|
|||||||
@ -33,6 +33,11 @@
|
|||||||
boot.loader.generic-extlinux-compatible.enable = true;
|
boot.loader.generic-extlinux-compatible.enable = true;
|
||||||
boot.loader.systemd-boot.enable = lib.mkForce false;
|
boot.loader.systemd-boot.enable = lib.mkForce false;
|
||||||
|
|
||||||
|
me.rollback.dataset = [
|
||||||
|
"zroot/linux/nixwork/root@blank"
|
||||||
|
"zroot/linux/nixwork/home@blank"
|
||||||
|
];
|
||||||
|
|
||||||
me.optimizations = {
|
me.optimizations = {
|
||||||
enable = true;
|
enable = true;
|
||||||
arch = "znver4";
|
arch = "znver4";
|
||||||
|
|||||||
@ -30,6 +30,11 @@
|
|||||||
boot.loader.generic-extlinux-compatible.enable = true;
|
boot.loader.generic-extlinux-compatible.enable = true;
|
||||||
boot.loader.systemd-boot.enable = lib.mkForce false;
|
boot.loader.systemd-boot.enable = lib.mkForce false;
|
||||||
|
|
||||||
|
me.rollback.dataset = [
|
||||||
|
"zroot/linux/nix/root@blank"
|
||||||
|
"zroot/linux/nix/home@blank"
|
||||||
|
];
|
||||||
|
|
||||||
me.optimizations = {
|
me.optimizations = {
|
||||||
enable = true;
|
enable = true;
|
||||||
arch = "znver4";
|
arch = "znver4";
|
||||||
|
|||||||
@ -23,6 +23,27 @@
|
|||||||
example = true;
|
example = true;
|
||||||
description = "Enable to use secure boot.";
|
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 (
|
config = lib.mkIf config.me.boot.enable (
|
||||||
@ -51,7 +72,7 @@
|
|||||||
|
|
||||||
# Check what will be lost with `zfs diff zroot/linux/root@blank`
|
# Check what will be lost with `zfs diff zroot/linux/root@blank`
|
||||||
boot.initrd.systemd.enable = lib.mkDefault true;
|
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";
|
description = "Rollback ZFS root dataset to blank snapshot";
|
||||||
wantedBy = [
|
wantedBy = [
|
||||||
"initrd.target"
|
"initrd.target"
|
||||||
@ -64,11 +85,12 @@
|
|||||||
];
|
];
|
||||||
unitConfig.DefaultDependencies = "no";
|
unitConfig.DefaultDependencies = "no";
|
||||||
serviceConfig.Type = "oneshot";
|
serviceConfig.Type = "oneshot";
|
||||||
script = ''
|
script = lib.concatStringsSep "\n" (
|
||||||
${config.boot.zfs.package}/sbin/zfs rollback -r zroot/linux/nix/root@blank
|
(builtins.map (ds: "${config.boot.zfs.package}/sbin/zfs rollback -r '${ds}'") (
|
||||||
${config.boot.zfs.package}/sbin/zfs rollback -r zroot/linux/nix/home@blank
|
builtins.attrNames config.me.rollback.dataset
|
||||||
echo "rollback complete"
|
))
|
||||||
'';
|
++ [ ''echo "rollback complete"'' ]
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
# boot.loader.systemd-boot.extraEntries = {
|
# boot.loader.systemd-boot.extraEntries = {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user