linux: add setup hook for kernel compression

This setup hook ensures that kernel modules are compressed with
parameters the kernel is capable of decompressing. This is currently
only effective when xz is used as the kernel module compression
algorithm.
This commit is contained in:
Jared Baur
2026-08-05 22:21:15 -07:00
parent 91a610be19
commit cad163aa3e
2 changed files with 18 additions and 0 deletions

View File

@@ -23,6 +23,8 @@
rustc-unwrapped,
rust-bindgen-unwrapped,
rustPlatform,
makeSetupHook,
xz,
}:
let
@@ -158,6 +160,11 @@ lib.makeOverridable (
elfutils
# module makefiles often run uname commands to find out the kernel version
(buildPackages.deterministic-uname.override { inherit modDirVersion; })
(makeSetupHook {
name = "setup-module-compression";
substitutions = { inherit configfile modDirVersion; };
propagatedNativeBuildInputs = [ xz ];
} ./setup-module-compression.sh)
]
++ optional (lib.versionAtLeast version "5.13") zstd
++ optionals withRust [

View File

@@ -0,0 +1,11 @@
# shellcheck shell=bash
setupModuleCompressionHook() {
# Ensure CRC32 is used, which the kernel is capable of decompressing natively (enabled by CONFIG_MODULE_DECOMPRESS=y).
export XZ_OPT="--check=crc32"
}
if [[ -z "${dontSetupModuleCompression-}" ]]; then
nixInfoLog "Using setupModuleCompressionHook"
postConfigureHooks+=(setupModuleCompressionHook)
fi