Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)

kmod: enable on darwin

This is needed to build linux kernels on darwin. While we can’t
actually use it to load kernel modules, we can use it to create
indexes of modules on macOS.

(cherry picked from commit ebb31480e8a45efbaff4c4a212bdfc0b053adde0)

+129 -4
+123
pkgs/os-specific/linux/kmod/darwin.patch
··· 1 + diff --git a/Makefile.am b/Makefile.am 2 + index 194e111..0a095b5 100644 3 + --- a/Makefile.am 4 + +++ b/Makefile.am 5 + @@ -80,8 +80,7 @@ EXTRA_DIST += libkmod/README \ 6 + libkmod/COPYING testsuite/COPYING tools/COPYING COPYING 7 + 8 + libkmod_libkmod_la_LDFLAGS = $(AM_LDFLAGS) \ 9 + - -version-info $(LIBKMOD_CURRENT):$(LIBKMOD_REVISION):$(LIBKMOD_AGE) \ 10 + - -Wl,--version-script=$(top_srcdir)/libkmod/libkmod.sym 11 + + -version-info $(LIBKMOD_CURRENT):$(LIBKMOD_REVISION):$(LIBKMOD_AGE) 12 + libkmod_libkmod_la_DEPENDENCIES = \ 13 + shared/libshared.la \ 14 + ${top_srcdir}/libkmod/libkmod.sym 15 + @@ -91,8 +90,7 @@ libkmod_libkmod_la_LIBADD = \ 16 + 17 + noinst_LTLIBRARIES += libkmod/libkmod-internal.la 18 + libkmod_libkmod_internal_la_SOURCES = $(libkmod_libkmod_la_SOURCES) 19 + -libkmod_libkmod_internal_la_LDFLAGS = $(AM_LDFLAGS) \ 20 + - -Wl,--version-script=$(top_srcdir)/libkmod/libkmod.sym 21 + +libkmod_libkmod_internal_la_LDFLAGS = $(AM_LDFLAGS) 22 + libkmod_libkmod_internal_la_DEPENDENCIES = $(libkmod_libkmod_la_DEPENDENCIES) 23 + libkmod_libkmod_internal_la_LIBADD = $(libkmod_libkmod_la_LIBADD) 24 + 25 + diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c 26 + index 889f264..6f0a285 100644 27 + --- a/libkmod/libkmod-module.c 28 + +++ b/libkmod/libkmod-module.c 29 + @@ -787,7 +787,11 @@ KMOD_EXPORT int kmod_module_remove_module(struct kmod_module *mod, 30 + flags &= KMOD_REMOVE_FORCE; 31 + flags |= KMOD_REMOVE_NOWAIT; 32 + 33 + +#if defined(__linux__) 34 + err = delete_module(mod->name, flags); 35 + +#else 36 + + err = -1; 37 + +#endif 38 + if (err != 0) { 39 + err = -errno; 40 + ERR(mod->ctx, "could not remove '%s': %m\n", mod->name); 41 + @@ -879,7 +883,11 @@ KMOD_EXPORT int kmod_module_insert_module(struct kmod_module *mod, 42 + } 43 + size = kmod_file_get_size(mod->file); 44 + 45 + +#if defined(__linux__) 46 + err = init_module(mem, size, args); 47 + +#else 48 + + err = -1; 49 + +#endif 50 + init_finished: 51 + if (err < 0) { 52 + err = -errno; 53 + diff --git a/libkmod/libkmod-signature.c b/libkmod/libkmod-signature.c 54 + index 429ffbd..17a3b9c 100644 55 + --- a/libkmod/libkmod-signature.c 56 + +++ b/libkmod/libkmod-signature.c 57 + @@ -17,7 +17,10 @@ 58 + * License along with this library; if not, see <http://www.gnu.org/licenses/>. 59 + */ 60 + 61 + +#if defined(__linux__) 62 + #include <endian.h> 63 + +#endif 64 + + 65 + #include <inttypes.h> 66 + #include <stdio.h> 67 + #include <stdlib.h> 68 + diff --git a/shared/macro.h b/shared/macro.h 69 + index 4fc5405..b5a2702 100644 70 + --- a/shared/macro.h 71 + +++ b/shared/macro.h 72 + @@ -71,3 +71,7 @@ 73 + #endif 74 + 75 + #define UNIQ __COUNTER__ 76 + + 77 + + #if !defined(__linux__) 78 + +#define program_invocation_short_name getprogname() 79 + +#endif 80 + diff --git a/shared/missing.h b/shared/missing.h 81 + index 4c0d136..ad8ec0f 100644 82 + --- a/shared/missing.h 83 + +++ b/shared/missing.h 84 + @@ -45,6 +45,9 @@ static inline int finit_module(int fd, const char *uargs, int flags) 85 + #endif 86 + 87 + #if !HAVE_DECL_BE32TOH 88 + + 89 + +#if defined(__linux__) 90 + + 91 + #include <endian.h> 92 + #include <byteswap.h> 93 + #if __BYTE_ORDER == __LITTLE_ENDIAN 94 + @@ -52,4 +55,16 @@ static inline int finit_module(int fd, const char *uargs, int flags) 95 + #else 96 + #define be32toh(x) (x) 97 + #endif 98 + + 99 + +#elif defined(__APPLE__) 100 + + 101 + +#include <libkern/OSByteOrder.h> 102 + +#define be32toh(x) OSSwapBigToHostInt32(x) 103 + + 104 + +#else 105 + + 106 + +#error No be32toh known for platform 107 + + 108 + +#endif 109 + + 110 + #endif 111 + diff --git a/shared/util.c b/shared/util.c 112 + index fd2028d..ecb0141 100644 113 + --- a/shared/util.c 114 + +++ b/shared/util.c 115 + @@ -367,7 +367,7 @@ char *path_make_absolute_cwd(const char *p) 116 + if (path_is_absolute(p)) 117 + return strdup(p); 118 + 119 + - cwd = get_current_dir_name(); 120 + + cwd = getcwd(NULL, 0); 121 + if (!cwd) 122 + return NULL; 123 +
+6 -4
pkgs/os-specific/linux/kmod/default.nix
··· 1 - { stdenv, buildPackages, lib, fetchurl, autoreconfHook, pkgconfig, libxslt, xz }: 1 + { stdenv, buildPackages, lib, fetchurl, autoreconfHook, pkgconfig 2 + , libxslt, xz, elf-header }: 2 3 3 4 let 4 5 systems = [ "/run/current-system/kernel-modules" "/run/booted-system/kernel-modules" "" ]; ··· 14 15 }; 15 16 16 17 nativeBuildInputs = [ autoreconfHook pkgconfig libxslt ]; 17 - buildInputs = [ xz ]; 18 + buildInputs = [ xz elf-header ]; 18 19 19 20 configureFlags = [ 20 21 "--sysconfdir=/etc" ··· 22 23 "--with-modulesdirs=${modulesDirs}" 23 24 ]; 24 25 25 - patches = [ ./module-dir.patch ]; 26 + patches = [ ./module-dir.patch ] 27 + ++ lib.optional stdenv.isDarwin ./darwin.patch; 26 28 27 29 postInstall = '' 28 30 for prog in rmmod insmod lsmod modinfo modprobe depmod; do ··· 37 39 homepage = https://www.kernel.org/pub/linux/utils/kernel/kmod/; 38 40 description = "Tools for loading and managing Linux kernel modules"; 39 41 license = licenses.lgpl21; 40 - platforms = platforms.linux; 42 + platforms = platforms.unix; 41 43 }; 42 44 }