at 15.09-beta 198 lines 7.4 kB view raw
1{ stdenv, fetchurl, lib, iasl, dev86, pam, libxslt, libxml2, libX11, xproto, libXext 2, libXcursor, libXmu, qt4, libIDL, SDL, libcap, zlib, libpng, glib, kernel, lvm2 3, which, alsaLib, curl, libvpx, gawk, nettools 4, xorriso, makeself, perl, pkgconfig, nukeReferences 5, javaBindings ? false, jdk ? null 6, pythonBindings ? false, python ? null 7, enableExtensionPack ? false, requireFile ? null, patchelf ? null, fakeroot ? null 8, pulseSupport ? false, libpulseaudio ? null 9, enableHardening ? false 10}: 11 12with stdenv.lib; 13 14let 15 buildType = "release"; 16 17 version = "5.0.0"; # changes ./guest-additions as well 18 19 forEachModule = action: '' 20 for mod in \ 21 out/linux.*/${buildType}/bin/src/vboxdrv \ 22 out/linux.*/${buildType}/bin/src/vboxpci \ 23 out/linux.*/${buildType}/bin/src/vboxnetadp \ 24 out/linux.*/${buildType}/bin/src/vboxnetflt 25 do 26 if [ "x$(basename "$mod")" != xvboxdrv -a ! -e "$mod/Module.symvers" ] 27 then 28 cp -v out/linux.*/${buildType}/bin/src/vboxdrv/Module.symvers \ 29 "$mod/Module.symvers" 30 fi 31 INSTALL_MOD_PATH="$out" INSTALL_MOD_DIR=misc \ 32 make -C "$MODULES_BUILD_DIR" DEPMOD=/do_not_use_depmod \ 33 "M=\$(PWD)/$mod" BUILD_TYPE="${buildType}" ${action} 34 done 35 ''; 36 37 # See https://github.com/NixOS/nixpkgs/issues/672 for details 38 extpackRevision = "101573"; 39 extensionPack = requireFile rec { 40 name = "Oracle_VM_VirtualBox_Extension_Pack-${version}-${extpackRevision}.vbox-extpack"; 41 # IMPORTANT: Hash must be base16 encoded because it's used as an input to 42 # VBoxExtPackHelperApp! 43 # Tip: see http://dlc.sun.com.edgesuite.net/virtualbox/4.3.10/SHA256SUMS 44 sha256 = "c357e36368883df821ed092d261890a95c75e50422b75848c40ad20984086a7a"; 45 message = '' 46 In order to use the extension pack, you need to comply with the VirtualBox Personal Use 47 and Evaluation License (PUEL) by downloading the related binaries from: 48 49 https://www.virtualbox.org/wiki/Downloads 50 51 Once you have downloaded the file, please use the following command and re-run the 52 installation: 53 54 nix-prefetch-url file://${name} 55 ''; 56 }; 57 58in stdenv.mkDerivation { 59 name = "virtualbox-${version}-${kernel.version}"; 60 61 src = fetchurl { 62 url = "http://download.virtualbox.org/virtualbox/${version}/VirtualBox-${version}.tar.bz2"; 63 sha256 = "bb71356c8f82012c9b5ae16e12302eb111c71ae7b063ada7688fbfa8aa10c2f7"; 64 }; 65 66 buildInputs = 67 [ iasl dev86 libxslt libxml2 xproto libX11 libXext libXcursor qt4 libIDL SDL 68 libcap glib lvm2 python alsaLib curl libvpx pam xorriso makeself perl 69 pkgconfig which libXmu nukeReferences ] 70 ++ optional javaBindings jdk 71 ++ optional pythonBindings python 72 ++ optional pulseSupport libpulseaudio; 73 74 prePatch = '' 75 set -x 76 MODULES_BUILD_DIR=`echo ${kernel.dev}/lib/modules/*/build` 77 sed -e 's@/lib/modules/`uname -r`/build@'$MODULES_BUILD_DIR@ \ 78 -e 's@MKISOFS --version@MKISOFS -version@' \ 79 -e 's@PYTHONDIR=.*@PYTHONDIR=${if pythonBindings then python else ""}@' \ 80 -i configure 81 ls kBuild/bin/linux.x86/k* tools/linux.x86/bin/* | xargs -n 1 patchelf --set-interpreter ${stdenv.glibc}/lib/ld-linux.so.2 82 ls kBuild/bin/linux.amd64/k* tools/linux.amd64/bin/* | xargs -n 1 patchelf --set-interpreter ${stdenv.glibc}/lib/ld-linux-x86-64.so.2 83 find . -type f -iname '*makefile*' -exec sed -i -e 's/depmod -a/:/g' {} + 84 sed -i -e ' 85 s@"libasound.so.2"@"${alsaLib}/lib/libasound.so.2"@g 86 ${optionalString pulseSupport '' 87 s@"libpulse.so.0"@"${libpulseaudio}/lib/libpulse.so.0"@g 88 ''} 89 ' src/VBox/Main/xml/Settings.cpp src/VBox/Devices/Audio/{alsa,pulse}_stubs.c 90 export USER=nix 91 set +x 92 ''; 93 94 patches = optional enableHardening ./hardened.patch; 95 96 postPatch = '' 97 sed -i -e 's|/sbin/ifconfig|${nettools}/bin/ifconfig|' \ 98 src/apps/adpctl/VBoxNetAdpCtl.cpp 99 ''; 100 101 # first line: ugly hack, and it isn't yet clear why it's a problem 102 configurePhase = '' 103 NIX_CFLAGS_COMPILE=$(echo "$NIX_CFLAGS_COMPILE" | sed 's,\-isystem ${stdenv.cc.libc}/include,,g') 104 105 cat >> LocalConfig.kmk <<LOCAL_CONFIG 106 VBOX_WITH_TESTCASES := 107 VBOX_WITH_TESTSUITE := 108 VBOX_WITH_VALIDATIONKIT := 109 VBOX_WITH_DOCS := 110 VBOX_WITH_WARNINGS_AS_ERRORS := 111 112 VBOX_WITH_ORIGIN := 113 VBOX_PATH_APP_PRIVATE_ARCH_TOP := $out/share/virtualbox 114 VBOX_PATH_APP_PRIVATE_ARCH := $out/libexec/virtualbox 115 VBOX_PATH_SHARED_LIBS := $out/libexec/virtualbox 116 VBOX_WITH_RUNPATH := $out/libexec/virtualbox 117 VBOX_PATH_APP_PRIVATE := $out/share/virtualbox 118 VBOX_PATH_APP_DOCS := $out/doc 119 ${optionalString javaBindings '' 120 VBOX_JAVA_HOME := ${jdk} 121 ''} 122 LOCAL_CONFIG 123 124 ./configure --with-qt4-dir=${qt4} \ 125 ${optionalString (!javaBindings) "--disable-java"} \ 126 ${optionalString (!pythonBindings) "--disable-python"} \ 127 ${optionalString (!pulseSupport) "--disable-pulse"} \ 128 ${optionalString (!enableHardening) "--disable-hardening"} \ 129 --disable-kmods --with-mkisofs=${xorriso}/bin/xorrisofs 130 sed -e 's@PKG_CONFIG_PATH=.*@PKG_CONFIG_PATH=${libIDL}/lib/pkgconfig:${glib}/lib/pkgconfig ${libIDL}/bin/libIDL-config-2@' \ 131 -i AutoConfig.kmk 132 sed -e 's@arch/x86/@@' \ 133 -i Config.kmk 134 substituteInPlace Config.kmk --replace "VBOX_WITH_TESTCASES = 1" "#" 135 ''; 136 137 enableParallelBuilding = true; 138 139 buildPhase = '' 140 source env.sh 141 kmk BUILD_TYPE="${buildType}" 142 ${forEachModule "modules"} 143 ''; 144 145 installPhase = '' 146 libexec="$out/libexec/virtualbox" 147 share="${if enableHardening then "$out/share/virtualbox" else "$libexec"}" 148 149 # Install VirtualBox files 150 mkdir -p "$libexec" 151 find out/linux.*/${buildType}/bin -mindepth 1 -maxdepth 1 \ 152 -name src -o -exec cp -avt "$libexec" {} + 153 154 # Install kernel modules 155 ${forEachModule "modules_install"} 156 157 # Create wrapper script 158 mkdir -p $out/bin 159 for file in VirtualBox VBoxManage VBoxSDL VBoxBalloonCtrl VBoxBFE VBoxHeadless; do 160 ln -s "$libexec/$file" $out/bin/$file 161 done 162 163 ${optionalString enableExtensionPack '' 164 mkdir -p "$share" 165 "${fakeroot}/bin/fakeroot" "${stdenv.shell}" <<EXTHELPER 166 "$libexec/VBoxExtPackHelperApp" install \ 167 --base-dir "$share/ExtensionPacks" \ 168 --cert-dir "$share/ExtPackCertificates" \ 169 --name "Oracle VM VirtualBox Extension Pack" \ 170 --tarball "${extensionPack}" \ 171 --sha-256 "${extensionPack.outputHash}" 172 EXTHELPER 173 ''} 174 175 # Create and fix desktop item 176 mkdir -p $out/share/applications 177 sed -i -e "s|Icon=VBox|Icon=$libexec/VBox.png|" $libexec/virtualbox.desktop 178 ln -sfv $libexec/virtualbox.desktop $out/share/applications 179 # Icons 180 mkdir -p $out/share/icons/hicolor 181 for size in `ls -1 $libexec/icons`; do 182 mkdir -p $out/share/icons/hicolor/$size/apps 183 ln -s $libexec/icons/$size/*.png $out/share/icons/hicolor/$size/apps 184 done 185 186 # Get rid of a reference to linux.dev. 187 nuke-refs $out/lib/modules/*/misc/*.ko 188 ''; 189 190 passthru = { inherit version; /* for guest additions */ }; 191 192 meta = { 193 description = "PC emulator"; 194 homepage = http://www.virtualbox.org/; 195 maintainers = [ lib.maintainers.sander ]; 196 platforms = lib.platforms.linux; 197 }; 198}