push sheeet
Some checks failed
Periodic Merges (6h) / master → staging-nixos (push) Failing after 12m50s
Periodic Merges (6h) / master → staging-next (push) Failing after 12m54s
Periodic Merges (24h) / merge-base(master,staging) → haskell-updates (push) Failing after 11m54s
Periodic Merges (6h) / staging-next → staging (push) Failing after 12m13s
Periodic Merges (24h) / staging-next-25.05 → staging-25.05 (push) Failing after 13m24s
Periodic Merges (24h) / release-25.05 → staging-next-25.05 (push) Failing after 14m28s

This commit is contained in:
Dark Steveneq
2025-10-09 14:15:47 +02:00
commit 646b892680
49168 changed files with 5897842 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
{
stdenvNoCC,
kmod,
modules,
buildEnv,
name ? "kernel-modules",
}:
buildEnv {
inherit name;
paths = modules;
postBuild = ''
source ${stdenvNoCC}/setup
if ! test -d "$out/lib/modules"; then
echo "No modules found."
# To support a kernel without modules
exit 0
fi
kernelVersion=$(cd $out/lib/modules && ls -d *)
if test "$(echo $kernelVersion | wc -w)" != 1; then
echo "inconsistent kernel versions: $kernelVersion"
exit 1
fi
echo "kernel version is $kernelVersion"
shopt -s extglob
# Regenerate the depmod map files. Be sure to pass an explicit
# kernel version number, otherwise depmod will use `uname -r'.
if test -w $out/lib/modules/$kernelVersion; then
rm -f $out/lib/modules/$kernelVersion/modules.!(builtin*|order*)
${kmod}/bin/depmod -b $out -C $out/etc/depmod.d -a $kernelVersion
fi
'';
}

View File

@@ -0,0 +1,131 @@
{
stdenv,
lib,
fetchzip,
fetchpatch,
autoconf,
automake,
docbook_xml_dtd_42,
docbook_xml_dtd_43,
docbook_xsl,
gtk-doc,
libtool,
pkg-config,
libxslt,
xz,
zstd,
elf-header,
withDevdoc ? stdenv.hostPlatform == stdenv.buildPlatform,
withStatic ? stdenv.hostPlatform.isStatic,
gitUpdater,
}:
let
systems = [
"/run/booted-system/kernel-modules"
"/run/current-system/kernel-modules"
""
];
modulesDirs = lib.concatMapStringsSep ":" (x: "${x}/lib/modules") systems;
in
stdenv.mkDerivation rec {
pname = "kmod";
version = "31";
# autogen.sh is missing from the release tarball,
# and we need to run it to regenerate gtk_doc.make,
# because the version in the release tarball is broken.
# Possibly this will be fixed in kmod 30?
# https://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git/commit/.gitignore?id=61a93a043aa52ad62a11ba940d4ba93cb3254e78
src = fetchzip {
url = "https://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git/snapshot/kmod-${version}.tar.gz";
hash = "sha256-FNR015/AoYBbi7Eb1M2TXH3yxUuddKICCu+ot10CdeQ=";
};
outputs = [
"out"
"dev"
"lib"
]
++ lib.optional withDevdoc "devdoc";
strictDeps = true;
nativeBuildInputs = [
autoconf
automake
docbook_xsl
libtool
libxslt
pkg-config
docbook_xml_dtd_42 # for the man pages
]
++ lib.optionals withDevdoc [
docbook_xml_dtd_43
gtk-doc
];
buildInputs = [
xz
zstd
]
# gtk-doc is looked for with pkg-config
++ lib.optionals withDevdoc [ gtk-doc ];
preConfigure = ''
./autogen.sh
'';
configureFlags = [
"--sysconfdir=/etc"
"--with-xz"
"--with-zstd"
"--with-modulesdirs=${modulesDirs}"
(lib.enableFeature withDevdoc "gtk-doc")
]
++ lib.optional withStatic "--enable-static";
patches = [
./module-dir.patch
(fetchpatch {
name = "musl.patch";
url = "https://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git/patch/?id=11eb9bc67c319900ab00523997323a97d2d08ad2";
hash = "sha256-CYG615elMWces6QGQRg2H/NL7W4XsG9Zvz5H+xsdFFo=";
})
]
++ lib.optional withStatic ./enable-static.patch;
postInstall = ''
for prog in rmmod insmod lsmod modinfo modprobe depmod; do
ln -sv $out/bin/kmod $out/bin/$prog
done
# Backwards compatibility
ln -s bin $out/sbin
'';
passthru.updateScript = gitUpdater {
# No nicer place to find latest release.
url = "https://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git";
rev-prefix = "v";
};
meta = with lib; {
description = "Tools for loading and managing Linux kernel modules";
longDescription = ''
kmod is a set of tools to handle common tasks with Linux kernel modules
like insert, remove, list, check properties, resolve dependencies and
aliases. These tools are designed on top of libkmod, a library that is
shipped with kmod.
'';
homepage = "https://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git/";
downloadPage = "https://www.kernel.org/pub/linux/utils/kernel/kmod/";
changelog = "https://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git/plain/NEWS?h=v${version}";
license = with licenses; [
lgpl21Plus
gpl2Plus
]; # GPLv2+ for tools
platforms = platforms.linux;
maintainers = with maintainers; [ artturin ];
};
}

View File

@@ -0,0 +1,12 @@
diff --git a/configure.ac b/configure.ac
index ee72283..b42c42a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -19,7 +19,6 @@ AM_SILENT_RULES([yes])
LT_INIT([disable-static pic-only])
DOLT
-AS_IF([test "x$enable_static" = "xyes"], [AC_MSG_ERROR([--enable-static is not supported by kmod])])
AS_IF([test "x$enable_largefile" = "xno"], [AC_MSG_ERROR([--disable-largefile is not supported by kmod])])
#####################################################################

View File

@@ -0,0 +1,157 @@
diff --git a/Makefile.am b/Makefile.am
index d4eeb7e..5c9f603 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -19,6 +19,7 @@ AM_CPPFLAGS = \
-include $(top_builddir)/config.h \
-I$(top_srcdir) \
-DSYSCONFDIR=\""$(sysconfdir)"\" \
+ -DMODULESDIRS=\""$(shell echo $(modulesdirs) | $(SED) 's|:|\\",\\"|g')"\" \
${zlib_CFLAGS}
AM_CFLAGS = $(OUR_CFLAGS)
diff --git a/configure.ac b/configure.ac
index 23510c8..66490cf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -202,6 +202,12 @@ GTK_DOC_CHECK([1.14],[--flavour no-tmpl-flat])
], [
AM_CONDITIONAL([ENABLE_GTK_DOC], false)])
+AC_ARG_WITH([modulesdirs],
+ AS_HELP_STRING([--with-modulesdirs=DIRS], [Kernel modules directories, separated by :]),
+ [],
+ [with_modulesdirs=/lib/modules])
+AC_SUBST([modulesdirs], [$with_modulesdirs])
+
#####################################################################
# Default CFLAGS and LDFLAGS
diff --git a/libkmod/libkmod.c b/libkmod/libkmod.c
index 69fe431..d37da32 100644
--- a/libkmod/libkmod.c
+++ b/libkmod/libkmod.c
@@ -206,12 +206,15 @@ static int log_priority(const char *priority)
return 0;
}
-static const char *dirname_default_prefix = "/lib/modules";
+static const char *dirname_default_prefixes[] = {
+ MODULESDIRS,
+ NULL
+};
static char *get_kernel_release(const char *dirname)
{
struct utsname u;
- char *p;
+ char *p, *dirname_prefix;
if (dirname != NULL)
return path_make_absolute_cwd(dirname);
@@ -219,8 +222,42 @@ static char *get_kernel_release(const char *dirname)
if (uname(&u) < 0)
return NULL;
- if (asprintf(&p, "%s/%s", dirname_default_prefix, u.release) < 0)
- return NULL;
+ if ((dirname_prefix = getenv("MODULE_DIR")) != NULL) {
+ if(asprintf(&p, "%s/%s", dirname_prefix, u.release) < 0)
+ return NULL;
+ } else {
+ size_t i;
+ char buf[PATH_MAX];
+
+ for (i = 0; dirname_default_prefixes[i] != NULL; i++) {
+ int plen;
+ struct stat dirstat;
+
+ plen = snprintf(buf, sizeof(buf), "%s/%s", dirname_default_prefixes[i], u.release);
+ if (plen < 0)
+ return NULL;
+ else if (plen >= PATH_MAX)
+ continue;
+
+ if (dirname_default_prefixes[i + 1] != NULL) {
+ if (stat(buf, &dirstat) < 0) {
+ if (errno == ENOENT)
+ continue;
+ else
+ return NULL;
+ }
+
+ if (!S_ISDIR(dirstat.st_mode))
+ continue;
+ }
+
+ p = malloc(plen + 1);
+ if (p == NULL)
+ return NULL;
+ memcpy(p, buf, plen + 1);
+ break;
+ }
+ }
return p;
}
diff --git a/tools/static-nodes.c b/tools/static-nodes.c
index 8d2356d..2ed306d 100644
--- a/tools/static-nodes.c
+++ b/tools/static-nodes.c
@@ -29,10 +29,11 @@
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
-#include <sys/utsname.h>
#include <shared/util.h>
+#include <libkmod/libkmod.h>
+
#include "kmod.h"
struct static_nodes_format {
@@ -154,8 +155,8 @@ static void help(void)
static int do_static_nodes(int argc, char *argv[])
{
- struct utsname kernel;
char modules[PATH_MAX], buf[4096];
+ struct kmod_ctx *ctx;
const char *output = "/dev/stdout";
FILE *in = NULL, *out = NULL;
const struct static_nodes_format *format = &static_nodes_format_human;
@@ -206,22 +207,25 @@ static int do_static_nodes(int argc, char *argv[])
}
}
- if (uname(&kernel) < 0) {
- fputs("Error: uname failed!\n", stderr);
+ ctx = kmod_new(NULL, NULL);
+ if (ctx == NULL) {
+ fprintf(stderr, "Error: failed to create kmod context\n");
ret = EXIT_FAILURE;
goto finish;
}
-
- snprintf(modules, sizeof(modules), "/lib/modules/%s/modules.devname", kernel.release);
+ if (snprintf(modules, sizeof(modules), "%s/modules.devname", kmod_get_dirname(ctx)) < 0) {
+ fprintf(stderr, "Error: path to modules.devname is too long\n");
+ ret = EXIT_FAILURE;
+ goto finish;
+ }
+ kmod_unref(ctx);
in = fopen(modules, "re");
if (in == NULL) {
if (errno == ENOENT) {
- fprintf(stderr, "Warning: /lib/modules/%s/modules.devname not found - ignoring\n",
- kernel.release);
+ fprintf(stderr, "Warning: %s not found - ignoring\n", modules);
ret = EXIT_SUCCESS;
} else {
- fprintf(stderr, "Error: could not open /lib/modules/%s/modules.devname - %m\n",
- kernel.release);
+ fprintf(stderr, "Error: could not open %s - %m\n", modules);
ret = EXIT_FAILURE;
}
goto finish;