1{
2 stdenv,
3 lib,
4 fetchFromGitHub,
5 kernel,
6 kernelModuleMakeFlags,
7}:
8
9let
10 modDestDir = "$out/lib/modules/${kernel.modDirVersion}/kernel/drivers/net/wireless/realtek/r8168";
11
12in
13stdenv.mkDerivation rec {
14 name = "r8168-${kernel.version}-${version}";
15 # on update please verify that the source matches the realtek version
16 version = "8.055.00";
17
18 # This is a mirror. The original website[1] doesn't allow non-interactive
19 # downloads, instead emailing you a download link.
20 # [1] https://www.realtek.com/Download/List?cate_id=584
21 # I've verified manually (`diff -r`) that the source code for version 8.055.00
22 # is the same as the one available on the realtek website.
23 src = fetchFromGitHub {
24 owner = "mtorromeo";
25 repo = "r8168";
26 rev = version;
27 sha256 = "sha256-qL64+jlF1biWaYc5Ga/fjz8ZY3u72bcKVtDpiozHb1g=";
28 };
29
30 hardeningDisable = [ "pic" ];
31
32 nativeBuildInputs = kernel.moduleBuildDependencies;
33
34 # avoid using the Makefile directly -- it doesn't understand
35 # any kernel but the current.
36 # based on the ArchLinux pkgbuild: https://git.archlinux.org/svntogit/community.git/tree/trunk/PKGBUILD?h=packages/r8168
37 makeFlags = kernelModuleMakeFlags ++ [
38 "-C ${kernel.dev}/lib/modules/${kernel.modDirVersion}/build"
39 "M=$(PWD)/src"
40 "modules"
41 ];
42 preBuild = ''
43 makeFlagsArray+=("EXTRA_CFLAGS=-DCONFIG_R8168_NAPI -DCONFIG_R8168_VLAN -DCONFIG_ASPM -DENABLE_S5WOL -DENABLE_EEE")
44 '';
45
46 enableParallelBuilding = true;
47
48 installPhase = ''
49 mkdir -p ${modDestDir}
50 find . -name '*.ko' -exec cp --parents '{}' ${modDestDir} \;
51 find ${modDestDir} -name '*.ko' -exec xz -f '{}' \;
52 '';
53
54 meta = with lib; {
55 description = "Realtek r8168 driver";
56 longDescription = ''
57 A kernel module for Realtek 8168 network cards.
58 If you want to use this driver, you might need to blacklist the r8169 driver
59 by adding "r8169" to boot.blacklistedKernelModules.
60 '';
61 license = licenses.gpl2Plus;
62 platforms = platforms.linux;
63 maintainers = [ ];
64 broken = lib.versionAtLeast kernel.modDirVersion "6.13";
65 };
66}