biome: 1.9.2 -> 1.9.3
[NixPkgs.git] / pkgs / applications / virtualization / virtualbox / guest-additions / builder.nix
blob00d0d555c60ad0b3176b560600013e8a3df551a0
1 { stdenv, kernel, fetchurl, lib, pam, libxslt
2 , libXext, libXcursor, libXmu
3 , glib, libXrandr, dbus, xz
4 , pkg-config, which, xorg
5 , yasm, patchelf, makeself
6 , linuxHeaders, openssl}:
8 let
9   buildType = "release";
11 in stdenv.mkDerivation (finalAttrs: {
12   pname = "VirtualBox-GuestAdditions-builder-${kernel.version}";
13   version = "7.0.20";
15   src = fetchurl {
16     url = "https://download.virtualbox.org/virtualbox/${finalAttrs.version}/VirtualBox-${finalAttrs.version}.tar.bz2";
17     sha256 = "5cf5979bef66ebab3fcd495796b215a940e8a07c469d4bc56d064de44222dd02";
18   };
20   env.NIX_CFLAGS_COMPILE = "-Wno-error=incompatible-pointer-types -Wno-error=implicit-function-declaration";
22   nativeBuildInputs = [ patchelf pkg-config which yasm makeself xorg.xorgserver openssl linuxHeaders xz ] ++ kernel.moduleBuildDependencies;
23   buildInputs = [ dbus libxslt libXext libXcursor pam libXmu libXrandr ];
25   KERN_DIR = "${kernel.dev}/lib/modules/${kernel.modDirVersion}/build";
26   KERN_INCL = "${kernel.dev}/lib/modules/${kernel.modDirVersion}/source/include";
28   prePatch = ''
29     rm -r src/VBox/Additions/x11/x11include/
30     rm -r src/VBox/Additions/3D/mesa/mesa-*/
31     rm -r src/libs/openssl-*/
32     rm -r src/libs/curl-*/
33     rm -r src/libs/libpng-*/
34     rm -r src/libs/libxml2-*/
35     rm -r src/libs/liblzma-*/
36     rm -r src/libs/zlib*/
37   '';
39   patches = [
40     ## https://www.virtualbox.org/changeset/100258/vbox
41     ./no-legacy-xorg.patch
42   ];
44   postPatch = ''
45     set -x
46     sed -e 's@MKISOFS --version@MKISOFS -version@' \
47         -e 's@CXX_FLAGS="\(.*\)"@CXX_FLAGS="-std=c++17 \1"@' \
48         -i configure
49     ls kBuild/bin/linux.x86/k* tools/linux.x86/bin/* | xargs -n 1 patchelf --set-interpreter ${stdenv.cc.libc}/lib/ld-linux.so.2
50     ls kBuild/bin/linux.amd64/k* tools/linux.amd64/bin/* | xargs -n 1 patchelf --set-interpreter ${stdenv.cc.libc}/lib/ld-linux-x86-64.so.2
52     substituteInPlace ./include/VBox/dbus-calls.h --replace-fail libdbus-1.so.3 ${dbus.lib}/lib/libdbus-1.so.3
54     substituteInPlace ./src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR3LibDrmClient.cpp --replace-fail /usr/bin/VBoxDRMClient /run/current-system/sw/bin/VBoxDRMClient
55     substituteInPlace ./src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR3LibDrmClient.cpp --replace-fail /usr/bin/VBoxClient /run/current-system/sw/bin/VBoxClient
56     substituteInPlace ./src/VBox/Additions/x11/VBoxClient/display.cpp --replace-fail /usr/X11/bin/xrandr ${xorg.xrandr}/bin/xrandr
57     substituteInPlace ./src/VBox/Additions/x11/vboxvideo/Makefile.kmk --replace-fail /usr/include/xorg "${xorg.xorgserver.dev}/include/xorg "
58   '';
60   configurePhase = ''
61       NIX_CFLAGS_COMPILE=$(echo "$NIX_CFLAGS_COMPILE" | sed 's,\-isystem ${lib.getDev stdenv.cc.libc}/include,,g')
63       cat >> LocalConfig.kmk <<LOCAL_CONFIG
64       VBOX_WITH_TESTCASES            :=
65       VBOX_WITH_TESTSUITE            :=
66       VBOX_WITH_VALIDATIONKIT        :=
67       VBOX_WITH_DOCS                 :=
68       VBOX_WITH_WARNINGS_AS_ERRORS   :=
70       VBOX_WITH_ORIGIN               :=
71       VBOX_PATH_APP_PRIVATE_ARCH_TOP := $out/share/virtualbox
72       VBOX_PATH_APP_PRIVATE_ARCH     := $out/libexec/virtualbox
73       VBOX_PATH_SHARED_LIBS          := $out/libexec/virtualbox
74       VBOX_WITH_RUNPATH              := $out/libexec/virtualbox
75       VBOX_PATH_APP_PRIVATE          := $out/share/virtualbox
76       VBOX_PATH_APP_DOCS             := $out/doc
78       VBOX_USE_SYSTEM_XORG_HEADERS := 1
79       VBOX_USE_SYSTEM_GL_HEADERS := 1
80       VBOX_NO_LEGACY_XORG_X11 := 1
81       SDK_VBoxLibPng_INCS :=
82       SDK_VBoxLibXml2_INCS :=
83       SDK_VBoxLibLzma_INCS := ${xz.dev}/include
84       SDK_VBoxLibLzma_LIBS := ${xz.out}/lib
86       SDK_VBoxOpenSslStatic_INCS := ${openssl.dev}/include/ssl
88       VBOX_ONLY_ADDITIONS := 1
89       VBOX_WITH_SHARED_CLIPBOARD := 1
90       VBOX_WITH_GUEST_PROPS := 1
91       VBOX_WITH_VMSVGA := 1
92       VBOX_WITH_SHARED_FOLDERS := 1
93       VBOX_WITH_GUEST_CONTROL := 1
94       VBOX_WITHOUT_LINUX_GUEST_PACKAGE := 1
95       VBOX_WITH_PAM :=
96       VBOX_WITH_UPDATE_AGENT :=
97       VBOX_WITH_AUDIO_ALSA :=
98       VBOX_WITH_AUDIO_PULSE :=
100       VBOX_BUILD_PUBLISHER := _NixOS
101       LOCAL_CONFIG
103       ./configure \
104         --only-additions \
105         --with-linux=${kernel.dev} \
106         --disable-kmods
108       sed -e 's@PKG_CONFIG_PATH=.*@PKG_CONFIG_PATH=${glib.dev}/lib/pkgconfig @' \
109         -i AutoConfig.kmk
110       sed -e 's@arch/x86/@@' \
111         -i Config.kmk
113       export USER=nix
114       set +x
115     '';
117   enableParallelBuilding = true;
119   buildPhase = ''
120     runHook preBuild
122     source env.sh
123     VBOX_ONLY_ADDITIONS=1 VBOX_ONLY_BUILD=1 kmk -j $NIX_BUILD_CORES BUILD_TYPE="${buildType}"
124     VBOX_ONLY_ADDITIONS=1 VBOX_ONLY_BUILD=1 kmk packing
126     runHook postBuild
127   '';
129   installPhase = ''
130     runHook preInstall
132     mkdir -p $out
133     cp -rv ./out/linux.${if stdenv.hostPlatform.is32bit then "x86" else "amd64"}/${buildType}/bin/additions/VBoxGuestAdditions-${if stdenv.hostPlatform.is32bit then "x86" else "amd64"}.tar.bz2 $out/
135     runHook postInstall
136   '';