1{
2 lib,
3 stdenv,
4 fetchurl,
5 fetchpatch,
6 which,
7 autoconf,
8 automake,
9 flex,
10 bison,
11 kernel,
12 glibc,
13 perl,
14 libtool_2,
15 libkrb5,
16}:
17
18let
19 inherit (import ./srcs.nix { inherit fetchurl; }) src version;
20
21 modDestDir = "$out/lib/modules/${kernel.modDirVersion}/extra/openafs";
22 kernelBuildDir = "${kernel.dev}/lib/modules/${kernel.modDirVersion}/build";
23
24in
25stdenv.mkDerivation {
26 pname = "openafs";
27 version = "${version}-${kernel.modDirVersion}";
28 inherit src;
29
30 patches = [
31 # LINUX: Refactor afs_linux_dentry_revalidate()
32 (fetchpatch {
33 url = "https://gerrit.openafs.org/changes/16276/revisions/c1d074317e5c8cb8212e0b19a29f7d710bcabb32/patch";
34 decode = "base64 -d";
35 hash = "sha256-8ga9ks9pr6pWaV2t67v+FaG0yVExhqELkvkpdLvO8Nc=";
36 })
37 # Linux-6.14: Handle dops.d_revalidate with parent
38 (fetchpatch {
39 url = "https://gerrit.openafs.org/changes/16277/revisions/0051bd0ee82b05e8caacdc0596e5b62609bebd2e/patch";
40 decode = "base64 -d";
41 hash = "sha256-08jedwZ1KX1RSs8y9sh7BUvv5xK9tlzZ6uBOR4kS0Jo=";
42 })
43 # Linux: Add required MODULE_DESCRIPTION
44 (fetchpatch {
45 url = "https://gerrit.openafs.org/changes/16372/revisions/39189eba45542376e668636bd79a93ae6a8a7cd2/patch";
46 decode = "base64 -d";
47 hash = "sha256-j5ckKQvybEvmlnFs5jX8g8Dfw37LYWGnfsl4hnZ3+A4=";
48 })
49 # linux: inode_ops mkdir returns struct dentry *
50 (fetchpatch {
51 url = "https://gerrit.openafs.org/changes/16373/revisions/769847e205d5908a0c430f7bcfbd2f48e19f8bf8/patch";
52 decode = "base64 -d";
53 hash = "sha256-znv5gunyPnJgi4SRFERJudtYFqiS+AVYDWfvr52Ku3s=";
54 })
55 # Linux: Use __filemap_get_folio()
56 (fetchpatch {
57 url = "https://gerrit.openafs.org/changes/16374/revisions/f187add554da9e9c52752edbfa98f486f683cf25/patch";
58 decode = "base64 -d";
59 hash = "sha256-+ay87ThSn6QyPZcN0+oE01Wqbxmz0Z1KXYwocQCvYLg=";
60 })
61 # Linux: Use folio_wait_locked()
62 (fetchpatch {
63 url = "https://gerrit.openafs.org/changes/16375/revisions/87a93f6488585553d833e1397e7f0dae0545cb7e/patch";
64 decode = "base64 -d";
65 hash = "sha256-MOVX2LFe8OBnvsQ2UdLvwKrwztOmnu1rdIou4CF+EBs=";
66 })
67 # cf: Introduce AC_CHECK_LINUX_SYMBOL
68 (fetchpatch {
69 url = "https://gerrit.openafs.org/changes/16376/revisions/bab5968d7f4639d4a0cbe81aaa3e9716dda00632/patch";
70 decode = "base64 -d";
71 hash = "sha256-d6DZqDTW1uEKSB5PsomS4ix9fYYQzdQVmDATKl6n7x4=";
72 })
73 # cf: check for dentry flag macros/enums
74 (fetchpatch {
75 url = "https://gerrit.openafs.org/changes/16377/revisions/f791d8ca4804486c656bc7c221076480df39b465/patch";
76 decode = "base64 -d";
77 hash = "sha256-7B0VJE3FeSQU1ElvXI5zXCPq1JRLAycyhqIQuDdR7xE=";
78 })
79 ];
80
81 nativeBuildInputs = [
82 autoconf
83 automake
84 flex
85 libtool_2
86 perl
87 which
88 bison
89 ]
90 ++ kernel.moduleBuildDependencies;
91
92 buildInputs = [ libkrb5 ];
93
94 hardeningDisable = [ "pic" ];
95
96 configureFlags = [
97 "--with-linux-kernel-build=${kernelBuildDir}"
98 "--sysconfdir=/etc"
99 "--localstatedir=/var"
100 "--with-gssapi"
101 ];
102
103 preConfigure = ''
104 patchShebangs .
105 for i in `grep -l -R '/usr/\(include\|src\)' .`; do
106 echo "Patch /usr/include and /usr/src in $i"
107 substituteInPlace $i \
108 --replace "/usr/include" "${glibc.dev}/include" \
109 --replace "/usr/src" "${kernelBuildDir}"
110 done
111
112 ./regen.sh -q
113 '';
114
115 buildPhase = ''
116 make V=1 only_libafs
117 '';
118
119 installPhase = ''
120 mkdir -p ${modDestDir}
121 cp src/libafs/MODLOAD-*/libafs-${kernel.modDirVersion}.* ${modDestDir}/libafs.ko
122 xz -f ${modDestDir}/libafs.ko
123 '';
124
125 meta = with lib; {
126 description = "Open AFS client kernel module";
127 homepage = "https://www.openafs.org";
128 license = licenses.ipl10;
129 platforms = platforms.linux;
130 maintainers = with maintainers; [
131 andersk
132 maggesi
133 spacefrogg
134 ];
135 broken = kernel.isHardened;
136 };
137}