Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ 2 stdenv, 3 kernel, 4 callPackage, 5 lib, 6 dbus, 7 xorg, 8 zlib, 9 patchelf, 10 makeWrapper, 11 wayland, 12 libX11, 13}: 14let 15 virtualboxVersion = "7.1.12"; 16 virtualboxSubVersion = ""; 17 virtualboxSha256 = "6f9618f39168898134975f51df7c2d6d5129c0aa82b6ae11cf47f920c70df276"; 18 19 virtualBoxNixGuestAdditionsBuilder = callPackage ./builder.nix { 20 inherit virtualboxVersion virtualboxSubVersion virtualboxSha256; 21 }; 22 23 # Specifies how to patch binaries to make sure that libraries loaded using 24 # dlopen are found. We grep binaries for specific library names and patch 25 # RUNPATH in matching binaries to contain the needed library paths. 26 dlopenLibs = [ 27 { 28 name = "libdbus-1.so"; 29 pkg = dbus; 30 } 31 { 32 name = "libXfixes.so"; 33 pkg = xorg.libXfixes; 34 } 35 { 36 name = "libXrandr.so"; 37 pkg = xorg.libXrandr; 38 } 39 { 40 name = "libwayland-client.so"; 41 pkg = wayland; 42 } 43 { 44 name = "libX11.so"; 45 pkg = libX11; 46 } 47 { 48 name = "libXt.so"; 49 pkg = xorg.libXt; 50 } 51 ]; 52in 53stdenv.mkDerivation { 54 pname = "VirtualBox-GuestAdditions"; 55 version = "${virtualboxVersion}${virtualboxSubVersion}-${kernel.version}"; 56 57 src = "${virtualBoxNixGuestAdditionsBuilder}/VBoxGuestAdditions-${ 58 if stdenv.hostPlatform.is32bit then "x86" else "amd64" 59 }.tar.bz2"; 60 sourceRoot = "."; 61 62 KERN_DIR = "${kernel.dev}/lib/modules/${kernel.modDirVersion}/build"; 63 KERN_INCL = "${kernel.dev}/lib/modules/${kernel.modDirVersion}/source/include"; 64 65 hardeningDisable = [ "pic" ]; 66 67 env.NIX_CFLAGS_COMPILE = "-Wno-error=incompatible-pointer-types -Wno-error=implicit-function-declaration"; 68 69 nativeBuildInputs = [ 70 patchelf 71 makeWrapper 72 virtualBoxNixGuestAdditionsBuilder 73 ] 74 ++ kernel.moduleBuildDependencies; 75 76 buildPhase = '' 77 runHook preBuild 78 79 # Build kernel modules. 80 cd src/vboxguest-${virtualboxVersion}_NixOS 81 # Run just make first. If we only did make install, we get symbol warnings during build. 82 make 83 cd ../.. 84 85 # Change the interpreter for various binaries 86 for i in sbin/VBoxService bin/{VBoxClient,VBoxControl,VBoxDRMClient} other/mount.vboxsf; do 87 patchelf --set-interpreter ${stdenv.cc.bintools.dynamicLinker} $i 88 patchelf --set-rpath ${ 89 lib.makeLibraryPath [ 90 stdenv.cc.cc 91 stdenv.cc.libc 92 zlib 93 xorg.libX11 94 xorg.libXt 95 xorg.libXext 96 xorg.libXmu 97 xorg.libXfixes 98 xorg.libXcursor 99 ] 100 } $i 101 done 102 103 runHook postBuild 104 ''; 105 106 installPhase = '' 107 runHook preInstall 108 109 mkdir -p $out/bin 110 111 # Install kernel modules. 112 cd src/vboxguest-${virtualboxVersion}_NixOS 113 make install INSTALL_MOD_PATH=$out KBUILD_EXTRA_SYMBOLS=$PWD/vboxsf/Module.symvers 114 cd ../.. 115 116 # Install binaries 117 install -D -m 755 other/mount.vboxsf $out/bin/mount.vboxsf 118 install -D -m 755 sbin/VBoxService $out/bin/VBoxService 119 120 install -m 755 bin/VBoxClient $out/bin 121 install -m 755 bin/VBoxControl $out/bin 122 install -m 755 bin/VBoxDRMClient $out/bin 123 124 125 # Don't install VBoxOGL for now 126 # It seems to be broken upstream too, and fixing it is far down the priority list: 127 # https://www.virtualbox.org/pipermail/vbox-dev/2017-June/014561.html 128 # Additionally, 3d support seems to rely on VBoxOGL.so being symlinked from 129 # libGL.so (which we can't), and Oracle doesn't plan on supporting libglvnd 130 # either. (#18457) 131 132 runHook postInstall 133 ''; 134 135 # Stripping breaks these binaries for some reason. 136 dontStrip = true; 137 138 # Patch RUNPATH according to dlopenLibs (see the comment there). 139 postFixup = lib.concatMapStrings (library: '' 140 for i in $(grep -F ${lib.escapeShellArg library.name} -l -r $out/{lib,bin}); do 141 origRpath=$(patchelf --print-rpath "$i") 142 patchelf --set-rpath "$origRpath:${lib.makeLibraryPath [ library.pkg ]}" "$i" 143 done 144 '') dlopenLibs; 145 146 meta = { 147 description = "Guest additions for VirtualBox"; 148 longDescription = '' 149 Various add-ons which makes NixOS work better as guest OS inside VirtualBox. 150 This add-on provides support for dynamic resizing of the virtual display, shared 151 host/guest clipboard support. 152 ''; 153 sourceProvenance = with lib.sourceTypes; [ fromSource ]; 154 license = lib.licenses.gpl3Only; 155 maintainers = [ 156 lib.maintainers.sander 157 lib.maintainers.friedrichaltheide 158 ]; 159 platforms = [ 160 "i686-linux" 161 "x86_64-linux" 162 ]; 163 broken = stdenv.hostPlatform.is32bit && (kernel.kernelAtLeast "5.10"); 164 }; 165}