1{ lib, stdenv, fetchurl, fetchpatch, pkg-config, perl, lvm2, libaio, readline, systemd, liburcu, json_c, kmod, nixosTests }:
2
3stdenv.mkDerivation rec {
4 pname = "multipath-tools";
5 version = "0.8.3";
6
7 src = fetchurl {
8 name = "${pname}-${version}.tar.gz";
9 url = "https://git.opensvc.com/gitweb.cgi?p=multipath-tools/.git;a=snapshot;h=refs/tags/${version};sf=tgz";
10 sha256 = "1mgjylklh1cx8px8ffgl12kyc0ln3445vbabd2sy8chq31rpiiq8";
11 };
12
13 patches = [
14 # fix build with json-c 0.14 https://www.redhat.com/archives/dm-devel/2020-May/msg00261.html
15 ./json-c-0.14.patch
16
17 # pull upstream fix for -fno-common toolchains like clang-12
18 (fetchpatch {
19 name = "fno-common.patch";
20 url = "https://github.com/opensvc/multipath-tools/commit/23a9247fa89cd0c84fe7e0f32468fd698b1caa48.patch";
21 sha256 = "10hq0g2jfkfbmwhm4x4q5cgsswj30lm34ib153alqzjzsxc1hqjk";
22 })
23 ];
24
25 postPatch = ''
26 substituteInPlace libmultipath/Makefile \
27 --replace /usr/include/libdevmapper.h ${lib.getDev lvm2}/include/libdevmapper.h
28
29 # systemd-udev-settle.service is deprecated.
30 substituteInPlace multipathd/multipathd.service \
31 --replace /sbin/modprobe ${lib.getBin kmod}/sbin/modprobe \
32 --replace /sbin/multipathd "$out/bin/multipathd" \
33 --replace " systemd-udev-settle.service" ""
34
35 sed -i -re '
36 s,^( *#define +DEFAULT_MULTIPATHDIR\>).*,\1 "'"$out/lib/multipath"'",
37 ' libmultipath/defaults.h
38 sed -i -e 's,\$(DESTDIR)/\(usr/\)\?,$(prefix)/,g' \
39 kpartx/Makefile libmpathpersist/Makefile
40 sed -i -e "s,GZIP,GZ," \
41 $(find * -name Makefile\*)
42 '';
43
44 nativeBuildInputs = [ pkg-config perl ];
45 buildInputs = [ systemd lvm2 libaio readline liburcu json_c ];
46
47 makeFlags = [
48 "LIB=lib"
49 "prefix=$(out)"
50 "man8dir=$(out)/share/man/man8"
51 "man5dir=$(out)/share/man/man5"
52 "man3dir=$(out)/share/man/man3"
53 "SYSTEMDPATH=lib"
54 ];
55
56 passthru.tests = { inherit (nixosTests) iscsi-multipath-root; };
57
58 meta = with lib; {
59 description = "Tools for the Linux multipathing driver";
60 homepage = "http://christophe.varoqui.free.fr/";
61 license = licenses.gpl2;
62 platforms = platforms.linux;
63 };
64}