nixos/zfs: expose zfs package as readonly attribute

This commit is contained in:
Jörg Thalheim 2021-01-15 13:13:51 +01:00
parent 1b718ca527
commit 648a6c4348
No known key found for this signature in database
GPG key ID: B3F5D81B0C6967C4

View file

@ -19,18 +19,8 @@ let
enableZfs = inInitrd || inSystem;
kernel = config.boot.kernelPackages;
packages = if config.boot.zfs.enableUnstable then {
zfs = kernel.zfsUnstable;
zfsUser = pkgs.zfsUnstable;
} else {
zfs = kernel.zfs;
zfsUser = pkgs.zfs;
};
autosnapPkg = pkgs.zfstools.override {
zfs = packages.zfsUser;
zfs = cfgZfs.package;
};
zfsAutoSnap = "${autosnapPkg}/bin/zfs-auto-snapshot";
@ -111,6 +101,12 @@ in
options = {
boot.zfs = {
package = mkOption {
readOnly = true;
type = types.package;
default = if config.boot.zfs.enableUnstable then pkgs.zfsUnstable else pkgs.zfs;
description = "Configured ZFS userland tools package.";
};
enableUnstable = mkOption {
type = types.bool;
default = false;
@ -370,16 +366,22 @@ in
boot = {
kernelModules = [ "zfs" ];
extraModulePackages = with packages; [ zfs ];
extraModulePackages = [
(if config.boot.zfs.enableUnstable then
config.boot.kernelPackages.zfsUnstable
else
config.boot.kernelPackages.zfs)
];
};
boot.initrd = mkIf inInitrd {
kernelModules = [ "zfs" ] ++ optional (!cfgZfs.enableUnstable) "spl";
extraUtilsCommands =
''
copy_bin_and_libs ${packages.zfsUser}/sbin/zfs
copy_bin_and_libs ${packages.zfsUser}/sbin/zdb
copy_bin_and_libs ${packages.zfsUser}/sbin/zpool
copy_bin_and_libs ${cfgZfs.package}/sbin/zfs
copy_bin_and_libs ${cfgZfs.package}/sbin/zdb
copy_bin_and_libs ${cfgZfs.package}/sbin/zpool
'';
extraUtilsCommandsTest = mkIf inInitrd
''
@ -433,7 +435,7 @@ in
services.zfs.zed.settings = {
ZED_EMAIL_PROG = mkDefault "${pkgs.mailutils}/bin/mail";
PATH = lib.makeBinPath [
packages.zfsUser
cfgZfs.package
pkgs.coreutils
pkgs.curl
pkgs.gawk
@ -461,18 +463,18 @@ in
"vdev_clear-led.sh"
]
)
(file: { source = "${packages.zfsUser}/etc/${file}"; })
(file: { source = "${cfgZfs.package}/etc/${file}"; })
// {
"zfs/zed.d/zed.rc".text = zedConf;
"zfs/zpool.d".source = "${packages.zfsUser}/etc/zfs/zpool.d/";
"zfs/zpool.d".source = "${cfgZfs.package}/etc/zfs/zpool.d/";
};
system.fsPackages = [ packages.zfsUser ]; # XXX: needed? zfs doesn't have (need) a fsck
environment.systemPackages = [ packages.zfsUser ]
system.fsPackages = [ cfgZfs.package ]; # XXX: needed? zfs doesn't have (need) a fsck
environment.systemPackages = [ cfgZfs.package ]
++ optional cfgSnapshots.enable autosnapPkg; # so the user can run the command to see flags
services.udev.packages = [ packages.zfsUser ]; # to hook zvol naming, etc.
systemd.packages = [ packages.zfsUser ];
services.udev.packages = [ cfgZfs.package ]; # to hook zvol naming, etc.
systemd.packages = [ cfgZfs.package ];
systemd.services = let
getPoolFilesystems = pool:
@ -506,8 +508,8 @@ in
environment.ZFS_FORCE = optionalString cfgZfs.forceImportAll "-f";
script = (importLib {
# See comments at importLib definition.
zpoolCmd="${packages.zfsUser}/sbin/zpool";
awkCmd="${pkgs.gawk}/bin/awk";
zpoolCmd = "${cfgZfs.package}/sbin/zpool";
zfsCmd = "${cfgZfs.package}/sbin/zfs";
inherit cfgZfs;
}) + ''
poolImported "${pool}" && exit
@ -561,7 +563,7 @@ in
RemainAfterExit = true;
};
script = ''
${packages.zfsUser}/sbin/zfs set nixos:shutdown-time="$(date)" "${pool}"
${cfgZfs.package}/sbin/zfs set nixos:shutdown-time="$(date)" "${pool}"
'';
};
createZfsService = serv:
@ -633,11 +635,11 @@ in
Type = "oneshot";
};
script = ''
${packages.zfsUser}/bin/zpool scrub ${
${cfgZfs.package}/bin/zpool scrub ${
if cfgScrub.pools != [] then
(concatStringsSep " " cfgScrub.pools)
else
"$(${packages.zfsUser}/bin/zpool list -H -o name)"
"$(${cfgZfs.package}/bin/zpool list -H -o name)"
}
'';
};
@ -656,7 +658,7 @@ in
systemd.services.zpool-trim = {
description = "ZFS pools trim";
after = [ "zfs-import.target" ];
path = [ packages.zfsUser ];
path = [ cfgZfs.package ];
startAt = cfgTrim.interval;
# By default we ignore errors returned by the trim command, in case:
# - HDDs are mixed with SSDs