2012-12-04 18:17:54 +00:00
|
|
|
{ config, pkgs, ... }:
|
2012-12-04 19:57:59 +00:00
|
|
|
#
|
|
|
|
# todo:
|
|
|
|
# - crontab for scrubs, etc
|
|
|
|
# - zfs tunables
|
|
|
|
# - /etc/zfs/zpool.cache handling
|
|
|
|
|
2012-12-04 18:17:54 +00:00
|
|
|
|
|
|
|
with pkgs.lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
2012-12-06 23:12:10 +00:00
|
|
|
cfgSpl = config.boot.spl;
|
2012-12-04 18:17:54 +00:00
|
|
|
inInitrd = any (fs: fs == "zfs") config.boot.initrd.supportedFilesystems;
|
2012-12-04 19:57:59 +00:00
|
|
|
inSystem = any (fs: fs == "zfs") config.boot.supportedFilesystems;
|
2012-12-04 18:17:54 +00:00
|
|
|
kernel = config.boot.kernelPackages;
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
2012-12-04 19:57:59 +00:00
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
2012-12-06 23:12:10 +00:00
|
|
|
boot.spl.hostid = mkOption {
|
2012-12-04 19:57:59 +00:00
|
|
|
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
|
2013-08-10 21:07:13 +00:00
|
|
|
changing network adapters, for instance). Specify a unique 32 bit hostid in
|
2012-12-04 19:57:59 +00:00
|
|
|
hex here for zfs to prevent getting a random hostid between boots and having to
|
|
|
|
manually import pools.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2012-12-04 18:17:54 +00:00
|
|
|
|
2012-12-04 19:57:59 +00:00
|
|
|
###### implementation
|
2012-12-04 18:17:54 +00:00
|
|
|
|
2012-12-04 19:57:59 +00:00
|
|
|
config = mkIf ( inInitrd || inSystem ) {
|
2012-12-04 18:17:54 +00:00
|
|
|
|
2012-12-04 19:57:59 +00:00
|
|
|
boot = {
|
|
|
|
kernelModules = [ "spl" "zfs" ] ;
|
|
|
|
extraModulePackages = [ kernel.zfs kernel.spl ];
|
2013-03-11 09:02:10 +00:00
|
|
|
extraModprobeConfig = mkIf (cfgSpl.hostid != "") ''
|
|
|
|
options spl spl_hostid=${cfgSpl.hostid}
|
|
|
|
'';
|
2012-12-04 19:57:59 +00:00
|
|
|
};
|
2012-12-04 18:17:54 +00:00
|
|
|
|
2012-12-04 19:57:59 +00:00
|
|
|
boot.initrd = mkIf inInitrd {
|
|
|
|
kernelModules = [ "spl" "zfs" ] ;
|
|
|
|
extraUtilsCommands =
|
|
|
|
''
|
2013-08-12 22:53:57 +00:00
|
|
|
cp -v ${kernel.zfs}/sbin/zfs $out/bin
|
|
|
|
cp -v ${kernel.zfs}/sbin/zdb $out/bin
|
|
|
|
cp -v ${kernel.zfs}/sbin/zpool $out/bin
|
2013-10-27 09:17:23 +00:00
|
|
|
cp -pdv ${kernel.zfs}/lib/lib*.so* $out/lib
|
|
|
|
cp -pdv ${pkgs.zlib}/lib/lib*.so* $out/lib
|
2012-12-04 19:57:59 +00:00
|
|
|
'';
|
|
|
|
postDeviceCommands =
|
|
|
|
''
|
2014-01-16 20:37:44 +00:00
|
|
|
zpool import -f -a
|
2012-12-04 19:57:59 +00:00
|
|
|
'';
|
|
|
|
};
|
2012-12-04 18:17:54 +00:00
|
|
|
|
2013-05-05 13:31:10 +00:00
|
|
|
systemd.services."zpool-import" = {
|
|
|
|
description = "Import zpools";
|
|
|
|
after = [ "systemd-udev-settle.service" ];
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
RemainAfterExit = true;
|
2013-06-07 16:34:46 +00:00
|
|
|
restartIfChanged = false;
|
2014-01-16 20:37:44 +00:00
|
|
|
ExecStart = "${kernel.zfs}/sbin/zpool import -f -a";
|
2013-05-05 13:31:10 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services."zfs-mount" = {
|
2013-11-09 19:06:01 +00:00
|
|
|
description = "Mount ZFS Volumes";
|
2013-05-05 13:31:10 +00:00
|
|
|
after = [ "zpool-import.service" ];
|
|
|
|
wantedBy = [ "local-fs.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
RemainAfterExit = true;
|
2013-06-10 05:01:48 +00:00
|
|
|
restartIfChanged = false;
|
2013-05-05 13:31:10 +00:00
|
|
|
ExecStart = "${kernel.zfs}/sbin/zfs mount -a";
|
|
|
|
ExecStop = "${kernel.zfs}/sbin/zfs umount -a";
|
|
|
|
};
|
|
|
|
};
|
2013-06-07 16:34:46 +00:00
|
|
|
|
|
|
|
system.fsPackages = [ kernel.zfs ]; # XXX: needed? zfs doesn't have (need) a fsck
|
2012-12-04 18:17:54 +00:00
|
|
|
environment.systemPackages = [ kernel.zfs ];
|
2012-12-04 19:57:59 +00:00
|
|
|
services.udev.packages = [ kernel.zfs ]; # to hook zvol naming, etc.
|
2012-12-04 18:17:54 +00:00
|
|
|
};
|
|
|
|
}
|