2020-06-07 14:03:12 +00:00
|
|
|
# SPDX-FileCopyrightText: 2020 Luke Granger-Brown <depot@lukegb.com>
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2023-11-19 20:12:35 +00:00
|
|
|
{ lib, pkgs, config, ... }:
|
2020-05-08 22:26:21 +00:00
|
|
|
let
|
2022-01-23 23:38:40 +00:00
|
|
|
inherit (lib) mkOption types mkAfter mkIf mkDefault;
|
2020-05-08 22:26:21 +00:00
|
|
|
robCfg = config.services.zfs.rollbackOnBoot;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.services.zfs.rollbackOnBoot = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
};
|
|
|
|
snapshot = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "zpool/local/root@blank";
|
|
|
|
};
|
2020-06-06 12:12:39 +00:00
|
|
|
keepPaths = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ ];
|
|
|
|
};
|
2020-05-08 22:26:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
|
|
|
boot.supportedFilesystems = [ "zfs" ];
|
2023-01-18 21:43:48 +00:00
|
|
|
boot.zfs.devNodes = lib.mkDefault "/dev/disk/by-partuuid";
|
2020-05-08 22:26:21 +00:00
|
|
|
services.zfs.autoScrub.enable = true;
|
|
|
|
services.zfs.autoSnapshot = {
|
|
|
|
enable = true;
|
|
|
|
monthly = 1;
|
|
|
|
};
|
2022-01-23 23:38:40 +00:00
|
|
|
systemd.tmpfiles.rules = mkAfter (builtins.map (x: "L ${x} - - - - /persist{x}") robCfg.keepPaths);
|
2020-05-08 22:26:21 +00:00
|
|
|
|
2023-11-19 20:12:35 +00:00
|
|
|
boot.initrd.systemd.services.zfs-rollback = {
|
|
|
|
wantedBy = [ "initrd.target" ];
|
|
|
|
path = [ pkgs.zfs ];
|
|
|
|
script = ''
|
2020-05-08 22:26:21 +00:00
|
|
|
zfs rollback -r ${robCfg.snapshot}
|
2023-11-19 20:12:35 +00:00
|
|
|
'';
|
|
|
|
after = [ "zfs-import.target" ];
|
|
|
|
};
|
2022-01-23 23:38:40 +00:00
|
|
|
|
|
|
|
my.vault.bindMountStateTo = mkIf robCfg.enable (mkDefault "/persist/var/lib/vault-agent");
|
2020-05-08 22:26:21 +00:00
|
|
|
};
|
2022-01-23 23:38:40 +00:00
|
|
|
}
|