at 18.03-beta 214 lines 8.1 kB view raw
1{ stdenv, fetchurl, lib, iasl, dev86, pam, libxslt, libxml2, libX11, xproto, libXext 2, libXcursor, libXmu, qt5, libIDL, SDL, libcap, zlib, libpng, glib, lvm2 3, libXrandr, libXinerama 4, pkgconfig, which, docbook_xsl, docbook_xml_dtd_43 5, alsaLib, curl, libvpx, gawk, nettools, dbus 6, xorriso, makeself, perl 7, javaBindings ? false, jdk ? null 8, pythonBindings ? false, python2 ? null 9, enableExtensionPack ? false, requireFile ? null, patchelf ? null, fakeroot ? null 10, pulseSupport ? false, libpulseaudio ? null 11, enableHardening ? false 12, headless ? false 13, enable32bitGuests ? true 14, patchelfUnstable # needed until 0.10 is released 15}: 16 17with stdenv.lib; 18 19let 20 python = python2; 21 buildType = "release"; 22 # Manually sha256sum the extensionPack file, must be hex! 23 # Do not forget to update the hash in ./guest-additions/default.nix! 24 extpack = "70584a70b666e9332ae2c6be0e64da4b8e3a27124801156577f205750bdde4f5"; 25 extpackRev = "120293"; 26 main = "1rx45ivwk89ghjc5zdd7c7j92w0w3930xj7l1zhwrvshxs454w7y"; 27 version = "5.2.6"; 28 29 # See https://github.com/NixOS/nixpkgs/issues/672 for details 30 extensionPack = requireFile rec { 31 name = "Oracle_VM_VirtualBox_Extension_Pack-${version}-${toString extpackRev}.vbox-extpack"; 32 sha256 = extpack; 33 message = '' 34 In order to use the extension pack, you need to comply with the VirtualBox Personal Use 35 and Evaluation License (PUEL) available at: 36 37 https://www.virtualbox.org/wiki/VirtualBox_PUEL 38 39 Once you have read and if you agree with the license, please use the 40 following command and re-run the installation: 41 42 nix-prefetch-url http://download.virtualbox.org/virtualbox/${version}/${name} 43 ''; 44 }; 45 46in stdenv.mkDerivation { 47 name = "virtualbox-${version}"; 48 49 src = fetchurl { 50 url = "http://download.virtualbox.org/virtualbox/${version}/VirtualBox-${version}.tar.bz2"; 51 sha256 = main; 52 }; 53 54 outputs = [ "out" "modsrc" ]; 55 56 nativeBuildInputs = [ pkgconfig which docbook_xsl docbook_xml_dtd_43 ]; 57 58 buildInputs = 59 [ iasl dev86 libxslt libxml2 xproto libX11 libXext libXcursor libIDL 60 libcap glib lvm2 alsaLib curl libvpx pam xorriso makeself perl 61 libXmu libpng patchelfUnstable python ] 62 ++ optional javaBindings jdk 63 ++ optional pythonBindings python # Python is needed even when not building bindings 64 ++ optional pulseSupport libpulseaudio 65 ++ optionals (headless) [ libXrandr ] 66 ++ optionals (!headless) [ qt5.qtbase qt5.qtx11extras libXinerama SDL ]; 67 68 hardeningDisable = [ "fortify" "pic" "stackprotector" ]; 69 70 prePatch = '' 71 set -x 72 sed -e 's@MKISOFS --version@MKISOFS -version@' \ 73 -e 's@PYTHONDIR=.*@PYTHONDIR=${if pythonBindings then python else ""}@' \ 74 -e 's@CXX_FLAGS="\(.*\)"@CXX_FLAGS="-std=c++11 \1"@' \ 75 ${optionalString (!headless) '' 76 -e 's@TOOLQT5BIN=.*@TOOLQT5BIN="${getDev qt5.qtbase}/bin"@' \ 77 ''} -i configure 78 ls kBuild/bin/linux.x86/k* tools/linux.x86/bin/* | xargs -n 1 patchelf --set-interpreter ${stdenv.glibc.out}/lib/ld-linux.so.2 79 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 80 81 grep 'libpulse\.so\.0' src include -rI --files-with-match | xargs sed -i -e ' 82 ${optionalString pulseSupport 83 ''s@"libpulse\.so\.0"@"${libpulseaudio.out}/lib/libpulse.so.0"@g''}' 84 85 grep 'libdbus-1\.so\.3' src include -rI --files-with-match | xargs sed -i -e ' 86 s@"libdbus-1\.so\.3"@"${dbus.lib}/lib/libdbus-1.so.3"@g' 87 88 grep 'libasound\.so\.2' src include -rI --files-with-match | xargs sed -i -e ' 89 s@"libasound\.so\.2"@"${alsaLib.out}/lib/libasound.so.2"@g' 90 91 export USER=nix 92 set +x 93 ''; 94 95 patches = 96 optional enableHardening ./hardened.patch 97 # https://www.virtualbox.org/pipermail/vbox-dev/2017-December/014888.html 98 ++ optional headless [ ./HostServices-SharedClipboard-x11-stub.cpp-use-RT_NOR.patch ] 99 ++ [ ./qtx11extras.patch ]; 100 101 102 103 postPatch = '' 104 sed -i -e 's|/sbin/ifconfig|${nettools}/bin/ifconfig|' \ 105 src/VBox/HostDrivers/adpctl/VBoxNetAdpCtl.cpp 106 ''; 107 108 # first line: ugly hack, and it isn't yet clear why it's a problem 109 configurePhase = '' 110 NIX_CFLAGS_COMPILE=$(echo "$NIX_CFLAGS_COMPILE" | sed 's,\-isystem ${lib.getDev stdenv.cc.libc}/include,,g') 111 112 cat >> LocalConfig.kmk <<LOCAL_CONFIG 113 VBOX_WITH_TESTCASES := 114 VBOX_WITH_TESTSUITE := 115 VBOX_WITH_VALIDATIONKIT := 116 VBOX_WITH_DOCS := 117 VBOX_WITH_WARNINGS_AS_ERRORS := 118 119 VBOX_WITH_ORIGIN := 120 VBOX_PATH_APP_PRIVATE_ARCH_TOP := $out/share/virtualbox 121 VBOX_PATH_APP_PRIVATE_ARCH := $out/libexec/virtualbox 122 VBOX_PATH_SHARED_LIBS := $out/libexec/virtualbox 123 VBOX_WITH_RUNPATH := $out/libexec/virtualbox 124 VBOX_PATH_APP_PRIVATE := $out/share/virtualbox 125 VBOX_PATH_APP_DOCS := $out/doc 126 ${optionalString javaBindings '' 127 VBOX_JAVA_HOME := ${jdk} 128 ''} 129 ${optionalString (!headless) '' 130 PATH_QT5_X11_EXTRAS_LIB := ${getLib qt5.qtx11extras}/lib 131 PATH_QT5_X11_EXTRAS_INC := ${getDev qt5.qtx11extras}/include 132 TOOL_QT5_LRC := ${getDev qt5.qttools}/bin/lrelease 133 ''} 134 LOCAL_CONFIG 135 136 ./configure \ 137 ${optionalString headless "--build-headless"} \ 138 ${optionalString (!javaBindings) "--disable-java"} \ 139 ${optionalString (!pythonBindings) "--disable-python"} \ 140 ${optionalString (!pulseSupport) "--disable-pulse"} \ 141 ${optionalString (!enableHardening) "--disable-hardening"} \ 142 ${optionalString (!enable32bitGuests) "--disable-vmmraw"} \ 143 --disable-kmods --with-mkisofs=${xorriso}/bin/xorrisofs 144 sed -e 's@PKG_CONFIG_PATH=.*@PKG_CONFIG_PATH=${libIDL}/lib/pkgconfig:${glib.dev}/lib/pkgconfig ${libIDL}/bin/libIDL-config-2@' \ 145 -i AutoConfig.kmk 146 sed -e 's@arch/x86/@@' \ 147 -i Config.kmk 148 substituteInPlace Config.kmk --replace "VBOX_WITH_TESTCASES = 1" "#" 149 ''; 150 151 enableParallelBuilding = true; 152 153 buildPhase = '' 154 source env.sh 155 kmk -j $NIX_BUILD_CORES BUILD_TYPE="${buildType}" 156 ''; 157 158 installPhase = '' 159 libexec="$out/libexec/virtualbox" 160 share="${if enableHardening then "$out/share/virtualbox" else "$libexec"}" 161 162 # Install VirtualBox files 163 mkdir -p "$libexec" 164 find out/linux.*/${buildType}/bin -mindepth 1 -maxdepth 1 \ 165 -name src -o -exec cp -avt "$libexec" {} + 166 167 mkdir -p $out/bin 168 for file in ${optionalString (!headless) "VirtualBox VBoxSDL rdesktop-vrdp"} VBoxManage VBoxBalloonCtrl VBoxHeadless; do 169 echo "Linking $file to /bin" 170 test -x "$libexec/$file" 171 ln -s "$libexec/$file" $out/bin/$file 172 done 173 174 ${optionalString enableExtensionPack '' 175 mkdir -p "$share" 176 "${fakeroot}/bin/fakeroot" "${stdenv.shell}" <<EXTHELPER 177 "$libexec/VBoxExtPackHelperApp" install \ 178 --base-dir "$share/ExtensionPacks" \ 179 --cert-dir "$share/ExtPackCertificates" \ 180 --name "Oracle VM VirtualBox Extension Pack" \ 181 --tarball "${extensionPack}" \ 182 --sha-256 "${extensionPack.outputHash}" 183 EXTHELPER 184 ''} 185 186 ${optionalString (!headless) '' 187 # Create and fix desktop item 188 mkdir -p $out/share/applications 189 sed -i -e "s|Icon=VBox|Icon=$libexec/VBox.png|" $libexec/virtualbox.desktop 190 ln -sfv $libexec/virtualbox.desktop $out/share/applications 191 # Icons 192 mkdir -p $out/share/icons/hicolor 193 for size in `ls -1 $libexec/icons`; do 194 mkdir -p $out/share/icons/hicolor/$size/apps 195 ln -s $libexec/icons/$size/*.png $out/share/icons/hicolor/$size/apps 196 done 197 ''} 198 199 cp -rv out/linux.*/${buildType}/bin/src "$modsrc" 200 ''; 201 202 passthru = { 203 inherit version; # for guest additions 204 inherit extensionPack; # for inclusion in profile to prevent gc 205 }; 206 207 meta = { 208 description = "PC emulator"; 209 license = licenses.gpl2; 210 homepage = https://www.virtualbox.org/; 211 maintainers = with maintainers; [ flokli sander ]; 212 platforms = [ "x86_64-linux" "i686-linux" ]; 213 }; 214}