@@ -1,5 +1,5 @@
11{ stdenv, fetchurl, lib, patchelf, cdrkit, kernel, which, makeWrapper
2−, zlib, xorg, dbus, virtualbox, dos2unix }:
2+, zlib, xorg, dbus, virtualbox, dos2unix, fetchpatch, findutils, patchutils }:
33
44let
55 version = virtualbox.version;
@@ -21,12 +21,12 @@ let
2121 { name = "libXfixes.so"; pkg = xorg.libXfixes; }
2222 ];
2323
24−in stdenv.mkDerivation {
24+in stdenv.mkDerivation rec {
2525 name = "VirtualBox-GuestAdditions-${version}-${kernel.version}";
2626
2727 src = fetchurl {
2828 url = "http://download.virtualbox.org/virtualbox/${version}/VBoxGuestAdditions_${version}.iso";
29− sha256 = "0hflsbx70dli34mpx94vd33p55ycfs3ahzwcdzqxdiwiiskjpykq";
29+ sha256 = "1c9ysx0fhxxginmp607b4fk74dvlr32n6w52gawm06prf4xg90nb";
3030 };
3131
3232 KERN_DIR = "${kernel.dev}/lib/modules/${kernel.modDirVersion}/build";
@@ -43,13 +43,67 @@ in stdenv.mkDerivation {
4343 prePatch = ''
4444 substituteInPlace src/vboxguest-${version}/vboxvideo/vbox_ttm.c \
4545 --replace "<ttm/" "<drm/ttm/"
46− ${dos2unix}/bin/dos2unix src/vboxguest-${version}/vboxguest/r0drv/linux/mp-r0drv-linux.c
46+
47+ echo ${lib.escapeShellArgs patches} | \
48+ ${findutils}/bin/xargs -n1 ${patchutils}/bin/lsdiff --strip=1 --addprefix=src/vboxguest-${version}/ | \
49+ ${findutils}/bin/xargs ${dos2unix}/bin/dos2unix
4750 '';
4851
4952 patchFlags = [ "-p1" "-d" "src/vboxguest-${version}" ];
50− # Kernel 5.3 fix, should be fixed with VirtualBox 6.0.14
51− # https://www.virtualbox.org/ticket/18911
52− patches = [ ./kernel-5.3-fix.patch ];
53+ # Kernel 5.4 fix, should be fixed with next upstream release
54+ # https://www.virtualbox.org/ticket/18945
55+ patches = lib.concatLists (lib.mapAttrsToList (changeset: args:
56+ map (arg:
57+ fetchpatch ({
58+ name = "kernel-5.4-fix-${changeset}.patch";
59+ url = "https://www.virtualbox.org/changeset/${changeset}/vbox?format=diff";
60+ } // arg)) args) {
61+ "81586" = [{
62+ sha256 = "126z67x6vy65w6jlqbh4z4f1cffxnycwb69vns0154bawbsbxsiw";
63+ stripLen = 5;
64+ extraPrefix = "vboxguest/";
65+ }];
66+ "81587" = [
67+ {
68+ sha256 = "0simzswnl0wvnc2i9gixz99rfc7lxk1nrnskksrlrrl9hqnh0lva";
69+ stripLen = 5;
70+ extraPrefix = "vboxsf/";
71+ includes = [ "*/the-linux-kernel.h" ];
72+ }
73+ {
74+ sha256 = "0a8r9h3x3lcjq2fykgqhdaykp00rnnkbxz8xnxg847zgvca15y02";
75+ stripLen = 5;
76+ extraPrefix = "vboxguest/";
77+ includes = [ "*/the-linux-kernel.h" ];
78+ }
79+ ];
80+ "81649" = [
81+ {
82+ sha256 = "1p1skxlvqigydxr4sk7w51lpk7nxg0d9lppq39sdnfmgi1z0h0sc";
83+ stripLen = 2;
84+ extraPrefix = "vboxguest/";
85+ includes = [ "*/cdefs.h" ];
86+ }
87+ {
88+ sha256 = "1j060ggdnndyjdhkfvs15306gl7g932sim9xjmx2mnx8gjdmg37f";
89+ stripLen = 2;
90+ extraPrefix = "vboxsf/";
91+ includes = [ "*/cdefs.h" ];
92+ }
93+ {
94+ sha256 = "060h3a5k2yklbvlg0hyg4x87xrg37cvv3rjb67xizlwvlyy6ykkg";
95+ stripLen = 5;
96+ extraPrefix = "vboxguest/";
97+ includes = [ "*/thread2-r0drv-linux.c" ];
98+ }
99+ {
100+ sha256 = "0cxlkf7cy751gl8dgzr7vkims1kmx5pgzsrxyk8w18zyp5nk9glw";
101+ stripLen = 7;
102+ extraPrefix = "vboxvideo/";
103+ includes = [ "*/vbox_*.c" ];
104+ }
105+ ];
106+ });
53107
54108 unpackPhase = ''
55109 ${if stdenv.hostPlatform.system == "i686-linux" || stdenv.hostPlatform.system == "x86_64-linux" then ''