Merge pull request #303790 from FriedrichAltheide/cleanup-virtualbox

virtualbox & virtualboxGuestAdditions: cleanup
This commit is contained in:
Arnout Engelen 2024-06-01 13:42:14 +02:00 committed by GitHub
commit 61c1d28215
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 62 additions and 45 deletions

View File

@ -52,7 +52,7 @@ in
description = "Whether to enable seamless mode. When activated windows from the guest appear next to the windows of the host.";
};
draganddrop = mkOption {
dragAndDrop = mkOption {
default = true;
type = types.bool;
description = "Whether to enable drag and drop support.";
@ -111,5 +111,10 @@ in
systemd.user.services.virtualboxClientSeamless = mkVirtualBoxUserService "--seamless";
}
)
(
mkIf cfg.dragAndDrop {
systemd.user.services.virtualboxClientDragAndDrop = mkVirtualBoxUserService "--draganddrop";
}
)
]);
}

View File

@ -28,26 +28,32 @@ assert enableKvm -> !enableHardening;
# The web services use Java infrastructure.
assert enableWebService -> javaBindings;
with lib;
let
buildType = "release";
# Use maintainers/scripts/update.nix to update the version and all related hashes or
# change the hashes in extpack.nix and guest-additions/default.nix as well manually.
version = "7.0.14";
virtualboxVersion = "7.0.14";
virtualboxSha256 = "45860d834804a24a163c1bb264a6b1cb802a5bc7ce7e01128072f8d6a4617ca9";
kvmPatchVersion = "20240502";
kvmPatchHash = "sha256-KokIrrAoJutHzPg6e5YAJgDGs+nQoVjapmyn9kG5tV0=";
# The KVM build is not compatible to VirtualBox's kernel modules. So don't export
# modsrc at all.
withModsrc = !enableKvm;
virtualboxGuestAdditionsIso = callPackage guest-additions-iso/default.nix { };
in stdenv.mkDerivation {
inherit (lib) optional optionals optionalString getDev getLib;
in stdenv.mkDerivation (finalAttrs: {
pname = "virtualbox";
inherit version;
version = finalAttrs.virtualboxVersion;
inherit buildType virtualboxVersion virtualboxSha256 kvmPatchVersion kvmPatchHash virtualboxGuestAdditionsIso;
src = fetchurl {
url = "https://download.virtualbox.org/virtualbox/${version}/VirtualBox-${version}.tar.bz2";
sha256 = "45860d834804a24a163c1bb264a6b1cb802a5bc7ce7e01128072f8d6a4617ca9";
url = "https://download.virtualbox.org/virtualbox/${finalAttrs.virtualboxVersion}/VirtualBox-${finalAttrs.virtualboxVersion}.tar.bz2";
sha256 = finalAttrs.virtualboxSha256;
};
outputs = [ "out" ] ++ optional withModsrc "modsrc";
@ -74,7 +80,7 @@ in stdenv.mkDerivation {
prePatch = ''
set -x
sed -e 's@MKISOFS --version@MKISOFS -version@' \
-e 's@PYTHONDIR=.*@PYTHONDIR=${lib.optionalString pythonBindings python3}@' \
-e 's@PYTHONDIR=.*@PYTHONDIR=${optionalString pythonBindings python3}@' \
-e 's@CXX_FLAGS="\(.*\)"@CXX_FLAGS="-std=c++11 \1"@' \
${optionalString (!headless) ''
-e 's@TOOLQT5BIN=.*@TOOLQT5BIN="${getDev qtbase}/bin"@' \
@ -103,7 +109,7 @@ in stdenv.mkDerivation {
# No update patch disables check for update function
# https://bugs.launchpad.net/ubuntu/+source/virtualbox-ose/+bug/272212
(fetchpatch {
url = "https://salsa.debian.org/pkg-virtualbox-team/virtualbox/-/raw/debian/${version}-dfsg-1/debian/patches/16-no-update.patch";
url = "https://salsa.debian.org/pkg-virtualbox-team/virtualbox/-/raw/debian/7.0.14-dfsg-1/debian/patches/16-no-update.patch";
hash = "sha256-UJHpuB6QB/BbxJorlqZXUF12lgq8gbLMRHRMsbyqRpY=";
})]
++ [ ./extra_symbols.patch ]
@ -120,14 +126,11 @@ in stdenv.mkDerivation {
})
# While the KVM patch should not break any other behavior if --with-kvm is not specified,
# we don't take any chances and only apply it if people actually want to use KVM support.
++ optional enableKvm (fetchpatch
(let
patchVersion = "20240502";
in {
name = "virtualbox-${version}-kvm-dev-${patchVersion}.patch";
url = "https://github.com/cyberus-technology/virtualbox-kvm/releases/download/dev-${patchVersion}/kvm-backend-${version}-dev-${patchVersion}.patch";
hash = "sha256-KokIrrAoJutHzPg6e5YAJgDGs+nQoVjapmyn9kG5tV0=";
}))
++ optional enableKvm (fetchpatch {
name = "virtualbox-${finalAttrs.virtualboxVersion}-kvm-dev-${finalAttrs.kvmPatchVersion}.patch";
url = "https://github.com/cyberus-technology/virtualbox-kvm/releases/download/dev-${finalAttrs.kvmPatchVersion}/kvm-backend-${finalAttrs.virtualboxVersion}-dev-${finalAttrs.kvmPatchVersion}.patch";
hash = finalAttrs.kvmPatchHash;
})
++ [
./qt-dependency-paths.patch
# https://github.com/NixOS/nixpkgs/issues/123851
@ -139,10 +142,6 @@ in stdenv.mkDerivation {
postPatch = ''
sed -i -e 's|/sbin/ifconfig|${nettools}/bin/ifconfig|' \
src/VBox/HostDrivers/adpctl/VBoxNetAdpCtl.cpp
'' + optionalString headless ''
# Fix compile error in version 6.1.6
substituteInPlace src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-x11-stubs.cpp \
--replace PSHCLFORMATDATA PSHCLFORMATS
'';
# first line: ugly hack, and it isn't yet clear why it's a problem
@ -163,6 +162,9 @@ in stdenv.mkDerivation {
VBOX_WITH_RUNPATH := $out/libexec/virtualbox
VBOX_PATH_APP_PRIVATE := $out/share/virtualbox
VBOX_PATH_APP_DOCS := $out/doc
VBOX_WITH_UPDATE_AGENT :=
${optionalString javaBindings ''
VBOX_JAVA_HOME := ${jdk}
''}
@ -196,14 +198,14 @@ in stdenv.mkDerivation {
-i AutoConfig.kmk
sed -e 's@arch/x86/@@' \
-i Config.kmk
substituteInPlace Config.kmk --replace "VBOX_WITH_TESTCASES = 1" "#"
substituteInPlace Config.kmk --replace-fail "VBOX_WITH_TESTCASES = 1" "#"
'';
enableParallelBuilding = true;
buildPhase = ''
source env.sh
kmk -j $NIX_BUILD_CORES BUILD_TYPE="${buildType}"
kmk -j $NIX_BUILD_CORES BUILD_TYPE="${finalAttrs.buildType}"
'';
installPhase = ''
@ -212,7 +214,7 @@ in stdenv.mkDerivation {
# Install VirtualBox files
mkdir -p "$libexec"
find out/linux.*/${buildType}/bin -mindepth 1 -maxdepth 1 \
find out/linux.*/${finalAttrs.buildType}/bin -mindepth 1 -maxdepth 1 \
-name src -o -exec cp -avt "$libexec" {} +
mkdir -p $out/bin
@ -250,12 +252,12 @@ in stdenv.mkDerivation {
''}
${optionalString withModsrc ''
cp -rv out/linux.*/${buildType}/bin/src "$modsrc"
cp -rv out/linux.*/${finalAttrs.buildType}/bin/src "$modsrc"
''}
mkdir -p "$out/share/virtualbox"
cp -rv src/VBox/Main/UnattendedTemplates "$out/share/virtualbox"
ln -s "${virtualboxGuestAdditionsIso}" "$out/share/virtualbox/VBoxGuestAdditions.iso"
ln -s "${finalAttrs.virtualboxGuestAdditionsIso}" "$out/share/virtualbox/VBoxGuestAdditions.iso"
'';
preFixup = optionalString (!headless) ''
@ -285,10 +287,10 @@ in stdenv.mkDerivation {
fromSource
binaryNativeCode
];
license = licenses.gpl2;
license = lib.licenses.gpl2;
homepage = "https://www.virtualbox.org/";
maintainers = with maintainers; [ sander friedrichaltheide blitz ];
maintainers = with lib.maintainers; [ sander friedrichaltheide blitz ];
platforms = [ "x86_64-linux" ];
mainProgram = "VirtualBox";
};
}
})

View File

@ -1,11 +1,9 @@
{ config, stdenv, kernel, fetchurl, lib, pam, libxslt
, libX11, libXext, libXcursor, libXmu
, glib, alsa-lib, libXrandr, dbus
, glib, libXrandr, dbus, xz
, pkg-config, which, zlib, xorg
, yasm, patchelf, makeWrapper, makeself, nasm
, linuxHeaders, openssl, libpulseaudio}:
with lib;
, yasm, patchelf, makeself
, linuxHeaders, openssl}:
let
buildType = "release";
@ -21,17 +19,21 @@ in stdenv.mkDerivation (finalAttrs: {
env.NIX_CFLAGS_COMPILE = "-Wno-error=incompatible-pointer-types -Wno-error=implicit-function-declaration";
nativeBuildInputs = [ patchelf makeWrapper pkg-config which yasm ];
buildInputs = kernel.moduleBuildDependencies ++ [ libxslt libX11 libXext libXcursor
glib nasm alsa-lib makeself pam libXmu libXrandr linuxHeaders openssl libpulseaudio xorg.xorgserver ];
nativeBuildInputs = [ patchelf pkg-config which yasm makeself xorg.xorgserver openssl linuxHeaders xz ] ++ kernel.moduleBuildDependencies;
buildInputs = [ dbus libxslt libXext libXcursor pam libXmu libXrandr ];
KERN_DIR = "${kernel.dev}/lib/modules/${kernel.modDirVersion}/build";
KERN_INCL = "${kernel.dev}/lib/modules/${kernel.modDirVersion}/source/include";
prePatch = ''
rm -r src/VBox/Additions/x11/x11include/
rm -r src/VBox/Additions/3D/mesa/mesa-*/
rm -r src/libs/openssl-*/
rm -r src/libs/curl-*/
rm -r src/libs/libpng-*/
rm -r src/libs/libxml2-*/
rm -r src/libs/liblzma-*/
rm -r src/libs/zlib*/
'';
patches = [
@ -81,6 +83,10 @@ in stdenv.mkDerivation (finalAttrs: {
VBOX_USE_SYSTEM_XORG_HEADERS := 1
VBOX_USE_SYSTEM_GL_HEADERS := 1
VBOX_NO_LEGACY_XORG_X11 := 1
SDK_VBoxLibPng_INCS :=
SDK_VBoxLibXml2_INCS :=
SDK_VBoxLibLzma_INCS := ${xz.dev}/include
SDK_VBoxLibLzma_LIBS := ${xz.out}/lib
SDK_VBoxOpenSslStatic_INCS := ${openssl.dev}/include/ssl
@ -92,6 +98,9 @@ in stdenv.mkDerivation (finalAttrs: {
VBOX_WITH_GUEST_CONTROL := 1
VBOX_WITHOUT_LINUX_GUEST_PACKAGE := 1
VBOX_WITH_PAM :=
VBOX_WITH_UPDATE_AGENT :=
VBOX_WITH_AUDIO_ALSA :=
VBOX_WITH_AUDIO_PULSE :=
VBOX_BUILD_PUBLISHER := _NixOS
LOCAL_CONFIG

View File

@ -34,16 +34,14 @@ in stdenv.mkDerivation {
env.NIX_CFLAGS_COMPILE = "-Wno-error=incompatible-pointer-types -Wno-error=implicit-function-declaration";
nativeBuildInputs = [ patchelf makeWrapper ];
buildInputs = [ virtualBoxNixGuestAdditionsBuilder ] ++ kernel.moduleBuildDependencies;
nativeBuildInputs = [ patchelf makeWrapper virtualBoxNixGuestAdditionsBuilder ] ++ kernel.moduleBuildDependencies;
buildInputs = [ ];
buildPhase = ''
runHook preBuild
# Build kernel modules.
cd src
find . -type f | xargs sed 's/depmod -a/true/' -i
cd vboxguest-${virtualBoxNixGuestAdditionsBuilder.version}_NixOS
cd src/vboxguest-${virtualBoxNixGuestAdditionsBuilder.version}_NixOS
# Run just make first. If we only did make install, we get symbol warnings during build.
make
cd ../..
@ -61,6 +59,8 @@ in stdenv.mkDerivation {
installPhase = ''
runHook preInstall
mkdir -p $out/bin
# Install kernel modules.
cd src/vboxguest-${virtualBoxNixGuestAdditionsBuilder.version}_NixOS
make install INSTALL_MOD_PATH=$out KBUILD_EXTRA_SYMBOLS=$PWD/vboxsf/Module.symvers
@ -70,7 +70,6 @@ in stdenv.mkDerivation {
install -D -m 755 other/mount.vboxsf $out/bin/mount.vboxsf
install -D -m 755 sbin/VBoxService $out/bin/VBoxService
mkdir -p $out/bin
install -m 755 bin/VBoxClient $out/bin
install -m 755 bin/VBoxControl $out/bin
install -m 755 bin/VBoxDRMClient $out/bin

View File

@ -34,7 +34,9 @@ if [ ! "$oldVersion" = "$latestVersion" ]; then
virtualBoxOldShaSum=$(oldHash ${attr}Extpack)
extpackOldShaSum=$(oldHash ${attr}Extpack)
update-source-version $attr $latestVersion $virtualBoxShaSum
sed -e "s/virtualboxVersion =.*;/virtualboxVersion = \"$latestVersion\";/g" \
-e "s/virtualboxSha256 =.*;/virtualboxSha256 = \"$virtualBoxShaSum\";/g" \
-i $virtualboxNixFile
sed -i -e 's|value = "'$extpackOldShaSum'"|value = "'$extpackShaSum'"|' $extpackNixFile
sed -e "s/sha256 =.*;/sha256 = \"$guestAdditionsIsoShaSum\";/g" \
-i $guestAdditionsIsoNixFile