From 294281596833b8d83ba90c03b792d31b868f46d7 Mon Sep 17 00:00:00 2001 From: Christian Albrecht Date: Sat, 10 Sep 2016 11:40:06 +0200 Subject: [PATCH 01/12] virtualbox: 5.0.26 -> 5.1.4 --- .../virtualization/virtualbox/default.nix | 32 ++++++++----- .../virtualbox/guest-additions/default.nix | 2 +- .../virtualization/virtualbox/libressl.patch | 47 +++++++++++++++++++ 3 files changed, 67 insertions(+), 14 deletions(-) create mode 100644 pkgs/applications/virtualization/virtualbox/libressl.patch diff --git a/pkgs/applications/virtualization/virtualbox/default.nix b/pkgs/applications/virtualization/virtualbox/default.nix index 8bcf122132e..161e3ab35bd 100644 --- a/pkgs/applications/virtualization/virtualbox/default.nix +++ b/pkgs/applications/virtualization/virtualbox/default.nix @@ -1,6 +1,6 @@ -{ stdenv, fetchurl, lib, iasl, dev86, pam, libxslt, libxml2, libX11, xproto, libXext -, libXcursor, libXmu, qt4, libIDL, SDL, libcap, zlib, libpng, glib, kernel, lvm2 -, libXrandr +{ stdenv, buildEnv, fetchurl, lib, iasl, dev86, pam, libxslt, libxml2, libX11, xproto, libXext +, libXcursor, libXmu, qt5, libIDL, SDL, libcap, zlib, libpng, glib, kernel, lvm2 +, libXrandr, libXinerama , which, alsaLib, curl, libvpx, gawk, nettools, dbus , xorriso, makeself, perl, pkgconfig, nukeReferences , javaBindings ? false, jdk ? null @@ -20,7 +20,7 @@ let # revision/hash as well. See # http://download.virtualbox.org/virtualbox/${version}/SHA256SUMS # for hashes. - version = "5.0.26"; + version = "5.1.4"; forEachModule = action: '' for mod in \ @@ -41,12 +41,12 @@ let ''; # See https://github.com/NixOS/nixpkgs/issues/672 for details - extpackRevision = "108824"; + extpackRevision = "110228"; extensionPack = requireFile rec { name = "Oracle_VM_VirtualBox_Extension_Pack-${version}-${extpackRevision}.vbox-extpack"; # IMPORTANT: Hash must be base16 encoded because it's used as an input to # VBoxExtPackHelperApp! - sha256 = "2f2302c7ba3d00a1258fe8e7767a6eb08dccdc3c31f6e3eeb74063c2c268b104"; + sha256 = "9462ff1b567c37ad9a33c0c7ca1925776615ec89b5a72563f29a8cc8514cf316"; message = '' In order to use the extension pack, you need to comply with the VirtualBox Personal Use and Evaluation License (PUEL) available at: @@ -60,23 +60,28 @@ let ''; }; + vbox-qt5-env = buildEnv { + name = "vbox-qt5-env-${version}"; + paths = [ qt5.qtbase.dev qt5.qtbase.out qt5.qtx11extras.dev qt5.qtx11extras.out qt5.qttools.dev ]; + }; + in stdenv.mkDerivation { name = "virtualbox-${version}-${kernel.version}"; src = fetchurl { url = "http://download.virtualbox.org/virtualbox/${version}/VirtualBox-${version}.tar.bz2"; - sha256 = "78dec1369d2c8feefea3c682d95e76c0e99414c56626388035cf4061d4dad62e"; + sha256 = "b9a14a7771059c55c44b97f8d4eef9bea84544f3e215e0caa563bc35e2f16aaf"; }; buildInputs = [ iasl dev86 libxslt libxml2 xproto libX11 libXext libXcursor libIDL libcap glib lvm2 python alsaLib curl libvpx pam xorriso makeself perl - pkgconfig which libXmu nukeReferences ] + pkgconfig which libXmu nukeReferences libpng ] ++ optional javaBindings jdk ++ optional pythonBindings python ++ optional pulseSupport libpulseaudio - ++ optionals (headless) [ libXrandr libpng ] - ++ optionals (!headless) [ qt4 SDL ]; + ++ optionals (headless) [ libXrandr ] + ++ optionals (!headless) [ vbox-qt5-env libXinerama SDL ]; hardeningDisable = [ "fortify" "pic" "stackprotector" ]; @@ -103,11 +108,12 @@ in stdenv.mkDerivation { set +x ''; - patches = optional enableHardening ./hardened.patch; + patches = optional enableHardening ./hardened.patch + ++ [ ./libressl.patch ]; postPatch = '' sed -i -e 's|/sbin/ifconfig|${nettools}/bin/ifconfig|' \ - src/apps/adpctl/VBoxNetAdpCtl.cpp + src/VBox/HostDrivers/adpctl/VBoxNetAdpCtl.cpp ''; # first line: ugly hack, and it isn't yet clear why it's a problem @@ -135,7 +141,7 @@ in stdenv.mkDerivation { ./configure \ ${optionalString headless "--build-headless"} \ - ${optionalString (!headless) "--with-qt4-dir=${qt4}"} \ + ${optionalString (!headless) "--with-qt-dir=${vbox-qt5-env}"} \ ${optionalString (!javaBindings) "--disable-java"} \ ${optionalString (!pythonBindings) "--disable-python"} \ ${optionalString (!pulseSupport) "--disable-pulse"} \ diff --git a/pkgs/applications/virtualization/virtualbox/guest-additions/default.nix b/pkgs/applications/virtualization/virtualbox/guest-additions/default.nix index 56e02519792..0a6293462b8 100644 --- a/pkgs/applications/virtualization/virtualbox/guest-additions/default.nix +++ b/pkgs/applications/virtualization/virtualbox/guest-additions/default.nix @@ -12,7 +12,7 @@ stdenv.mkDerivation { src = fetchurl { url = "http://download.virtualbox.org/virtualbox/${version}/VBoxGuestAdditions_${version}.iso"; - sha256 = "7458ee5a7121a7d243fd6a7528ba427945d9120c5efc7cd75b3951fb01f09c59"; + sha256 = "e385b698338003595f6cdeee7b631ec6713058ba1227d1f2a1da342bdf741982"; }; KERN_DIR = "${kernel.dev}/lib/modules/*/build"; diff --git a/pkgs/applications/virtualization/virtualbox/libressl.patch b/pkgs/applications/virtualization/virtualbox/libressl.patch new file mode 100644 index 00000000000..db9b7e7a59d --- /dev/null +++ b/pkgs/applications/virtualization/virtualbox/libressl.patch @@ -0,0 +1,47 @@ +diff --git a/src/VBox/Runtime/common/crypto/digest-builtin.cpp b/src/VBox/Runtime/common/crypto/digest-builtin.cpp +index 66b4304..1aaceff 100644 +--- a/src/VBox/Runtime/common/crypto/digest-builtin.cpp ++++ b/src/VBox/Runtime/common/crypto/digest-builtin.cpp +@@ -561,7 +561,7 @@ static PCRTCRDIGESTDESC const g_apDigestOps[] = + * OpenSSL EVP. + */ + +-# if OPENSSL_VERSION_NUMBER >= 0x10100000 ++# if OPENSSL_VERSION_NUMBER >= 0x10100000 && !defined(LIBRESSL_VERSION_NUMBER) + /** @impl_interface_method{RTCRDIGESTDESC::pfnNew} */ + static DECLCALLBACK(void*) rtCrDigestOsslEvp_New(void) + { +@@ -597,7 +597,7 @@ static DECLCALLBACK(int) rtCrDigestOsslEvp_Init(void *pvState, void *pvOpaque, b + if (fReInit) + { + pEvpType = EVP_MD_CTX_md(pThis); +-# if OPENSSL_VERSION_NUMBER >= 0x10100000 ++# if OPENSSL_VERSION_NUMBER >= 0x10100000 && !defined(LIBRESSL_VERSION_NUMBER) + EVP_MD_CTX_reset(pThis); + # else + EVP_MD_CTX_cleanup(pThis); +@@ -616,7 +616,7 @@ static DECLCALLBACK(int) rtCrDigestOsslEvp_Init(void *pvState, void *pvOpaque, b + static DECLCALLBACK(void) rtCrDigestOsslEvp_Delete(void *pvState) + { + EVP_MD_CTX *pThis = (EVP_MD_CTX *)pvState; +-# if OPENSSL_VERSION_NUMBER >= 0x10100000 ++# if OPENSSL_VERSION_NUMBER >= 0x10100000 && !defined(LIBRESSL_VERSION_NUMBER) + EVP_MD_CTX_reset(pThis); + # else + EVP_MD_CTX_cleanup(pThis); +@@ -661,13 +661,13 @@ static RTCRDIGESTDESC const g_rtCrDigestOpenSslDesc = + NULL, + RTDIGESTTYPE_UNKNOWN, + EVP_MAX_MD_SIZE, +-# if OPENSSL_VERSION_NUMBER >= 0x10100000 ++# if OPENSSL_VERSION_NUMBER >= 0x10100000 && !defined(LIBRESSL_VERSION_NUMBER) + 0, + # else + sizeof(EVP_MD_CTX), + # endif + 0, +-# if OPENSSL_VERSION_NUMBER >= 0x10100000 ++# if OPENSSL_VERSION_NUMBER >= 0x10100000 && !defined(LIBRESSL_VERSION_NUMBER) + rtCrDigestOsslEvp_New, + rtCrDigestOsslEvp_Free, + # else From f5ab9c81a8b00ee1f96f85b0b22a549305cf10a2 Mon Sep 17 00:00:00 2001 From: aszlig Date: Tue, 13 Sep 2016 03:24:47 +0200 Subject: [PATCH 02/12] virtualbox: Add an update script Just a small updater which should fetch the latest sha256sums from the upstream site and check whether the current version is the latest one. The output is in a JSON file in the same directory, which then will be used by the Nix expressions to fetch the upstream files. Signed-off-by: aszlig --- .../virtualization/virtualbox/update.py | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100755 pkgs/applications/virtualization/virtualbox/update.py diff --git a/pkgs/applications/virtualization/virtualbox/update.py b/pkgs/applications/virtualization/virtualbox/update.py new file mode 100755 index 00000000000..ff1b2e2fffb --- /dev/null +++ b/pkgs/applications/virtualization/virtualbox/update.py @@ -0,0 +1,83 @@ +#!/usr/bin/env python3 +import os +import re +import json +import urllib.request + +from distutils.version import LooseVersion + +UPSTREAM_INFO_FILE = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "upstream-info.json" +) + + +def fetch_latest_version(): + url = "http://download.virtualbox.org/virtualbox/LATEST.TXT" + return urllib.request.urlopen(url).read().strip().decode() + + +def load_upstream_info(): + try: + with open(UPSTREAM_INFO_FILE, 'r') as fp: + return json.load(fp) + except FileNotFoundError: + return {'version': "0"} + + +def save_upstream_info(contents): + remark = "Generated using update.py from the same directory." + contents['__NOTE'] = remark + data = json.dumps(contents, indent=2, sort_keys=True) + with open(UPSTREAM_INFO_FILE, 'w') as fp: + fp.write(data + "\n") + + +def fetch_file_table(version): + url = "http://download.virtualbox.org/virtualbox/{}/SHA256SUMS" + url = url.format(version) + result = {} + for line in urllib.request.urlopen(url): + sha, name = line.rstrip().split() + result[name.lstrip(b'*').decode()] = sha.decode() + return result + + +def update_to_version(version): + extpack_start = 'Oracle_VM_VirtualBox_Extension_Pack-' + version_re = version.replace('.', '\\.') + attribute_map = { + 'extpack': r'^' + extpack_start + r'[^-]+-[^.]+.vbox-extpack$', + 'extpackRev': r'^' + extpack_start + r'[^-]+-([^.]+).vbox-extpack$', + 'main': r'^VirtualBox-' + version_re + r'.tar.bz2$', + 'guest': r'^VBoxGuestAdditions_' + version_re + r'.iso$', + } + table = fetch_file_table(version) + new_attrs = {'version': version} + for attr, searchexpr in attribute_map.items(): + result = [re.search(searchexpr, key) for key in table.keys()] + filtered = filter(lambda m: m is not None, result) + found = [m.groups()[0] if len(m.groups()) > 0 else table[m.group(0)] + for m in filtered if m is not None] + + if len(found) == 0: + msg = "No package found for attribute {}".format(attr) + raise AssertionError(msg) + elif len(found) != 1: + msg = "More than one package found for attribute {}: ".format(attr) + msg += ', '.join(found) + raise AssertionError(msg) + else: + new_attrs[attr] = found[0] + return new_attrs + + +info = load_upstream_info() +latest = fetch_latest_version() +if LooseVersion(info['version']) < LooseVersion(latest): + print("Updating to version {}...".format(latest), end="", flush=True) + new_attrs = update_to_version(latest) + save_upstream_info(new_attrs) + print(" done.") +else: + print("Version {} is already the latest one.".format(info['version'])) From 6d69293f26ff57a2621b299409af814ba7226413 Mon Sep 17 00:00:00 2001 From: aszlig Date: Tue, 13 Sep 2016 03:48:14 +0200 Subject: [PATCH 03/12] virtualbox: Generate and use upstream-info.json We now no longer need to update VirtualBox manually, which has a few advantages. Along with making it just easier to update this also makes the update procedure way less error-prone, for example if people forget to bump the extension pack revision or to update the guest additions. Signed-off-by: aszlig --- .../virtualization/virtualbox/default.nix | 15 ++++----------- .../virtualbox/guest-additions/default.nix | 2 +- .../virtualization/virtualbox/upstream-info.json | 8 ++++++++ 3 files changed, 13 insertions(+), 12 deletions(-) create mode 100644 pkgs/applications/virtualization/virtualbox/upstream-info.json diff --git a/pkgs/applications/virtualization/virtualbox/default.nix b/pkgs/applications/virtualization/virtualbox/default.nix index 161e3ab35bd..3a75479b2cf 100644 --- a/pkgs/applications/virtualization/virtualbox/default.nix +++ b/pkgs/applications/virtualization/virtualbox/default.nix @@ -16,11 +16,7 @@ with stdenv.lib; let buildType = "release"; - # When changing this, update ./guest-additions and the extpack - # revision/hash as well. See - # http://download.virtualbox.org/virtualbox/${version}/SHA256SUMS - # for hashes. - version = "5.1.4"; + inherit (importJSON ./upstream-info.json) version extpackRev extpack main; forEachModule = action: '' for mod in \ @@ -41,12 +37,9 @@ let ''; # See https://github.com/NixOS/nixpkgs/issues/672 for details - extpackRevision = "110228"; extensionPack = requireFile rec { - name = "Oracle_VM_VirtualBox_Extension_Pack-${version}-${extpackRevision}.vbox-extpack"; - # IMPORTANT: Hash must be base16 encoded because it's used as an input to - # VBoxExtPackHelperApp! - sha256 = "9462ff1b567c37ad9a33c0c7ca1925776615ec89b5a72563f29a8cc8514cf316"; + name = "Oracle_VM_VirtualBox_Extension_Pack-${version}-${extpackRev}.vbox-extpack"; + sha256 = extpack; message = '' In order to use the extension pack, you need to comply with the VirtualBox Personal Use and Evaluation License (PUEL) available at: @@ -70,7 +63,7 @@ in stdenv.mkDerivation { src = fetchurl { url = "http://download.virtualbox.org/virtualbox/${version}/VirtualBox-${version}.tar.bz2"; - sha256 = "b9a14a7771059c55c44b97f8d4eef9bea84544f3e215e0caa563bc35e2f16aaf"; + sha256 = main; }; buildInputs = diff --git a/pkgs/applications/virtualization/virtualbox/guest-additions/default.nix b/pkgs/applications/virtualization/virtualbox/guest-additions/default.nix index 0a6293462b8..c32a34fbc12 100644 --- a/pkgs/applications/virtualization/virtualbox/guest-additions/default.nix +++ b/pkgs/applications/virtualization/virtualbox/guest-additions/default.nix @@ -12,7 +12,7 @@ stdenv.mkDerivation { src = fetchurl { url = "http://download.virtualbox.org/virtualbox/${version}/VBoxGuestAdditions_${version}.iso"; - sha256 = "e385b698338003595f6cdeee7b631ec6713058ba1227d1f2a1da342bdf741982"; + sha256 = (lib.importJSON ../upstream-info.json).guest; }; KERN_DIR = "${kernel.dev}/lib/modules/*/build"; diff --git a/pkgs/applications/virtualization/virtualbox/upstream-info.json b/pkgs/applications/virtualization/virtualbox/upstream-info.json new file mode 100644 index 00000000000..de0adf2e9db --- /dev/null +++ b/pkgs/applications/virtualization/virtualbox/upstream-info.json @@ -0,0 +1,8 @@ +{ + "__NOTE": "Generated using update.py from the same directory.", + "extpack": "9462ff1b567c37ad9a33c0c7ca1925776615ec89b5a72563f29a8cc8514cf316", + "extpackRev": "110228", + "guest": "e385b698338003595f6cdeee7b631ec6713058ba1227d1f2a1da342bdf741982", + "main": "b9a14a7771059c55c44b97f8d4eef9bea84544f3e215e0caa563bc35e2f16aaf", + "version": "5.1.4" +} From 8bd89c922d527a60d5511a1d8c9d080321478da6 Mon Sep 17 00:00:00 2001 From: aszlig Date: Tue, 13 Sep 2016 03:42:16 +0200 Subject: [PATCH 04/12] virtualbox: Split kernel modules into own package Putting the kernel modules into the same output path as the main VirtualBox derivation causes all of VirtualBox to be rebuilt on every single kernel update. The build process of VirtualBox already outputs the kernel module source along with the generated files for the configuration of the main VirtualBox package. We put this into a different output called "modsrc" which we re-use from linuxPackages.virtualbox, which is now only containing the resulting kernel modules without the main user space implementation. This not only has the advantage of decluttering the Nix expression for the user space portions but also gets rid of the need to nuke references and the need to patch out "depmod -a". Signed-off-by: aszlig --- .../virtualisation/virtualbox-host.nix | 9 ++++- .../virtualization/virtualbox/default.nix | 40 ++++--------------- pkgs/os-specific/linux/virtualbox/default.nix | 23 +++++++++++ pkgs/top-level/all-packages.nix | 36 ++++++++++------- 4 files changed, 59 insertions(+), 49 deletions(-) create mode 100644 pkgs/os-specific/linux/virtualbox/default.nix diff --git a/nixos/modules/virtualisation/virtualbox-host.nix b/nixos/modules/virtualisation/virtualbox-host.nix index ce4abecd676..7214543871d 100644 --- a/nixos/modules/virtualisation/virtualbox-host.nix +++ b/nixos/modules/virtualisation/virtualbox-host.nix @@ -4,10 +4,15 @@ with lib; let cfg = config.virtualisation.virtualbox.host; - virtualbox = config.boot.kernelPackages.virtualbox.override { + + virtualbox = pkgs.virtualbox.override { inherit (cfg) enableHardening headless; }; + kernelModules = config.boot.kernelPackages.virtualbox.override { + inherit virtualbox; + }; + in { @@ -60,7 +65,7 @@ in config = mkIf cfg.enable (mkMerge [{ boot.kernelModules = [ "vboxdrv" "vboxnetadp" "vboxnetflt" ]; - boot.extraModulePackages = [ virtualbox ]; + boot.extraModulePackages = [ kernelModules ]; environment.systemPackages = [ virtualbox ]; security.setuidOwners = let diff --git a/pkgs/applications/virtualization/virtualbox/default.nix b/pkgs/applications/virtualization/virtualbox/default.nix index 3a75479b2cf..f0f56cd1735 100644 --- a/pkgs/applications/virtualization/virtualbox/default.nix +++ b/pkgs/applications/virtualization/virtualbox/default.nix @@ -1,8 +1,8 @@ { stdenv, buildEnv, fetchurl, lib, iasl, dev86, pam, libxslt, libxml2, libX11, xproto, libXext -, libXcursor, libXmu, qt5, libIDL, SDL, libcap, zlib, libpng, glib, kernel, lvm2 +, libXcursor, libXmu, qt5, libIDL, SDL, libcap, zlib, libpng, glib, lvm2 , libXrandr, libXinerama , which, alsaLib, curl, libvpx, gawk, nettools, dbus -, xorriso, makeself, perl, pkgconfig, nukeReferences +, xorriso, makeself, perl, pkgconfig , javaBindings ? false, jdk ? null , pythonBindings ? false, python ? null , enableExtensionPack ? false, requireFile ? null, patchelf ? null, fakeroot ? null @@ -18,24 +18,6 @@ let inherit (importJSON ./upstream-info.json) version extpackRev extpack main; - forEachModule = action: '' - for mod in \ - out/linux.*/${buildType}/bin/src/vboxdrv \ - out/linux.*/${buildType}/bin/src/vboxpci \ - out/linux.*/${buildType}/bin/src/vboxnetadp \ - out/linux.*/${buildType}/bin/src/vboxnetflt - do - if [ "x$(basename "$mod")" != xvboxdrv -a ! -e "$mod/Module.symvers" ] - then - cp -v out/linux.*/${buildType}/bin/src/vboxdrv/Module.symvers \ - "$mod/Module.symvers" - fi - INSTALL_MOD_PATH="$out" INSTALL_MOD_DIR=misc \ - make -j $NIX_BUILD_CORES -C "$MODULES_BUILD_DIR" DEPMOD=/do_not_use_depmod \ - "M=\$(PWD)/$mod" BUILD_TYPE="${buildType}" ${action} - done - ''; - # See https://github.com/NixOS/nixpkgs/issues/672 for details extensionPack = requireFile rec { name = "Oracle_VM_VirtualBox_Extension_Pack-${version}-${extpackRev}.vbox-extpack"; @@ -59,17 +41,19 @@ let }; in stdenv.mkDerivation { - name = "virtualbox-${version}-${kernel.version}"; + name = "virtualbox-${version}"; src = fetchurl { url = "http://download.virtualbox.org/virtualbox/${version}/VirtualBox-${version}.tar.bz2"; sha256 = main; }; + outputs = [ "out" "modsrc" ]; + buildInputs = [ iasl dev86 libxslt libxml2 xproto libX11 libXext libXcursor libIDL libcap glib lvm2 python alsaLib curl libvpx pam xorriso makeself perl - pkgconfig which libXmu nukeReferences libpng ] + pkgconfig which libXmu libpng ] ++ optional javaBindings jdk ++ optional pythonBindings python ++ optional pulseSupport libpulseaudio @@ -80,14 +64,11 @@ in stdenv.mkDerivation { prePatch = '' set -x - MODULES_BUILD_DIR=`echo ${kernel.dev}/lib/modules/*/build` - sed -e 's@/lib/modules/`uname -r`/build@'$MODULES_BUILD_DIR@ \ - -e 's@MKISOFS --version@MKISOFS -version@' \ + sed -e 's@MKISOFS --version@MKISOFS -version@' \ -e 's@PYTHONDIR=.*@PYTHONDIR=${if pythonBindings then python else ""}@' \ -i configure ls kBuild/bin/linux.x86/k* tools/linux.x86/bin/* | xargs -n 1 patchelf --set-interpreter ${stdenv.glibc.out}/lib/ld-linux.so.2 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 - find . -type f -iname '*makefile*' -exec sed -i -e 's/depmod -a/:/g' {} + sed -i -e ' s@"libdbus-1\.so\.3"@"${dbus.lib}/lib/libdbus-1.so.3"@g s@"libasound\.so\.2"@"${alsaLib.out}/lib/libasound.so.2"@g @@ -152,7 +133,6 @@ in stdenv.mkDerivation { buildPhase = '' source env.sh kmk -j $NIX_BUILD_CORES BUILD_TYPE="${buildType}" - ${forEachModule "modules"} ''; installPhase = '' @@ -164,9 +144,6 @@ in stdenv.mkDerivation { find out/linux.*/${buildType}/bin -mindepth 1 -maxdepth 1 \ -name src -o -exec cp -avt "$libexec" {} + - # Install kernel modules - ${forEachModule "modules_install"} - # Create wrapper script mkdir -p $out/bin for file in VirtualBox VBoxManage VBoxSDL VBoxBalloonCtrl VBoxBFE VBoxHeadless; do @@ -198,8 +175,7 @@ in stdenv.mkDerivation { done ''} - # Get rid of a reference to linux.dev. - nuke-refs $out/lib/modules/*/misc/*.ko + cp -rv out/linux.*/${buildType}/bin/src "$modsrc" ''; passthru = { inherit version; /* for guest additions */ }; diff --git a/pkgs/os-specific/linux/virtualbox/default.nix b/pkgs/os-specific/linux/virtualbox/default.nix new file mode 100644 index 00000000000..593c4400b7f --- /dev/null +++ b/pkgs/os-specific/linux/virtualbox/default.nix @@ -0,0 +1,23 @@ +{ stdenv, virtualbox, kernel, strace }: + +stdenv.mkDerivation { + name = "virtualbox-modules-${virtualbox.version}-${kernel.version}"; + src = virtualbox.modsrc; + hardeningDisable = [ + "fortify" "pic" "stackprotector" + ]; + + makeFlags = [ + "-C ${kernel.dev}/lib/modules/${kernel.modDirVersion}/build" + "INSTALL_MOD_PATH=$(out)" + ]; + preBuild = "makeFlagsArray+=(\"M=$(pwd)\")"; + buildFlags = [ "modules" ]; + installTargets = [ "modules_install" ]; + + enableParallelBuilding = true; + + meta = virtualbox.meta // { + description = virtualbox.meta.description + " (kernel modules)"; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 146e260f423..ff8f3dfca6c 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -11399,23 +11399,13 @@ in vhba = callPackage ../misc/emulators/cdemu/vhba.nix { }; - virtualbox = callPackage ../applications/virtualization/virtualbox { - stdenv = stdenv_32bit; - inherit (gnome) libIDL; - enableExtensionPack = config.virtualbox.enableExtensionPack or false; - pulseSupport = config.pulseaudio or false; + virtualbox = callPackage ../os-specific/linux/virtualbox { + virtualbox = pkgs.virtualboxHardened; }; - virtualboxHardened = lowPrio (virtualbox.override { - enableHardening = true; - }); - - virtualboxHeadless = lowPrio (virtualbox.override { - enableHardening = true; - headless = true; - }); - - virtualboxGuestAdditions = callPackage ../applications/virtualization/virtualbox/guest-additions { }; + virtualboxGuestAdditions = callPackage ../applications/virtualization/virtualbox/guest-additions { + virtualbox = pkgs.virtualboxHardened; + }; wireguard = callPackage ../os-specific/linux/wireguard { }; @@ -15224,6 +15214,22 @@ in virtinst = callPackage ../applications/virtualization/virtinst {}; + virtualbox = callPackage ../applications/virtualization/virtualbox { + stdenv = stdenv_32bit; + inherit (gnome) libIDL; + enableExtensionPack = config.virtualbox.enableExtensionPack or false; + pulseSupport = config.pulseaudio or false; + }; + + virtualboxHardened = lowPrio (virtualbox.override { + enableHardening = true; + }); + + virtualboxHeadless = lowPrio (virtualbox.override { + enableHardening = true; + headless = true; + }); + virtualglLib = callPackage ../tools/X11/virtualgl/lib.nix { fltk = fltk13; }; From d2af4c67228a28b3df3016ca216f48f6d139a62e Mon Sep 17 00:00:00 2001 From: aszlig Date: Tue, 13 Sep 2016 06:01:27 +0200 Subject: [PATCH 05/12] virtualbox: Explicitly state Qt 5 dependencies In 294281596833b8d83ba90c03b792d31b868f46d7, the dependencies for Qt 5 were passed using buildEnv with all the development binaries, headers and libs. Unfortunately, the build output references that environment which also increases the size of the runtime closure. The upstream makefile assumes a common Qt 5 library path, but that's not the case within Nix, because we have separate paths for the Qt 5 modules. We now patch the makefile to recognize PATH_QT5_X11_EXTRAS_{LIB,INC} so that we can pass in the relevant paths from Qt5X11Extras. In summary, the closure size goes down to 525559600 bytes (501 MB) instead of 863035544 bytes (823 MB) with vbox-qt5-env. Signed-off-by: aszlig --- .../virtualization/virtualbox/default.nix | 21 +++++++------ .../virtualbox/qtx11extras.patch | 31 +++++++++++++++++++ 2 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 pkgs/applications/virtualization/virtualbox/qtx11extras.patch diff --git a/pkgs/applications/virtualization/virtualbox/default.nix b/pkgs/applications/virtualization/virtualbox/default.nix index f0f56cd1735..baf18c3f66f 100644 --- a/pkgs/applications/virtualization/virtualbox/default.nix +++ b/pkgs/applications/virtualization/virtualbox/default.nix @@ -1,4 +1,4 @@ -{ stdenv, buildEnv, fetchurl, lib, iasl, dev86, pam, libxslt, libxml2, libX11, xproto, libXext +{ stdenv, fetchurl, lib, iasl, dev86, pam, libxslt, libxml2, libX11, xproto, libXext , libXcursor, libXmu, qt5, libIDL, SDL, libcap, zlib, libpng, glib, lvm2 , libXrandr, libXinerama , which, alsaLib, curl, libvpx, gawk, nettools, dbus @@ -35,11 +35,6 @@ let ''; }; - vbox-qt5-env = buildEnv { - name = "vbox-qt5-env-${version}"; - paths = [ qt5.qtbase.dev qt5.qtbase.out qt5.qtx11extras.dev qt5.qtx11extras.out qt5.qttools.dev ]; - }; - in stdenv.mkDerivation { name = "virtualbox-${version}"; @@ -58,7 +53,7 @@ in stdenv.mkDerivation { ++ optional pythonBindings python ++ optional pulseSupport libpulseaudio ++ optionals (headless) [ libXrandr ] - ++ optionals (!headless) [ vbox-qt5-env libXinerama SDL ]; + ++ optionals (!headless) [ qt5.qtbase qt5.qtx11extras libXinerama SDL ]; hardeningDisable = [ "fortify" "pic" "stackprotector" ]; @@ -66,7 +61,9 @@ in stdenv.mkDerivation { set -x sed -e 's@MKISOFS --version@MKISOFS -version@' \ -e 's@PYTHONDIR=.*@PYTHONDIR=${if pythonBindings then python else ""}@' \ - -i configure + ${optionalString (!headless) '' + -e 's@TOOLQT5BIN=.*@TOOLQT5BIN="${getDev qt5.qtbase}/bin"@' \ + ''} -i configure ls kBuild/bin/linux.x86/k* tools/linux.x86/bin/* | xargs -n 1 patchelf --set-interpreter ${stdenv.glibc.out}/lib/ld-linux.so.2 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 sed -i -e ' @@ -83,7 +80,7 @@ in stdenv.mkDerivation { ''; patches = optional enableHardening ./hardened.patch - ++ [ ./libressl.patch ]; + ++ [ ./libressl.patch ./qtx11extras.patch ]; postPatch = '' sed -i -e 's|/sbin/ifconfig|${nettools}/bin/ifconfig|' \ @@ -111,11 +108,15 @@ in stdenv.mkDerivation { ${optionalString javaBindings '' VBOX_JAVA_HOME := ${jdk} ''} + ${optionalString (!headless) '' + PATH_QT5_X11_EXTRAS_LIB := ${getLib qt5.qtx11extras}/lib + PATH_QT5_X11_EXTRAS_INC := ${getDev qt5.qtx11extras}/include + TOOL_QT5_LRC := ${getDev qt5.qttools}/bin/lrelease + ''} LOCAL_CONFIG ./configure \ ${optionalString headless "--build-headless"} \ - ${optionalString (!headless) "--with-qt-dir=${vbox-qt5-env}"} \ ${optionalString (!javaBindings) "--disable-java"} \ ${optionalString (!pythonBindings) "--disable-python"} \ ${optionalString (!pulseSupport) "--disable-pulse"} \ diff --git a/pkgs/applications/virtualization/virtualbox/qtx11extras.patch b/pkgs/applications/virtualization/virtualbox/qtx11extras.patch new file mode 100644 index 00000000000..f5decc211c7 --- /dev/null +++ b/pkgs/applications/virtualization/virtualbox/qtx11extras.patch @@ -0,0 +1,31 @@ +diff --git a/kBuild/units/qt5.kmk b/kBuild/units/qt5.kmk +index 71b96a3..73391f0 100644 +--- a/kBuild/units/qt5.kmk ++++ b/kBuild/units/qt5.kmk +@@ -994,9 +994,10 @@ else + $(eval $(target)_LIBS += $(PATH_SDK_QT5_LIB)/$(qt_prefix)qtmain$(qt_infix)$(SUFF_LIB) ) + endif + else +- $(eval $(target)_LIBS += $(foreach module,$(qt_modules), $(PATH_SDK_QT5_LIB)/lib$(qt_prefix)Qt5$(module)$(qt_infix)$(SUFF_DLL)) ) ++ $(eval $(target)_LIBS += $(foreach module,$(qt_modules), $(PATH_SDK_QT5_LIB)/lib$(qt_prefix)Qt5$(module)$(qt_infix)$(SUFF_DLL)) \ ++ $(PATH_QT5_X11_EXTRAS_LIB)/lib$(qt_prefix)Qt5X11Extras$(qt_infix)$(SUFF_DLL)) + endif +- $(eval $(target)_INCS += $(addprefix $(PATH_SDK_QT5_INC)/Qt,$(qt_modules)) $(PATH_SDK_QT5_INC) ) ++ $(eval $(target)_INCS += $(addprefix $(PATH_SDK_QT5_INC)/Qt,$(qt_modules)) $(PATH_SDK_QT5_INC) $(PATH_QT5_X11_EXTRAS_INC)/QtX11Extras ) + endif + $(eval $(target)_DEFS += $(foreach module,$(toupper $(qt_modules)), QT_$(module)_LIB) ) + +diff --git a/src/VBox/Frontends/VirtualBox/Makefile.kmk b/src/VBox/Frontends/VirtualBox/Makefile.kmk +index 38db6b0..7dd446b 100644 +--- a/src/VBox/Frontends/VirtualBox/Makefile.kmk ++++ b/src/VBox/Frontends/VirtualBox/Makefile.kmk +@@ -912,9 +912,6 @@ VirtualBox_QT_MODULES = Core Gui + ifdef VBOX_WITH_QTGUI_V5 + # Qt5 requires additional modules: + VirtualBox_QT_MODULES += Widgets PrintSupport +- VirtualBox_QT_MODULES.linux += X11Extras +- VirtualBox_QT_MODULES.solaris += X11Extras +- VirtualBox_QT_MODULES.freebsd += X11Extras + VirtualBox_QT_MODULES.darwin += MacExtras + VirtualBox_QT_MODULES.win += WinExtras + endif # VBOX_WITH_QTGUI_V5 From 4a44eca07d5da2adc162b727a2ca0683aa29c45d Mon Sep 17 00:00:00 2001 From: aszlig Date: Tue, 13 Sep 2016 06:34:33 +0200 Subject: [PATCH 06/12] nixos/release-notes: Add VirtualBox changes The change is backwards-compatible for users of the NixOS module but not if people were using the package directly, so let's warn users about that. Signed-off-by: aszlig --- nixos/doc/manual/release-notes/rl-1609.xml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/nixos/doc/manual/release-notes/rl-1609.xml b/nixos/doc/manual/release-notes/rl-1609.xml index 70759ee25f8..792b4458caa 100644 --- a/nixos/doc/manual/release-notes/rl-1609.xml +++ b/nixos/doc/manual/release-notes/rl-1609.xml @@ -90,6 +90,15 @@ following incompatible changes: Use security.audit.enable = true; to explicitly enable it. + + + pkgs.linuxPackages.virtualbox now contains only the + kernel modules instead of the VirtualBox user space binaries. + If you want to reference the user space binaries, you have to use the new + pkgs.virtualbox instead. + + + From eea4af1c4cc7e885f66b1a804be0246c7ad63d1a Mon Sep 17 00:00:00 2001 From: aszlig Date: Tue, 13 Sep 2016 07:24:58 +0200 Subject: [PATCH 07/12] nixos/virtualbox-image: Fix path to virtualbox VirtualBox user space binaries now no longer reside in linuxPackages, so let's use the package for the real user space binaries instead. Tested using the following command: nix-build nixos/release.nix -A ova.x86_64-linux Signed-off-by: aszlig --- nixos/modules/virtualisation/virtualbox-image.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos/modules/virtualisation/virtualbox-image.nix b/nixos/modules/virtualisation/virtualbox-image.nix index b6a5b3e4788..d68b3bb7390 100644 --- a/nixos/modules/virtualisation/virtualbox-image.nix +++ b/nixos/modules/virtualisation/virtualbox-image.nix @@ -34,7 +34,7 @@ in { postVM = '' export HOME=$PWD - export PATH=${pkgs.linuxPackages.virtualbox}/bin:$PATH + export PATH=${pkgs.virtualbox}/bin:$PATH echo "creating VirtualBox pass-through disk wrapper (no copying invovled)..." VBoxManage internalcommands createrawvmdk -filename disk.vmdk -rawdisk $diskImage From e19aa3819e21c79215db361b2913571f33b7d23f Mon Sep 17 00:00:00 2001 From: aszlig Date: Tue, 13 Sep 2016 14:07:56 +0200 Subject: [PATCH 08/12] virtualbox: 5.1.4 -> 5.1.6 Upstream changelog without bug numbers: * GUI: fixed issue with opening '.vbox' files and it's aliases * GUI: keyboard grabbing fixes * GUI: fix for passing through Ctrl + mouse-click * GUI: fixed automatic deletion of extension pack files * USB: fixed showing unknown device instead of the manufacturer or product description under certain circumstances * XHCI: another fix for a hanging guest under certain conditions, this time for Windows 7 guests * Serial: fixed high CPU usage with certain USB to serial converters on Linux hosts * Storage: fixed attaching stream optimized VMDK images * Storage: reject image variants which are unsupported by the backend * Storage: fixed loading saved states created with VirtualBox 5.0.10 and older when using a SCSI controller * Storage: fixed broken NVMe emulation if the host I/O cache setting is enabled * Storage: fixed using multiple NVMe controllers if ICH9 is used * NVMe: fixed a crash during reset which could happen under certain circumstances * Audio: fixed microphone input (5.1.2 regression) * Audio: fixed crashes under certain conditions (5.1.0 regression) * Audio: fixed recording with the ALSA backend (5.1 regression) * Audio: fixed stream access mode with OSS backend (5.1 regression, thanks to Jung-uk Kim) * E1000: do also return masked bits when reading the ICR register, this fixes booting from iPXE (5.1.2 regression) * BIOS: fixed 4bpp scanline calculation * API: relax the check for the version attribute in OVF/OVA appliances * Windows hosts: fixed crashes when terminating the VM selector or other VBox COM clients * Linux Installer: fixed path to the documentation in .rpm packages (5.1.0 regression) * Linux Installer: fixed the vboxdrv.sh script to prevent an SELinux complaint * Linux hosts: don't use 32-bit legacy capabilities * Linux Additions: Linux 4.8 fix for the kernel display driver * Linux Additions: don't load the kernel modules provided by the Linux distribution but load the kernel modules from the official Guest Additions package instead * Linux Additions: fix dynamic resizing problems in recent Linux guests * User Manual: fixed error in the VBoxManage chapter for the getextradata enumerate example The full upstream changelog with bug numbers can be found at: https://www.virtualbox.org/wiki/Changelog-5.1#v6 Signed-off-by: aszlig --- .../virtualization/virtualbox/upstream-info.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkgs/applications/virtualization/virtualbox/upstream-info.json b/pkgs/applications/virtualization/virtualbox/upstream-info.json index de0adf2e9db..3a386004a3f 100644 --- a/pkgs/applications/virtualization/virtualbox/upstream-info.json +++ b/pkgs/applications/virtualization/virtualbox/upstream-info.json @@ -1,8 +1,8 @@ { "__NOTE": "Generated using update.py from the same directory.", - "extpack": "9462ff1b567c37ad9a33c0c7ca1925776615ec89b5a72563f29a8cc8514cf316", - "extpackRev": "110228", - "guest": "e385b698338003595f6cdeee7b631ec6713058ba1227d1f2a1da342bdf741982", - "main": "b9a14a7771059c55c44b97f8d4eef9bea84544f3e215e0caa563bc35e2f16aaf", - "version": "5.1.4" + "extpack": "607ac3636bd49a738d5c48159b39261369b5487f71fb10afa2ecf869627a12de", + "extpackRev": "110634", + "guest": "cbcf9b9b1000e09911b3d20e1efe529aef8a945cf130f6abffc14a39522cc1ed", + "main": "2e0112b0d85841587b8f212e6ba8f6c35b31e1cce6b6999497dc917cd37e6911", + "version": "5.1.6" } From 562c7f56f0526c2353b99246370a3d17f40ec148 Mon Sep 17 00:00:00 2001 From: aszlig Date: Tue, 13 Sep 2016 14:52:49 +0200 Subject: [PATCH 09/12] nixos/tests/vbox: Make shutdown less noisy Using waitUntilSucceeds for testing whether the shutdown signalling files have vanished is quite noisy because it prints two lines for every try. This is now fixed with a while loop on the guest VM which does the same check but with only one output for the command that's executed and another one when the conditions are met. Signed-off-by: aszlig --- nixos/tests/virtualbox.nix | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/nixos/tests/virtualbox.nix b/nixos/tests/virtualbox.nix index ab4d46ab7e1..c1205ca0c8a 100644 --- a/nixos/tests/virtualbox.nix +++ b/nixos/tests/virtualbox.nix @@ -273,9 +273,12 @@ let sub shutdownVM_${name} { $machine->succeed(ru "touch ${sharePath}/shutdown"); - $machine->waitUntilSucceeds( - "test ! -e ${sharePath}/shutdown ". - " -a ! -e ${sharePath}/boot-done" + $machine->execute( + 'set -e; i=0; '. + 'while test -e ${sharePath}/shutdown '. + ' -o -e ${sharePath}/boot-done; do '. + 'sleep 1; i=$(($i + 1)); [ $i -le 3600 ]; '. + 'done' ); waitForShutdown_${name}; } From e18f4a2cf92cf4fd43d0d4ad1adfb93cd011cbf1 Mon Sep 17 00:00:00 2001 From: aszlig Date: Tue, 13 Sep 2016 15:04:56 +0200 Subject: [PATCH 10/12] virtualbox: Build with PulseAudio by default If people want to disable support for PulseAudio they can still explicitly use pulseaudio = false in their nixpkgs config. But even with enabled PulseAudio support, it's still optional, enabled at runtime and can be turned off in VirtualBox settings as well. Signed-off-by: aszlig Issue: #15005 --- pkgs/top-level/all-packages.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index ff8f3dfca6c..a74c74e66e1 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -15218,7 +15218,7 @@ in stdenv = stdenv_32bit; inherit (gnome) libIDL; enableExtensionPack = config.virtualbox.enableExtensionPack or false; - pulseSupport = config.pulseaudio or false; + pulseSupport = config.pulseaudio or true; }; virtualboxHardened = lowPrio (virtualbox.override { From 80c2cc350cd51fbfa9ccd49aeff08a78ab38fbd0 Mon Sep 17 00:00:00 2001 From: aszlig Date: Tue, 13 Sep 2016 23:17:47 +0200 Subject: [PATCH 11/12] nixos/tests/vbox: Disable audio for VBox guests We don't have (simulated) sound hardware within the qemu VM, neither do we have it available within VirtualBox that's running within the qemu VMs. With sound hardware the VirtualBox UI displays an error dialog, which in turn causes the VM process to hang on unregister. This in turn has caused the tests to fail because of the following error: Cannot unregister the machine '...' while it is locked Signed-off-by: aszlig --- nixos/tests/virtualbox.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/nixos/tests/virtualbox.nix b/nixos/tests/virtualbox.nix index c1205ca0c8a..cafdf10ef51 100644 --- a/nixos/tests/virtualbox.nix +++ b/nixos/tests/virtualbox.nix @@ -144,6 +144,7 @@ let "--uart1 0x3F8 4" "--uartmode1 client /run/virtualbox-log-${name}.sock" "--memory 768" + "--audio none" ] ++ (attrs.vmFlags or [])); controllerFlags = mkFlags [ From f7563efa6e01c3dbc883a1c0047d4beeddc4fc86 Mon Sep 17 00:00:00 2001 From: aszlig Date: Wed, 14 Sep 2016 02:12:16 +0200 Subject: [PATCH 12/12] nixos/tests/vbox: Add destroyVM for all subtests One reason why it took me so long for debugging the test failure with systemd-detect-virt was that simple-cli has succeeded while the former has not. This now makes sure we have consistency accross all the subtests and if problems like the one in the previos commit ever show up again, we will have just the headless test succeeding and it's more obvious where the actual problem resides. Signed-off-by: aszlig --- nixos/tests/virtualbox.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nixos/tests/virtualbox.nix b/nixos/tests/virtualbox.nix index cafdf10ef51..66f16ed8bcc 100644 --- a/nixos/tests/virtualbox.nix +++ b/nixos/tests/virtualbox.nix @@ -390,6 +390,7 @@ in mapAttrs mkVBoxTest { $machine->sendKeys("ctrl-q"); $machine->sleep(5); $machine->screenshot("gui_manager_stopped"); + destroyVM_simple; ''; simple-cli = '' @@ -407,6 +408,7 @@ in mapAttrs mkVBoxTest { }); shutdownVM_simple; + destroyVM_simple; ''; headless = '' @@ -415,6 +417,7 @@ in mapAttrs mkVBoxTest { waitForStartup_headless; waitForVMBoot_headless; shutdownVM_headless; + destroyVM_headless; ''; host-usb-permissions = ''