@@ -1,5 +1,5 @@
11{ stdenv, fetchurl, lib, patchelf, cdrkit, kernel, which, makeWrapper
2−, xorg, dbus, virtualbox }:
2+, zlib, xorg, dbus, virtualbox }:
33
44let
55 version = virtualbox.version;
@@ -19,32 +19,23 @@ stdenv.mkDerivation {
1919
2020 src = fetchurl {
2121 url = "http://download.virtualbox.org/virtualbox/${version}/VBoxGuestAdditions_${version}.iso";
22− sha256 = "0cwdmdgcd1jysyw7c9b3cdk1ngk5nq7slh1zkhxkvvq142cnm1v9";
22+ sha256 = "1srcsf9264l5yxbq2x83z66j38blbfrywq5lkzwb5kih6sv548c3";
2323 };
2424
2525 KERN_DIR = "${kernel.dev}/lib/modules/${kernel.modDirVersion}/build";
2626 KERN_INCL = "${kernel.dev}/lib/modules/${kernel.modDirVersion}/source/include";
2727
28− patchFlags = [ "-p1" "-d" "install/src/vboxguest-${version}" ];
29−
30− patches = [
31− ./fix_kerndir.patch
32− ./fix_kernincl.patch
33− ];
28+ # If you add a patch you probably need this.
29+ #patchFlags = [ "-p1" "-d" "install/src/vboxguest-${version}" ];
3430
3531 hardeningDisable = [ "pic" ];
3632
3733 NIX_CFLAGS_COMPILE = "-Wno-error=incompatible-pointer-types -Wno-error=implicit-function-declaration";
3834
3935 nativeBuildInputs = [ patchelf makeWrapper ];
40− buildInputs = [ cdrkit dbus ] ++ kernel.moduleBuildDependencies;
36+ buildInputs = [ cdrkit ] ++ kernel.moduleBuildDependencies;
4137
42− installPhase = ''
43− mkdir -p $out
44− cp -r install/* $out
45− '';
46−
47− buildCommand = with xorg; ''
38+ unpackPhase = ''
4839 ${if stdenv.hostPlatform.system == "i686-linux" || stdenv.hostPlatform.system == "x86_64-linux" then ''
4940 isoinfo -J -i $src -x /VBoxLinuxAdditions.run > ./VBoxLinuxAdditions.run
5041 chmod 755 ./VBoxLinuxAdditions.run
@@ -63,39 +54,30 @@ stdenv.mkDerivation {
6354 ''
6455 else throw ("Architecture: "+stdenv.hostPlatform.system+" not supported for VirtualBox guest additions")
6556 }
57+ '';
6658
67− cd ../
68− patchPhase
69− cd install/src
70−
71− # Build kernel modules
72− export INSTALL_MOD_PATH=$out
59+ doConfigure = false;
7360
61+ buildPhase = ''
62+ # Build kernel modules.
63+ cd src
7464 find . -type f | xargs sed 's/depmod -a/true/' -i
75−
7665 cd vboxguest-${version}
77−
66+ # Run just make first. If we only did make install, we get symbol warnings during build.
7867 make
79−
8068 cd ../..
8169
8270 # Change the interpreter for various binaries
83− for i in sbin/VBoxService bin/{VBoxClient,VBoxControl} other/mount.vboxsf
84− do
85− ${if stdenv.hostPlatform.system == "i686-linux" then ''
86− patchelf --set-interpreter ${stdenv.glibc.out}/lib/ld-linux.so.2 $i
87− ''
88− else if stdenv.hostPlatform.system == "x86_64-linux" then ''
89− patchelf --set-interpreter ${stdenv.glibc.out}/lib/ld-linux-x86-64.so.2 $i
90− ''
91− else throw ("Architecture: "+stdenv.hostPlatform.system+" not supported for VirtualBox guest additions")
92− }
93− patchelf --set-rpath ${lib.makeLibraryPath [ stdenv.cc.cc dbus libX11 libXt libXext libXmu libXfixes libXrandr libXcursor ]} $i
71+ for i in sbin/VBoxService bin/{VBoxClient,VBoxControl} other/mount.vboxsf; do
72+ patchelf --set-interpreter ${stdenv.cc.bintools.dynamicLinker} $i
73+ patchelf --set-rpath ${lib.makeLibraryPath [ stdenv.cc.cc stdenv.cc.libc zlib
74+ xorg.libX11 xorg.libXt xorg.libXext xorg.libXmu xorg.libXfixes xorg.libXrandr xorg.libXcursor ]} $i
9475 done
9576
9677 for i in lib/VBoxOGL*.so
9778 do
98− patchelf --set-rpath ${lib.makeLibraryPath [ "$out" dbus libXcomposite libXdamage libXext libXfixes ]} $i
79+ patchelf --set-rpath ${lib.makeLibraryPath [ "$out"
80+ xorg.libXcomposite xorg.libXdamage xorg.libXext xorg.libXfixes ]} $i
9981 done
10082
10183 # FIXME: Virtualbox 4.3.22 moved VBoxClient-all (required by Guest Additions
@@ -105,6 +87,13 @@ stdenv.mkDerivation {
10587 # Remove references to /usr from various scripts and files
10688 sed -i -e "s|/usr/bin|$out/bin|" other/vboxclient.desktop
10789 sed -i -e "s|/usr/bin|$out/bin|" bin/VBoxClient-all
90+ '';
91+
92+ installPhase = ''
93+ # Install kernel modules.
94+ cd src/vboxguest-${version}
95+ make install INSTALL_MOD_PATH=$out
96+ cd ../..
10897
10998 # Install binaries
11099 install -D -m 755 other/mount.vboxsf $out/bin/mount.vboxsf
@@ -131,21 +120,18 @@ stdenv.mkDerivation {
131120 # Install Xorg drivers
132121 mkdir -p $out/lib/xorg/modules/{drivers,input}
133122 install -m 644 other/vboxvideo_drv_${xserverABI}.so $out/lib/xorg/modules/drivers/vboxvideo_drv.so
123+ '';
134124
135− # Install kernel modules
136− cd src
125+ # Stripping breaks these binaries for some reason.
126+ dontStrip = true;
137127
138− for i in *
139− do
140− cd $i
141− kernelVersion=$(cd ${kernel.dev}/lib/modules; ls)
142− export MODULE_DIR=$out/lib/modules/$kernelVersion/misc
143− find . -type f | xargs sed -i -e "s|-o root||g" \
144− -e "s|-g root||g"
145− make install
146− cd ..
128+ # Some code dlopen() libdbus, patch RUNPATH in fixupPhase so it isn't stripped.
129+ postFixup = ''
130+ for i in $(grep -F libdbus-1.so -l -r $out/{lib,bin}); do
131+ origRpath=$(patchelf --print-rpath "$i")
132+ patchelf --set-rpath "$origRpath:${lib.makeLibraryPath [ dbus ]}" "$i"
147133 done
148− ''; # */
134+ '';
149135
150136 meta = {
151137 description = "Guest additions for VirtualBox";