1{ stdenv, lib, fetchurl, kernel, flex, coccinelle, python3 }:
2
3stdenv.mkDerivation rec {
4 name = "drbd-${version}-${kernel.version}";
5 version = "9.2.8";
6
7 src = fetchurl {
8 url = "https://pkg.linbit.com//downloads/drbd/9/drbd-${version}.tar.gz";
9 hash = "sha256-LqK1lPucab7wKvcB4VKGdvBIq+K9XtuO2m0DP5XtK3M=";
10 };
11
12 hardeningDisable = [ "pic" ];
13
14 nativeBuildInputs = [
15 kernel.moduleBuildDependencies
16 flex
17 coccinelle
18 python3
19 ];
20
21 makeFlags = [
22 "KDIR=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build"
23 "SPAAS=false"
24 ];
25
26 # 6.4 and newer provide a in-tree version of the handshake module https://www.kernel.org/doc/html/v6.4/networking/tls-handshake.html
27 installPhase = ''
28 runHook preInstall
29 install -D drbd/drbd.ko -t $out/lib/modules/${kernel.modDirVersion}/kernel/drivers/block/drbd9
30 install -D drbd/drbd_transport_tcp.ko -t $out/lib/modules/${kernel.modDirVersion}/kernel/drivers/block/drbd9
31 install -D drbd/drbd_transport_lb-tcp.ko -t $out/lib/modules/${kernel.modDirVersion}/kernel/drivers/block/drbd9
32 install -D drbd/drbd_transport_rdma.ko -t $out/lib/modules/${kernel.modDirVersion}/kernel/drivers/block/drbd9
33 ${lib.optionalString (lib.versionOlder kernel.version "6.4") ''
34 install -D drbd/drbd-kernel-compat/handshake/handshake.ko -t $out/lib/modules/${kernel.modDirVersion}/kernel/drivers/block/drbd9
35 ''}
36 runHook postInstall
37 '';
38
39 postPatch = ''
40 patchShebangs .
41 substituteInPlace Makefile --replace 'SHELL=/bin/bash' 'SHELL=${builtins.getEnv "SHELL"}'
42 '';
43
44 # builder.pl had complained about the same file (drbd.ko.xz) provided by two different packages
45 # builder.pl also had complained about different permissions between the files from the two packages
46 # The compression is required because the kernel has the CONFIG_MODULE_COMPRESS_XZ option enabled
47 postFixup = ''
48 for ko in $out/lib/modules/${kernel.modDirVersion}/kernel/drivers/block/drbd9/*.ko; do
49 xz --compress -6 --threads=0 $ko
50 chmod 0444 $ko.xz
51 done
52 '';
53
54 enableParallelBuilding = true;
55
56 meta = with lib; {
57 homepage = "https://github.com/LINBIT/drbd";
58 description = "LINBIT DRBD kernel module";
59 license = licenses.gpl2Plus;
60 platforms = platforms.linux;
61 maintainers = with maintainers; [ birkb ];
62 longDescription = ''
63 DRBD is a software-based, shared-nothing, replicated storage solution
64 mirroring the content of block devices (hard disks, partitions, logical volumes, and so on) between hosts.
65 '';
66 broken = lib.versionAtLeast kernel.version "6.8"; # wait until next DRBD release for 6.8 support https://github.com/LINBIT/drbd/issues/87#issuecomment-2059323084
67 };
68}