1{ stdenv, fetchurl, fetchpatch, lib, pkg-config, util-linux, libcap, libtirpc, libevent
2, sqlite, libkrb5, kmod, libuuid, keyutils, lvm2, systemd, coreutils, tcp_wrappers
3, python3, buildPackages, nixosTests, rpcsvc-proto, openldap
4, enablePython ? true, enableLdap ? true
5}:
6
7let
8 statdPath = lib.makeBinPath [ systemd util-linux coreutils ];
9in
10
11stdenv.mkDerivation rec {
12 pname = "nfs-utils";
13 version = "2.6.4";
14
15 src = fetchurl {
16 url = "mirror://kernel/linux/utils/nfs-utils/${version}/${pname}-${version}.tar.xz";
17 hash = "sha256-AbOw+5x9C7q/URTHNlQgMHSMeI7C/Zc0dEIB6bChEZ0=";
18 };
19
20 # libnfsidmap is built together with nfs-utils from the same source,
21 # put it in the "lib" output, and the headers in "dev"
22 outputs = [ "out" "dev" "lib" "man" ];
23
24 nativeBuildInputs = [ pkg-config buildPackages.stdenv.cc rpcsvc-proto ];
25
26 buildInputs = [
27 libtirpc libcap libevent sqlite lvm2
28 libuuid keyutils libkrb5 tcp_wrappers
29 ] ++ lib.optional enablePython python3
30 ++ lib.optional enableLdap openldap;
31
32 enableParallelBuilding = true;
33
34 preConfigure =
35 ''
36 substituteInPlace configure \
37 --replace '$dir/include/gssapi' ${lib.getDev libkrb5}/include/gssapi \
38 --replace '$dir/bin/krb5-config' ${lib.getDev libkrb5}/bin/krb5-config
39 '';
40
41 configureFlags =
42 [ "--enable-gss"
43 "--enable-svcgss"
44 "--with-statedir=/var/lib/nfs"
45 "--with-krb5=${lib.getLib libkrb5}"
46 "--with-systemd=${placeholder "out"}/etc/systemd/system"
47 "--enable-libmount-mount"
48 "--with-pluginpath=${placeholder "lib"}/lib/libnfsidmap" # this installs libnfsidmap
49 "--with-rpcgen=${buildPackages.rpcsvc-proto}/bin/rpcgen"
50 "--with-modprobedir=${placeholder "out"}/etc/modprobe.d"
51 ] ++ lib.optional enableLdap "--with-ldap";
52
53 patches = lib.optionals stdenv.hostPlatform.isMusl [
54 # http://openwall.com/lists/musl/2015/08/18/10
55 (fetchpatch {
56 url = "https://raw.githubusercontent.com/alpinelinux/aports/cb880042d48d77af412d4688f24b8310ae44f55f/main/nfs-utils/musl-getservbyport.patch";
57 sha256 = "1fqws9dz8n1d9a418c54r11y3w330qgy2652dpwcy96cm44sqyhf";
58 })
59 ];
60
61 postPatch =
62 ''
63 patchShebangs tests
64 sed -i "s,/usr/sbin,$out/bin,g" utils/statd/statd.c
65 sed -i "s,^PATH=.*,PATH=$out/bin:${statdPath}," utils/statd/start-statd
66
67 configureFlags="--with-start-statd=$out/bin/start-statd $configureFlags"
68
69 substituteInPlace systemd/nfs-utils.service \
70 --replace "/bin/true" "${coreutils}/bin/true"
71
72 substituteInPlace tools/nfsrahead/Makefile.in systemd/Makefile.in \
73 --replace "/usr/lib/udev/rules.d/" "$out/lib/udev/rules.d/"
74
75 substituteInPlace utils/mount/Makefile.in \
76 --replace "chmod 4511" "chmod 0511"
77
78 sed '1i#include <stdint.h>' -i support/nsm/rpc.c
79 '';
80
81 makeFlags = [
82 "sbindir=$(out)/bin"
83 "generator_dir=$(out)/etc/systemd/system-generators"
84 ];
85
86 installFlags = [
87 "statedir=$(TMPDIR)"
88 "statdpath=$(TMPDIR)"
89 ];
90
91 stripDebugList = [ "lib" "libexec" "bin" "etc/systemd/system-generators" ];
92
93 postInstall =
94 ''
95 # Not used on NixOS
96 sed -i \
97 -e "s,/sbin/modprobe,${kmod}/bin/modprobe,g" \
98 -e "s,/usr/sbin,$out/bin,g" \
99 $out/etc/systemd/system/*
100 '' + lib.optionalString (!enablePython) ''
101 # Remove all scripts that require python (currently mountstats and nfsiostat)
102 grep -l /usr/bin/python $out/bin/* | xargs -I {} rm -v {}
103 '';
104
105 # One test fails on mips.
106 # doCheck = !stdenv.isMips;
107 # https://bugzilla.kernel.org/show_bug.cgi?id=203793
108 doCheck = false;
109
110 disallowedReferences = [ (lib.getDev libkrb5) ];
111
112 passthru.tests = {
113 nfs3-simple = nixosTests.nfs3.simple;
114 nfs4-simple = nixosTests.nfs4.simple;
115 nfs4-kerberos = nixosTests.nfs4.kerberos;
116 };
117
118 meta = with lib; {
119 description = "Linux user-space NFS utilities";
120
121 longDescription = ''
122 This package contains various Linux user-space Network File
123 System (NFS) utilities, including RPC `mount' and `nfs'
124 daemons.
125 '';
126
127 homepage = "https://linux-nfs.org/";
128 license = licenses.gpl2Plus;
129 platforms = platforms.linux;
130 maintainers = with maintainers; [ abbradar ];
131 };
132}