refactor(nixos): derive ZFS host IDs
This commit is contained in:
@@ -60,7 +60,6 @@
|
|||||||
|
|
||||||
modules.zfs = {
|
modules.zfs = {
|
||||||
enable = true;
|
enable = true;
|
||||||
hostId = "2346edbd";
|
|
||||||
pools.pikachu = { };
|
pools.pikachu = { };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -11,18 +11,6 @@ in
|
|||||||
options.modules.zfs = {
|
options.modules.zfs = {
|
||||||
enable = lib.mkEnableOption "importing durable ZFS pools that hold service state";
|
enable = lib.mkEnableOption "importing durable ZFS pools that hold service state";
|
||||||
|
|
||||||
hostId = lib.mkOption {
|
|
||||||
type = lib.types.strMatching "[0-9a-f]{8}";
|
|
||||||
example = "deadbeef";
|
|
||||||
description = ''
|
|
||||||
This host's 8-hex-digit ZFS host id, written to `networking.hostId`. ZFS
|
|
||||||
stamps an imported pool with the importing host's id, so a pool still
|
|
||||||
held by another machine is refused rather than silently dual-mounted. It
|
|
||||||
must be fixed for the machine and distinct across machines that can reach
|
|
||||||
the same pool.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
pools = lib.mkOption {
|
pools = lib.mkOption {
|
||||||
type = lib.types.attrsOf (lib.types.attrsOf lib.types.path);
|
type = lib.types.attrsOf (lib.types.attrsOf lib.types.path);
|
||||||
default = { };
|
default = { };
|
||||||
@@ -49,8 +37,10 @@ in
|
|||||||
# The ZFS stack in the kernel and boot, needed even where the root filesystem is another kind.
|
# The ZFS stack in the kernel and boot, needed even where the root filesystem is another kind.
|
||||||
boot.supportedFilesystems = [ "zfs" ];
|
boot.supportedFilesystems = [ "zfs" ];
|
||||||
|
|
||||||
# ZFS refuses to import a pool without a host id to stamp its ownership onto.
|
# Derive a stable 32-bit host ID from the configured hostname.
|
||||||
networking.hostId = cfg.hostId;
|
networking.hostId = builtins.substring 0 8 (
|
||||||
|
builtins.hashString "sha256" config.networking.hostName
|
||||||
|
);
|
||||||
|
|
||||||
# The declared pools are imported at boot, distinct from any pool backing the root filesystem.
|
# The declared pools are imported at boot, distinct from any pool backing the root filesystem.
|
||||||
boot.zfs.extraPools = lib.attrNames cfg.pools;
|
boot.zfs.extraPools = lib.attrNames cfg.pools;
|
||||||
|
|||||||
Reference in New Issue
Block a user