nixpkgs/nixos/modules/tasks/filesystems/zfs.nix

95 lines
2.6 KiB
Nix
Raw Normal View History

2012-12-04 19:17:54 +01:00
{ config, pkgs, ... }:
#
# todo:
# - crontab for scrubs, etc
# - zfs tunables
# - /etc/zfs/zpool.cache handling
2012-12-04 19:17:54 +01:00
with pkgs.lib;
let
2012-12-07 00:12:10 +01:00
cfgSpl = config.boot.spl;
2012-12-04 19:17:54 +01:00
inInitrd = any (fs: fs == "zfs") config.boot.initrd.supportedFilesystems;
inSystem = any (fs: fs == "zfs") config.boot.supportedFilesystems;
2012-12-04 19:17:54 +01:00
kernel = config.boot.kernelPackages;
in
{
###### interface
options = {
2012-12-07 00:12:10 +01:00
boot.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 adapters, 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.
'';
};
};
2012-12-04 19:17:54 +01:00
###### implementation
2012-12-04 19:17:54 +01:00
config = mkIf ( inInitrd || inSystem ) {
2012-12-04 19:17:54 +01:00
boot = {
kernelModules = [ "spl" "zfs" ] ;
extraModulePackages = [ kernel.zfs kernel.spl ];
2013-03-11 10:02:10 +01:00
extraModprobeConfig = mkIf (cfgSpl.hostid != "") ''
options spl spl_hostid=${cfgSpl.hostid}
'';
};
2012-12-04 19:17:54 +01:00
boot.initrd = mkIf inInitrd {
kernelModules = [ "spl" "zfs" ] ;
extraUtilsCommands =
''
cp -v ${kernel.zfs}/sbin/zfs $out/bin
cp -v ${kernel.zfs}/sbin/zdb $out/bin
cp -v ${kernel.zfs}/sbin/zpool $out/bin
'';
postDeviceCommands =
''
zpool import -f -a -d /dev
zfs mount -a
'';
};
2012-12-04 19:17:54 +01:00
systemd.services."zpool-import" = {
description = "Import zpools";
after = [ "systemd-udev-settle.service" ];
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
restartIfChanged = false;
ExecStart = "${kernel.zfs}/sbin/zpool import -f -a -d /dev";
};
};
systemd.services."zfs-mount" = {
description = "Mount zfs volumes";
after = [ "zpool-import.service" ];
wantedBy = [ "local-fs.target" ];
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
restartIfChanged = false;
ExecStart = "${kernel.zfs}/sbin/zfs mount -a";
ExecStop = "${kernel.zfs}/sbin/zfs umount -a";
};
};
system.fsPackages = [ kernel.zfs ]; # XXX: needed? zfs doesn't have (need) a fsck
2012-12-04 19:17:54 +01:00
environment.systemPackages = [ kernel.zfs ];
services.udev.packages = [ kernel.zfs ]; # to hook zvol naming, etc.
2012-12-04 19:17:54 +01:00
};
}