lol

virtualbox: Split kernel modules into own package

Putting the kernel modules into the same output path as the main
VirtualBox derivation causes all of VirtualBox to be rebuilt on every
single kernel update.

The build process of VirtualBox already outputs the kernel module source
along with the generated files for the configuration of the main
VirtualBox package. We put this into a different output called "modsrc"
which we re-use from linuxPackages.virtualbox, which is now only
containing the resulting kernel modules without the main user space
implementation.

This not only has the advantage of decluttering the Nix expression for
the user space portions but also gets rid of the need to nuke references
and the need to patch out "depmod -a".

Signed-off-by: aszlig <aszlig@redmoonstudios.org>

aszlig 8bd89c92 6d69293f

+59 -49
+7 -2
nixos/modules/virtualisation/virtualbox-host.nix
··· 4 4 5 5 let 6 6 cfg = config.virtualisation.virtualbox.host; 7 - virtualbox = config.boot.kernelPackages.virtualbox.override { 7 + 8 + virtualbox = pkgs.virtualbox.override { 8 9 inherit (cfg) enableHardening headless; 10 + }; 11 + 12 + kernelModules = config.boot.kernelPackages.virtualbox.override { 13 + inherit virtualbox; 9 14 }; 10 15 11 16 in ··· 60 65 61 66 config = mkIf cfg.enable (mkMerge [{ 62 67 boot.kernelModules = [ "vboxdrv" "vboxnetadp" "vboxnetflt" ]; 63 - boot.extraModulePackages = [ virtualbox ]; 68 + boot.extraModulePackages = [ kernelModules ]; 64 69 environment.systemPackages = [ virtualbox ]; 65 70 66 71 security.setuidOwners = let
+8 -32
pkgs/applications/virtualization/virtualbox/default.nix
··· 1 1 { stdenv, buildEnv, fetchurl, lib, iasl, dev86, pam, libxslt, libxml2, libX11, xproto, libXext 2 - , libXcursor, libXmu, qt5, libIDL, SDL, libcap, zlib, libpng, glib, kernel, lvm2 2 + , libXcursor, libXmu, qt5, libIDL, SDL, libcap, zlib, libpng, glib, lvm2 3 3 , libXrandr, libXinerama 4 4 , which, alsaLib, curl, libvpx, gawk, nettools, dbus 5 - , xorriso, makeself, perl, pkgconfig, nukeReferences 5 + , xorriso, makeself, perl, pkgconfig 6 6 , javaBindings ? false, jdk ? null 7 7 , pythonBindings ? false, python ? null 8 8 , enableExtensionPack ? false, requireFile ? null, patchelf ? null, fakeroot ? null ··· 18 18 19 19 inherit (importJSON ./upstream-info.json) version extpackRev extpack main; 20 20 21 - forEachModule = action: '' 22 - for mod in \ 23 - out/linux.*/${buildType}/bin/src/vboxdrv \ 24 - out/linux.*/${buildType}/bin/src/vboxpci \ 25 - out/linux.*/${buildType}/bin/src/vboxnetadp \ 26 - out/linux.*/${buildType}/bin/src/vboxnetflt 27 - do 28 - if [ "x$(basename "$mod")" != xvboxdrv -a ! -e "$mod/Module.symvers" ] 29 - then 30 - cp -v out/linux.*/${buildType}/bin/src/vboxdrv/Module.symvers \ 31 - "$mod/Module.symvers" 32 - fi 33 - INSTALL_MOD_PATH="$out" INSTALL_MOD_DIR=misc \ 34 - make -j $NIX_BUILD_CORES -C "$MODULES_BUILD_DIR" DEPMOD=/do_not_use_depmod \ 35 - "M=\$(PWD)/$mod" BUILD_TYPE="${buildType}" ${action} 36 - done 37 - ''; 38 - 39 21 # See https://github.com/NixOS/nixpkgs/issues/672 for details 40 22 extensionPack = requireFile rec { 41 23 name = "Oracle_VM_VirtualBox_Extension_Pack-${version}-${extpackRev}.vbox-extpack"; ··· 59 41 }; 60 42 61 43 in stdenv.mkDerivation { 62 - name = "virtualbox-${version}-${kernel.version}"; 44 + name = "virtualbox-${version}"; 63 45 64 46 src = fetchurl { 65 47 url = "http://download.virtualbox.org/virtualbox/${version}/VirtualBox-${version}.tar.bz2"; 66 48 sha256 = main; 67 49 }; 68 50 51 + outputs = [ "out" "modsrc" ]; 52 + 69 53 buildInputs = 70 54 [ iasl dev86 libxslt libxml2 xproto libX11 libXext libXcursor libIDL 71 55 libcap glib lvm2 python alsaLib curl libvpx pam xorriso makeself perl 72 - pkgconfig which libXmu nukeReferences libpng ] 56 + pkgconfig which libXmu libpng ] 73 57 ++ optional javaBindings jdk 74 58 ++ optional pythonBindings python 75 59 ++ optional pulseSupport libpulseaudio ··· 80 64 81 65 prePatch = '' 82 66 set -x 83 - MODULES_BUILD_DIR=`echo ${kernel.dev}/lib/modules/*/build` 84 - sed -e 's@/lib/modules/`uname -r`/build@'$MODULES_BUILD_DIR@ \ 85 - -e 's@MKISOFS --version@MKISOFS -version@' \ 67 + sed -e 's@MKISOFS --version@MKISOFS -version@' \ 86 68 -e 's@PYTHONDIR=.*@PYTHONDIR=${if pythonBindings then python else ""}@' \ 87 69 -i configure 88 70 ls kBuild/bin/linux.x86/k* tools/linux.x86/bin/* | xargs -n 1 patchelf --set-interpreter ${stdenv.glibc.out}/lib/ld-linux.so.2 89 71 ls kBuild/bin/linux.amd64/k* tools/linux.amd64/bin/* | xargs -n 1 patchelf --set-interpreter ${stdenv.glibc.out}/lib/ld-linux-x86-64.so.2 90 - find . -type f -iname '*makefile*' -exec sed -i -e 's/depmod -a/:/g' {} + 91 72 sed -i -e ' 92 73 s@"libdbus-1\.so\.3"@"${dbus.lib}/lib/libdbus-1.so.3"@g 93 74 s@"libasound\.so\.2"@"${alsaLib.out}/lib/libasound.so.2"@g ··· 152 133 buildPhase = '' 153 134 source env.sh 154 135 kmk -j $NIX_BUILD_CORES BUILD_TYPE="${buildType}" 155 - ${forEachModule "modules"} 156 136 ''; 157 137 158 138 installPhase = '' ··· 163 143 mkdir -p "$libexec" 164 144 find out/linux.*/${buildType}/bin -mindepth 1 -maxdepth 1 \ 165 145 -name src -o -exec cp -avt "$libexec" {} + 166 - 167 - # Install kernel modules 168 - ${forEachModule "modules_install"} 169 146 170 147 # Create wrapper script 171 148 mkdir -p $out/bin ··· 198 175 done 199 176 ''} 200 177 201 - # Get rid of a reference to linux.dev. 202 - nuke-refs $out/lib/modules/*/misc/*.ko 178 + cp -rv out/linux.*/${buildType}/bin/src "$modsrc" 203 179 ''; 204 180 205 181 passthru = { inherit version; /* for guest additions */ };
+23
pkgs/os-specific/linux/virtualbox/default.nix
··· 1 + { stdenv, virtualbox, kernel, strace }: 2 + 3 + stdenv.mkDerivation { 4 + name = "virtualbox-modules-${virtualbox.version}-${kernel.version}"; 5 + src = virtualbox.modsrc; 6 + hardeningDisable = [ 7 + "fortify" "pic" "stackprotector" 8 + ]; 9 + 10 + makeFlags = [ 11 + "-C ${kernel.dev}/lib/modules/${kernel.modDirVersion}/build" 12 + "INSTALL_MOD_PATH=$(out)" 13 + ]; 14 + preBuild = "makeFlagsArray+=(\"M=$(pwd)\")"; 15 + buildFlags = [ "modules" ]; 16 + installTargets = [ "modules_install" ]; 17 + 18 + enableParallelBuilding = true; 19 + 20 + meta = virtualbox.meta // { 21 + description = virtualbox.meta.description + " (kernel modules)"; 22 + }; 23 + }
+21 -15
pkgs/top-level/all-packages.nix
··· 11399 11399 11400 11400 vhba = callPackage ../misc/emulators/cdemu/vhba.nix { }; 11401 11401 11402 - virtualbox = callPackage ../applications/virtualization/virtualbox { 11403 - stdenv = stdenv_32bit; 11404 - inherit (gnome) libIDL; 11405 - enableExtensionPack = config.virtualbox.enableExtensionPack or false; 11406 - pulseSupport = config.pulseaudio or false; 11402 + virtualbox = callPackage ../os-specific/linux/virtualbox { 11403 + virtualbox = pkgs.virtualboxHardened; 11407 11404 }; 11408 11405 11409 - virtualboxHardened = lowPrio (virtualbox.override { 11410 - enableHardening = true; 11411 - }); 11412 - 11413 - virtualboxHeadless = lowPrio (virtualbox.override { 11414 - enableHardening = true; 11415 - headless = true; 11416 - }); 11417 - 11418 - virtualboxGuestAdditions = callPackage ../applications/virtualization/virtualbox/guest-additions { }; 11406 + virtualboxGuestAdditions = callPackage ../applications/virtualization/virtualbox/guest-additions { 11407 + virtualbox = pkgs.virtualboxHardened; 11408 + }; 11419 11409 11420 11410 wireguard = callPackage ../os-specific/linux/wireguard { }; 11421 11411 ··· 15223 15213 }; 15224 15214 15225 15215 virtinst = callPackage ../applications/virtualization/virtinst {}; 15216 + 15217 + virtualbox = callPackage ../applications/virtualization/virtualbox { 15218 + stdenv = stdenv_32bit; 15219 + inherit (gnome) libIDL; 15220 + enableExtensionPack = config.virtualbox.enableExtensionPack or false; 15221 + pulseSupport = config.pulseaudio or false; 15222 + }; 15223 + 15224 + virtualboxHardened = lowPrio (virtualbox.override { 15225 + enableHardening = true; 15226 + }); 15227 + 15228 + virtualboxHeadless = lowPrio (virtualbox.override { 15229 + enableHardening = true; 15230 + headless = true; 15231 + }); 15226 15232 15227 15233 virtualglLib = callPackage ../tools/X11/virtualgl/lib.nix { 15228 15234 fltk = fltk13;