1 { stdenv, kernel, callPackage, lib, dbus
2 , xorg, zlib, patchelf, makeWrapper
5 virtualBoxNixGuestAdditionsBuilder = callPackage ./builder.nix { };
7 # Forced to 1.18; vboxvideo doesn't seem to provide any newer ABI,
8 # and nixpkgs doesn't support older ABIs anymore.
11 # Specifies how to patch binaries to make sure that libraries loaded using
12 # dlopen are found. We grep binaries for specific library names and patch
13 # RUNPATH in matching binaries to contain the needed library paths.
15 { name = "libdbus-1.so"; pkg = dbus; }
16 { name = "libXfixes.so"; pkg = xorg.libXfixes; }
17 { name = "libXrandr.so"; pkg = xorg.libXrandr; }
19 in stdenv.mkDerivation {
20 pname = "VirtualBox-GuestAdditions";
21 version = "${virtualBoxNixGuestAdditionsBuilder.version}-${kernel.version}";
23 src = "${virtualBoxNixGuestAdditionsBuilder}/VBoxGuestAdditions-${if stdenv.hostPlatform.is32bit then "x86" else "amd64"}.tar.bz2";
26 KERN_DIR = "${kernel.dev}/lib/modules/${kernel.modDirVersion}/build";
27 KERN_INCL = "${kernel.dev}/lib/modules/${kernel.modDirVersion}/source/include";
29 hardeningDisable = [ "pic" ];
31 env.NIX_CFLAGS_COMPILE = "-Wno-error=incompatible-pointer-types -Wno-error=implicit-function-declaration";
33 nativeBuildInputs = [ patchelf makeWrapper virtualBoxNixGuestAdditionsBuilder ] ++ kernel.moduleBuildDependencies;
38 # Build kernel modules.
39 cd src/vboxguest-${virtualBoxNixGuestAdditionsBuilder.version}_NixOS
40 # Run just make first. If we only did make install, we get symbol warnings during build.
44 # Change the interpreter for various binaries
45 for i in sbin/VBoxService bin/{VBoxClient,VBoxControl,VBoxDRMClient} other/mount.vboxsf; do
46 patchelf --set-interpreter ${stdenv.cc.bintools.dynamicLinker} $i
47 patchelf --set-rpath ${lib.makeLibraryPath [ stdenv.cc.cc stdenv.cc.libc zlib
48 xorg.libX11 xorg.libXt xorg.libXext xorg.libXmu xorg.libXfixes xorg.libXcursor ]} $i
59 # Install kernel modules.
60 cd src/vboxguest-${virtualBoxNixGuestAdditionsBuilder.version}_NixOS
61 make install INSTALL_MOD_PATH=$out KBUILD_EXTRA_SYMBOLS=$PWD/vboxsf/Module.symvers
65 install -D -m 755 other/mount.vboxsf $out/bin/mount.vboxsf
66 install -D -m 755 sbin/VBoxService $out/bin/VBoxService
68 install -m 755 bin/VBoxClient $out/bin
69 install -m 755 bin/VBoxControl $out/bin
70 install -m 755 bin/VBoxDRMClient $out/bin
73 # Don't install VBoxOGL for now
74 # It seems to be broken upstream too, and fixing it is far down the priority list:
75 # https://www.virtualbox.org/pipermail/vbox-dev/2017-June/014561.html
76 # Additionally, 3d support seems to rely on VBoxOGL.so being symlinked from
77 # libGL.so (which we can't), and Oracle doesn't plan on supporting libglvnd
83 # Stripping breaks these binaries for some reason.
86 # Patch RUNPATH according to dlopenLibs (see the comment there).
87 postFixup = lib.concatMapStrings (library: ''
88 for i in $(grep -F ${lib.escapeShellArg library.name} -l -r $out/{lib,bin}); do
89 origRpath=$(patchelf --print-rpath "$i")
90 patchelf --set-rpath "$origRpath:${lib.makeLibraryPath [ library.pkg ]}" "$i"
95 description = "Guest additions for VirtualBox";
97 Various add-ons which makes NixOS work better as guest OS inside VirtualBox.
98 This add-on provides support for dynamic resizing of the virtual display, shared
99 host/guest clipboard support.
101 sourceProvenance = with lib.sourceTypes; [ fromSource ];
102 license = lib.licenses.gpl2;
103 maintainers = [ lib.maintainers.sander lib.maintainers.friedrichaltheide ];
104 platforms = [ "i686-linux" "x86_64-linux" ];
105 broken = stdenv.hostPlatform.is32bit && (kernel.kernelAtLeast "5.10");