about summary refs log tree commit diff
path: root/nixpkgs/pkgs/applications/virtualization/virtualbox/guest-additions/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/applications/virtualization/virtualbox/guest-additions/default.nix')
-rw-r--r--nixpkgs/pkgs/applications/virtualization/virtualbox/guest-additions/default.nix95
1 files changed, 81 insertions, 14 deletions
diff --git a/nixpkgs/pkgs/applications/virtualization/virtualbox/guest-additions/default.nix b/nixpkgs/pkgs/applications/virtualization/virtualbox/guest-additions/default.nix
index ad860b07bdf6..690b72f3eeb0 100644
--- a/nixpkgs/pkgs/applications/virtualization/virtualbox/guest-additions/default.nix
+++ b/nixpkgs/pkgs/applications/virtualization/virtualbox/guest-additions/default.nix
@@ -1,9 +1,9 @@
 { stdenv, fetchurl, lib, patchelf, cdrkit, kernel, which, makeWrapper
-, zlib, xorg, dbus, virtualbox }:
+, zlib, xorg, dbus, virtualbox, dos2unix, fetchpatch, findutils, patchutils }:
 
 let
   version = virtualbox.version;
-  xserverVListFunc = builtins.elemAt (stdenv.lib.splitString "." xorg.xorgserver.version);
+  xserverVListFunc = builtins.elemAt (stdenv.lib.splitVersion xorg.xorgserver.version);
 
   # Forced to 1.18 in <nixpkgs/nixos/modules/services/x11/xserver.nix>
   # as it even fails to build otherwise.  Still, override this even here,
@@ -12,22 +12,26 @@ let
   # It's likely to work again in some future update.
   xserverABI = let abi = xserverVListFunc 0 + xserverVListFunc 1;
     in if abi == "119" || abi == "120" then "118" else abi;
-in
 
-stdenv.mkDerivation {
+  # Specifies how to patch binaries to make sure that libraries loaded using
+  # dlopen are found. We grep binaries for specific library names and patch
+  # RUNPATH in matching binaries to contain the needed library paths.
+  dlopenLibs = [
+    { name = "libdbus-1.so"; pkg = dbus; }
+    { name = "libXfixes.so"; pkg = xorg.libXfixes; }
+  ];
+
+in stdenv.mkDerivation rec {
   name = "VirtualBox-GuestAdditions-${version}-${kernel.version}";
 
   src = fetchurl {
     url = "http://download.virtualbox.org/virtualbox/${version}/VBoxGuestAdditions_${version}.iso";
-    sha256 = "098kibz8dkiqd8shm44n4h6iyszcbj0ikav1b4vsi75dqzw8d9n8";
+    sha256 = "1c9ysx0fhxxginmp607b4fk74dvlr32n6w52gawm06prf4xg90nb";
   };
 
   KERN_DIR = "${kernel.dev}/lib/modules/${kernel.modDirVersion}/build";
   KERN_INCL = "${kernel.dev}/lib/modules/${kernel.modDirVersion}/source/include";
 
-  # If you add a patch you probably need this.
-  #patchFlags = [ "-p1" "-d" "install/src/vboxguest-${version}" ];
-
   hardeningDisable = [ "pic" ];
 
   NIX_CFLAGS_COMPILE = "-Wno-error=incompatible-pointer-types -Wno-error=implicit-function-declaration";
@@ -35,15 +39,78 @@ stdenv.mkDerivation {
   nativeBuildInputs = [ patchelf makeWrapper ];
   buildInputs = [ cdrkit ] ++ kernel.moduleBuildDependencies;
 
-  postPatch = ''
+
+  prePatch = ''
     substituteInPlace src/vboxguest-${version}/vboxvideo/vbox_ttm.c \
       --replace "<ttm/" "<drm/ttm/"
+    
+    echo ${lib.escapeShellArgs patches} | \
+      ${findutils}/bin/xargs -n1 ${patchutils}/bin/lsdiff --strip=1 --addprefix=src/vboxguest-${version}/ | \
+      ${findutils}/bin/xargs ${dos2unix}/bin/dos2unix
   '';
 
+  patchFlags = [ "-p1" "-d" "src/vboxguest-${version}" ];
+  # Kernel 5.4 fix, should be fixed with next upstream release
+  # https://www.virtualbox.org/ticket/18945
+  patches = lib.concatLists (lib.mapAttrsToList (changeset: args:
+    map (arg:
+      fetchpatch ({
+        name = "kernel-5.4-fix-${changeset}.patch";
+        url = "https://www.virtualbox.org/changeset/${changeset}/vbox?format=diff";
+      } // arg)) args) {
+        "81586" = [{
+          sha256 = "126z67x6vy65w6jlqbh4z4f1cffxnycwb69vns0154bawbsbxsiw";
+          stripLen = 5;
+          extraPrefix = "vboxguest/";
+        }];
+        "81587" = [
+          {
+            sha256 = "0simzswnl0wvnc2i9gixz99rfc7lxk1nrnskksrlrrl9hqnh0lva";
+            stripLen = 5;
+            extraPrefix = "vboxsf/";
+            includes = [ "*/the-linux-kernel.h" ];
+          }
+          {
+            sha256 = "0a8r9h3x3lcjq2fykgqhdaykp00rnnkbxz8xnxg847zgvca15y02";
+            stripLen = 5;
+            extraPrefix = "vboxguest/";
+            includes = [ "*/the-linux-kernel.h" ];
+          }
+        ];
+        "81649" = [
+          {
+            sha256 = "1p1skxlvqigydxr4sk7w51lpk7nxg0d9lppq39sdnfmgi1z0h0sc";
+            stripLen = 2;
+            extraPrefix = "vboxguest/";
+            includes = [ "*/cdefs.h" ];
+          }
+          {
+            sha256 = "1j060ggdnndyjdhkfvs15306gl7g932sim9xjmx2mnx8gjdmg37f";
+            stripLen = 2;
+            extraPrefix = "vboxsf/";
+            includes = [ "*/cdefs.h" ];
+          }
+          {
+            sha256 = "060h3a5k2yklbvlg0hyg4x87xrg37cvv3rjb67xizlwvlyy6ykkg";
+            stripLen = 5;
+            extraPrefix = "vboxguest/";
+            includes = [ "*/thread2-r0drv-linux.c" ];
+          }
+          {
+            sha256 = "0cxlkf7cy751gl8dgzr7vkims1kmx5pgzsrxyk8w18zyp5nk9glw";
+            stripLen = 7;
+            extraPrefix = "vboxvideo/";
+            includes = [ "*/vbox_*.c" ];
+          }
+        ];
+      });
+
   unpackPhase = ''
     ${if stdenv.hostPlatform.system == "i686-linux" || stdenv.hostPlatform.system == "x86_64-linux" then ''
         isoinfo -J -i $src -x /VBoxLinuxAdditions.run > ./VBoxLinuxAdditions.run
         chmod 755 ./VBoxLinuxAdditions.run
+        # An overflow leads the is-there-enough-space check to fail when there's too much space available, so fake how much space there is
+        sed -i 's/\$leftspace/16383/' VBoxLinuxAdditions.run
         ./VBoxLinuxAdditions.run --noexec --keep
       ''
       else throw ("Architecture: "+stdenv.hostPlatform.system+" not supported for VirtualBox guest additions")
@@ -134,13 +201,13 @@ stdenv.mkDerivation {
   # Stripping breaks these binaries for some reason.
   dontStrip = true;
 
-  # Some code dlopen() libdbus, patch RUNPATH in fixupPhase so it isn't stripped.
-  postFixup = ''
-    for i in $(grep -F libdbus-1.so -l -r $out/{lib,bin}); do
+  # Patch RUNPATH according to dlopenLibs (see the comment there).
+  postFixup = lib.concatMapStrings (library: ''
+    for i in $(grep -F ${lib.escapeShellArg library.name} -l -r $out/{lib,bin}); do
       origRpath=$(patchelf --print-rpath "$i")
-      patchelf --set-rpath "$origRpath:${lib.makeLibraryPath [ dbus ]}" "$i"
+      patchelf --set-rpath "$origRpath:${lib.makeLibraryPath [ library.pkg ]}" "$i"
     done
-  '';
+  '') dlopenLibs;
 
   meta = {
     description = "Guest additions for VirtualBox";