Add the hostid option. Refactor code a bit better for initrd(untested) and system operation.
This commit is contained in:
parent
d2789791ee
commit
b42d52eeb0
@ -1,41 +1,68 @@
|
|||||||
{ config, pkgs, ... }:
|
{ config, pkgs, ... }:
|
||||||
|
#
|
||||||
|
# todo:
|
||||||
|
# - crontab for scrubs, etc
|
||||||
|
# - zfs tunables
|
||||||
|
# - /etc/zfs/zpool.cache handling
|
||||||
|
|
||||||
|
|
||||||
with pkgs.lib;
|
with pkgs.lib;
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
||||||
|
cfgSpl = config.environment.spl;
|
||||||
inInitrd = any (fs: fs == "zfs") config.boot.initrd.supportedFilesystems;
|
inInitrd = any (fs: fs == "zfs") config.boot.initrd.supportedFilesystems;
|
||||||
|
inSystem = any (fs: fs == "zfs") config.boot.supportedFilesystems;
|
||||||
kernel = config.boot.kernelPackages;
|
kernel = config.boot.kernelPackages;
|
||||||
|
|
||||||
in
|
in
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
|
###### interface
|
||||||
|
|
||||||
|
options = {
|
||||||
|
environment.spl.hostid = mkOption {
|
||||||
|
default = "";
|
||||||
|
example = "0xdeadbeef";
|
||||||
|
description = ''
|
||||||
|
ZFS uses a system's hostid to determine if a storage pool (zpool) is
|
||||||
|
native to this system, and should thus be imported automatically.
|
||||||
|
Unfortunately, this hostid can change under linux from boot to boot (by
|
||||||
|
changing network adapaters, for instance). Specify a unique 32 bit hostid in
|
||||||
|
hex here for zfs to prevent getting a random hostid between boots and having to
|
||||||
|
manually import pools.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
###### implementation
|
###### implementation
|
||||||
|
|
||||||
config = mkIf (any (fs: fs == "zfs") config.boot.supportedFilesystems) {
|
config = mkIf ( inInitrd || inSystem ) {
|
||||||
|
|
||||||
boot.kernelModules = [ "spl" "zfs" ] ;
|
boot = {
|
||||||
boot.extraModulePackages = [ kernel.zfs kernel.spl ];
|
kernelModules = [ "spl" "zfs" ] ;
|
||||||
|
extraModulePackages = [ kernel.zfs kernel.spl ];
|
||||||
|
extraModprobeConfig = mkIf (cfgSpl.hostid != "") "options spl spl_hostid=${cfgSpl.hostid}";
|
||||||
|
};
|
||||||
|
|
||||||
boot.initrd.kernelModules = mkIf inInitrd [ "spl" "zfs" ] ;
|
boot.initrd = mkIf inInitrd {
|
||||||
|
kernelModules = [ "spl" "zfs" ] ;
|
||||||
boot.initrd.extraUtilsCommands = mkIf inInitrd
|
extraUtilsCommands =
|
||||||
''
|
''
|
||||||
cp -v ${kernel.zfs}/sbin/zfs $out/sbin
|
cp -v ${kernel.zfs}/sbin/zfs $out/sbin
|
||||||
cp -v ${kernel.zfs}/sbin/zdb $out/sbin
|
cp -v ${kernel.zfs}/sbin/zdb $out/sbin
|
||||||
cp -v ${kernel.zfs}/sbin/zpool $out/sbin
|
cp -v ${kernel.zfs}/sbin/zpool $out/sbin
|
||||||
'';
|
'';
|
||||||
|
postDeviceCommands =
|
||||||
boot.initrd.postDeviceCommands = mkIf inInitrd
|
''
|
||||||
''
|
zpool import -f -a -d /dev
|
||||||
zpool import -f -a -d /dev
|
zfs mount -a
|
||||||
zfs mount -a
|
'';
|
||||||
'';
|
};
|
||||||
|
|
||||||
system.fsPackages = [ kernel.zfs ];
|
|
||||||
|
|
||||||
|
system.fsPackages = [ kernel.zfs ]; # XXX: needed? zfs doesn't have a fsck
|
||||||
environment.systemPackages = [ kernel.zfs ];
|
environment.systemPackages = [ kernel.zfs ];
|
||||||
|
services.udev.packages = [ kernel.zfs ]; # to hook zvol naming, etc.
|
||||||
services.udev.packages = [ kernel.zfs ];
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user