|
| 1 | +{ |
| 2 | + stdenv, |
| 3 | + lib, |
| 4 | + pkgs, |
| 5 | + kernel, |
| 6 | + kernelModuleMakeFlags ? [ ], |
| 7 | + autoreconfHook, |
| 8 | + attr, |
| 9 | + coreutils, |
| 10 | + gawk, |
| 11 | + gnused, |
| 12 | + gnugrep, |
| 13 | + ksh, |
| 14 | + libtirpc, |
| 15 | + libuuid, |
| 16 | + nukeReferences, |
| 17 | + openssl, |
| 18 | + pam, |
| 19 | + pkg-config, |
| 20 | + python3, |
| 21 | + systemd, |
| 22 | + udevCheckHook, |
| 23 | + zlib, |
| 24 | +}: |
| 25 | + |
| 26 | +stdenv.mkDerivation { |
| 27 | + pname = "zfs"; |
| 28 | + version = "2.3.4-${kernel.version}"; # Specify the version of ZFS you want |
| 29 | + |
| 30 | + src = ./..; |
| 31 | + |
| 32 | + preConfigure = '' |
| 33 | + # The kernel module builds some tests during the configurePhase, this envvar controls their parallelism |
| 34 | + export TEST_JOBS=$NIX_BUILD_CORES |
| 35 | + if [ -z "$enableParallelBuilding" ]; then |
| 36 | + export TEST_JOBS=1 |
| 37 | + fi |
| 38 | + ''; |
| 39 | + |
| 40 | + postPatch = '' |
| 41 | + patchShebangs scripts tests |
| 42 | +
|
| 43 | + substituteInPlace ./config/user-systemd.m4 --replace-fail "/usr/lib/modules-load.d" "$out/etc/modules-load.d" |
| 44 | + substituteInPlace ./config/zfs-build.m4 --replace-fail "\$sysconfdir/init.d" "$out/etc/init.d" \ |
| 45 | + --replace-fail "/etc/default" "$out/etc/default" |
| 46 | + substituteInPlace ./contrib/initramfs/Makefile.am \ |
| 47 | + --replace-fail "/usr/share/initramfs-tools" "$out/usr/share/initramfs-tools" |
| 48 | +
|
| 49 | + substituteInPlace ./udev/vdev_id \ |
| 50 | + --replace-fail "PATH=/bin:/sbin:/usr/bin:/usr/sbin" \ |
| 51 | + "PATH=${ |
| 52 | + lib.makeBinPath [ |
| 53 | + coreutils |
| 54 | + gawk |
| 55 | + gnused |
| 56 | + gnugrep |
| 57 | + systemd |
| 58 | + ] |
| 59 | + }" |
| 60 | +
|
| 61 | + substituteInPlace ./config/zfs-build.m4 \ |
| 62 | + --replace-fail "bashcompletiondir=/etc/bash_completion.d" \ |
| 63 | + "bashcompletiondir=$out/share/bash-completion/completions" \ |
| 64 | + --replace-fail 'DEBUG_CFLAGS="-Werror"' ' ' |
| 65 | +
|
| 66 | + # Tests |
| 67 | + substituteInPlace ./scripts/zfs-tests.sh \ |
| 68 | + --replace-fail '"$STF_PATH/ksh"' "${lib.getExe pkgs.ksh}" |
| 69 | + substituteInPlace ./tests/test-runner/bin/test-runner.py.in \ |
| 70 | + --replace-fail "/usr/share/zfs/" "$out/share/zfs/" \ |
| 71 | + --replace-fail "KILL = 'kill'" "KILL = '${lib.getExe' pkgs.coreutils "kill"}'" \ |
| 72 | + --replace-fail "SUDO = 'sudo'" "SUDO = '/run/wrappers/bin/sudo'" \ |
| 73 | + --replace-fail "TRUE = 'true'" "TRUE = '${lib.getExe' pkgs.coreutils "true"}'" |
| 74 | + ''; |
| 75 | + |
| 76 | + buildInputs = [ |
| 77 | + attr |
| 78 | + libtirpc |
| 79 | + libuuid |
| 80 | + openssl |
| 81 | + pam |
| 82 | + python3 |
| 83 | + systemd |
| 84 | + zlib |
| 85 | + ]; |
| 86 | + |
| 87 | + nativeBuildInputs = [ |
| 88 | + autoreconfHook |
| 89 | + ksh |
| 90 | + nukeReferences |
| 91 | + pkg-config |
| 92 | + udevCheckHook |
| 93 | + kernel.moduleBuildDependencies |
| 94 | + ]; |
| 95 | + |
| 96 | + enableParallelBuilding = true; |
| 97 | + |
| 98 | + configureFlags = [ |
| 99 | + "--with-linux=${kernel.dev}/lib/modules/${kernel.modDirVersion}/source" |
| 100 | + "--with-linux-obj=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build" |
| 101 | + "--with-dracutdir=$(out)/lib/dracut" |
| 102 | + "--with-udevdir=$(out)/lib/udev" |
| 103 | + "--with-systemdunitdir=$(out)/etc/systemd/system" |
| 104 | + "--with-systemdpresetdir=$(out)/etc/systemd/system-preset" |
| 105 | + "--with-systemdgeneratordir=$(out)/lib/systemd/system-generator" |
| 106 | + "--with-mounthelperdir=$(out)/bin" |
| 107 | + "--libexecdir=$(out)/libexec" |
| 108 | + "--sysconfdir=/etc" |
| 109 | + "--localstatedir=/var" |
| 110 | + "--enable-systemd" |
| 111 | + "--enable-pam" |
| 112 | + |
| 113 | + # Debug |
| 114 | + "--enable-debug" |
| 115 | + "--enable-debuginfo" |
| 116 | + "--enable-asan" |
| 117 | + "--enable-ubsan" |
| 118 | + "--enable-debug-kmem" |
| 119 | + "--enable-debug-kmem-tracking" |
| 120 | + ] |
| 121 | + ++ map (f: "KERNEL_${f}") kernelModuleMakeFlags; |
| 122 | + |
| 123 | + doInstallCheck = true; |
| 124 | + |
| 125 | + installFlags = [ |
| 126 | + "sysconfdir=\${out}/etc" |
| 127 | + "DEFAULT_INITCONF_DIR=\${out}/default" |
| 128 | + "INSTALL_MOD_PATH=\${out}" |
| 129 | + ]; |
| 130 | + |
| 131 | + meta = with lib; { |
| 132 | + description = "OpenZFS on Linux"; |
| 133 | + license = licenses.cddl; |
| 134 | + platforms = platforms.linux; |
| 135 | + }; |
| 136 | +} |
0 commit comments