1{ stdenv, lib, fetchzip, fetchpatch, autoconf, automake, docbook_xml_dtd_42
2, docbook_xml_dtd_43, docbook_xsl, gtk-doc, libtool, pkg-config
3, libxslt, xz, zstd, elf-header
4, withDevdoc ? stdenv.hostPlatform == stdenv.buildPlatform
5, withStatic ? stdenv.hostPlatform.isStatic
6, gitUpdater
7}:
8
9let
10 systems = [ "/run/booted-system/kernel-modules" "/run/current-system/kernel-modules" "" ];
11 modulesDirs = lib.concatMapStringsSep ":" (x: "${x}/lib/modules") systems;
12
13in stdenv.mkDerivation rec {
14 pname = "kmod";
15 version = "31";
16
17 # autogen.sh is missing from the release tarball,
18 # and we need to run it to regenerate gtk_doc.make,
19 # because the version in the release tarball is broken.
20 # Possibly this will be fixed in kmod 30?
21 # https://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git/commit/.gitignore?id=61a93a043aa52ad62a11ba940d4ba93cb3254e78
22 src = fetchzip {
23 url = "https://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git/snapshot/kmod-${version}.tar.gz";
24 hash = "sha256-FNR015/AoYBbi7Eb1M2TXH3yxUuddKICCu+ot10CdeQ=";
25 };
26
27 outputs = [ "out" "dev" "lib" ] ++ lib.optional withDevdoc "devdoc";
28
29 strictDeps = true;
30 nativeBuildInputs = [
31 autoconf automake docbook_xsl libtool libxslt pkg-config
32
33 docbook_xml_dtd_42 # for the man pages
34 ] ++ lib.optionals withDevdoc [ docbook_xml_dtd_43 gtk-doc ];
35 buildInputs = [ xz zstd ]
36 # gtk-doc is looked for with pkg-config
37 ++ lib.optionals withDevdoc [ gtk-doc ];
38
39 preConfigure = ''
40 ./autogen.sh
41 '';
42
43 configureFlags = [
44 "--sysconfdir=/etc"
45 "--with-xz"
46 "--with-zstd"
47 "--with-modulesdirs=${modulesDirs}"
48 (lib.enableFeature withDevdoc "gtk-doc")
49 ] ++ lib.optional withStatic "--enable-static";
50
51 patches = [
52 ./module-dir.patch
53 (fetchpatch {
54 name = "musl.patch";
55 url = "https://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git/patch/?id=11eb9bc67c319900ab00523997323a97d2d08ad2";
56 hash = "sha256-CYG615elMWces6QGQRg2H/NL7W4XsG9Zvz5H+xsdFFo=";
57 })
58 ] ++ lib.optional withStatic ./enable-static.patch;
59
60 postInstall = ''
61 for prog in rmmod insmod lsmod modinfo modprobe depmod; do
62 ln -sv $out/bin/kmod $out/bin/$prog
63 done
64
65 # Backwards compatibility
66 ln -s bin $out/sbin
67 '';
68
69 passthru.updateScript = gitUpdater {
70 # No nicer place to find latest release.
71 url = "https://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git";
72 rev-prefix = "v";
73 };
74
75 meta = with lib; {
76 description = "Tools for loading and managing Linux kernel modules";
77 longDescription = ''
78 kmod is a set of tools to handle common tasks with Linux kernel modules
79 like insert, remove, list, check properties, resolve dependencies and
80 aliases. These tools are designed on top of libkmod, a library that is
81 shipped with kmod.
82 '';
83 homepage = "https://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git/";
84 downloadPage = "https://www.kernel.org/pub/linux/utils/kernel/kmod/";
85 changelog = "https://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git/plain/NEWS?h=v${version}";
86 license = with licenses; [ lgpl21Plus gpl2Plus ]; # GPLv2+ for tools
87 platforms = platforms.linux;
88 maintainers = with maintainers; [ artturin ];
89 };
90}