3 # When no modules are built, the $out/lib/modules directory will not
4 # exist. Because the rest of the script assumes it does exist, we
5 # handle this special case first.
6 if ! test -d "$kernel/lib/modules"; then
7 if test -z "$rootModules" ||
test -n "$allowMissing"; then
11 echo "Required modules: $rootModules"
12 echo "Can not derive a closure of kernel modules because no modules were provided."
17 version
=$
(cd $kernel/lib
/modules
&& ls -d *)
19 echo "kernel version is $version"
21 # Determine the dependencies of each root module.
22 mkdir
-p $out/lib
/modules
/"$version"
24 for module
in $rootModules; do
25 echo "root module: $module"
26 modprobe
--config no-config
-d $kernel --set-version "$version" --show-depends "$module" \
27 |
while read cmd module args
; do
31 echo "$module" >>closure
32 echo " builtin dependency: $module";;
35 if ! test -e "$module"; then
36 echo " dependency not found: $module"
39 target
=$
(echo "$module" |
sed "s^$NIX_STORE.*/lib/modules/^$out/lib/modules/^")
40 if test -e "$target"; then
41 echo " dependency already copied: $module"
44 echo "$module" >>closure
45 echo " copying dependency: $module"
46 mkdir
-p $
(dirname $target)
47 cp "$module" "$target"
48 # If the kernel is compiled with coverage instrumentation, it
49 # contains the paths of the *.gcda coverage data output files
50 # (which it doesn't actually use...). Get rid of them to prevent
51 # the whole kernel from being included in the initrd.
53 echo "$target" >> $out/insmod-list
;;
55 echo " unexpected modprobe output: $cmd $module"
58 done ||
test -n "$allowMissing"
59 if ! test -e found
; then
61 if test -z "$allowMissing"; then
70 for module
in $
(< ~
-/closure
); do
71 # for builtin modules, modinfo will reply with a wrong output looking like:
72 # $ modinfo -F firmware unix
75 # There is a pending attempt to fix this:
76 # https://github.com/NixOS/nixpkgs/pull/96153
77 # https://lore.kernel.org/linux-modules/20200823215433.j5gc5rnsmahpf43v@blumerang/T/#u
79 # For now, the workaround is just to filter out the extraneous lines out
81 modinfo
-b $kernel --set-version "$version" -F firmware
$module |
grep -v '^name:' |
while read -r i
; do
82 echo "firmware for $module: $i"
83 for name
in "$i" "$i.xz" "$i.zst" ""; do
84 [ -z "$name" ] && echo "WARNING: missing firmware $i for module $module"
85 if cp -v --parents --no-preserve=mode lib
/firmware
/$name "$out" 2>/dev
/null
; then
92 if test -e lib
/firmware
/edid
; then
93 echo "lib/firmware/edid found, copying."
94 mkdir
-p "$out/lib/firmware"
95 cp -v --no-preserve=mode
--recursive --dereference --no-target-directory lib
/firmware
/edid
"$out/lib/firmware/edid"
97 echo "lib/firmware/edid not found, skipping."
100 # copy module ordering hints for depmod
101 cp $kernel/lib
/modules
/"$version"/modules.order
$out/lib
/modules
/"$version"/.
102 cp $kernel/lib
/modules
/"$version"/modules.
builtin $out/lib
/modules
/"$version"/.
104 depmod
-b $out -a $version
106 # remove original hints from final derivation
107 rm $out/lib
/modules
/"$version"/modules.order
108 rm $out/lib
/modules
/"$version"/modules.
builtin