virtualbox: nixfmt

This commit is contained in:
Friedrich Altheide 2024-10-14 06:46:43 +02:00 committed by Friedrich Altheide
parent 2a3b139da1
commit 53b37c99b4
7 changed files with 617 additions and 348 deletions

View File

@ -1,5 +1,10 @@
# Module for VirtualBox guests. # Module for VirtualBox guests.
{ config, lib, pkgs, ... }: {
config,
lib,
pkgs,
...
}:
let let
cfg = config.virtualisation.virtualbox.guest; cfg = config.virtualisation.virtualbox.guest;
kernel = config.boot.kernelPackages; kernel = config.boot.kernelPackages;
@ -28,7 +33,20 @@ let
in in
{ {
imports = [ imports = [
(lib.mkRenamedOptionModule [ "virtualisation" "virtualbox" "guest" "draganddrop" ] [ "virtualisation" "virtualbox" "guest" "dragAndDrop" ]) (lib.mkRenamedOptionModule
[
"virtualisation"
"virtualbox"
"guest"
"draganddrop"
]
[
"virtualisation"
"virtualbox"
"guest"
"dragAndDrop"
]
)
]; ];
options.virtualisation.virtualbox.guest = { options.virtualisation.virtualbox.guest = {
@ -59,12 +77,15 @@ in
###### implementation ###### implementation
config = lib.mkIf cfg.enable (lib.mkMerge [ config = lib.mkIf cfg.enable (
lib.mkMerge [
{
assertions = [
{ {
assertions = [{
assertion = pkgs.stdenv.hostPlatform.isx86; assertion = pkgs.stdenv.hostPlatform.isx86;
message = "Virtualbox not currently supported on ${pkgs.stdenv.hostPlatform.system}"; message = "Virtualbox not currently supported on ${pkgs.stdenv.hostPlatform.system}";
}]; }
];
environment.systemPackages = [ kernel.virtualboxGuestAdditions ]; environment.systemPackages = [ kernel.virtualboxGuestAdditions ];
@ -87,8 +108,7 @@ in
serviceConfig.ExecStart = "@${kernel.virtualboxGuestAdditions}/bin/VBoxService VBoxService --foreground"; serviceConfig.ExecStart = "@${kernel.virtualboxGuestAdditions}/bin/VBoxService VBoxService --foreground";
}; };
services.udev.extraRules = services.udev.extraRules = ''
''
# /dev/vboxuser is necessary for VBoxClient to work. Maybe we # /dev/vboxuser is necessary for VBoxClient to work. Maybe we
# should restrict this to logged-in users. # should restrict this to logged-in users.
KERNEL=="vboxuser", OWNER="root", GROUP="root", MODE="0666" KERNEL=="vboxuser", OWNER="root", GROUP="root", MODE="0666"
@ -99,20 +119,15 @@ in
systemd.user.services.virtualboxClientVmsvga = mkVirtualBoxUserService "--vmsvga-session"; systemd.user.services.virtualboxClientVmsvga = mkVirtualBoxUserService "--vmsvga-session";
} }
( (lib.mkIf cfg.clipboard {
lib.mkIf cfg.clipboard {
systemd.user.services.virtualboxClientClipboard = mkVirtualBoxUserService "--clipboard"; systemd.user.services.virtualboxClientClipboard = mkVirtualBoxUserService "--clipboard";
} })
) (lib.mkIf cfg.seamless {
(
lib.mkIf cfg.seamless {
systemd.user.services.virtualboxClientSeamless = mkVirtualBoxUserService "--seamless"; systemd.user.services.virtualboxClientSeamless = mkVirtualBoxUserService "--seamless";
} })
) (lib.mkIf cfg.dragAndDrop {
(
lib.mkIf cfg.dragAndDrop {
systemd.user.services.virtualboxClientDragAndDrop = mkVirtualBoxUserService "--draganddrop"; systemd.user.services.virtualboxClientDragAndDrop = mkVirtualBoxUserService "--draganddrop";
} })
) ]
]); );
} }

View File

@ -1,9 +1,19 @@
{ config, lib, pkgs, ... }: {
config,
lib,
pkgs,
...
}:
let let
cfg = config.virtualisation.virtualbox.host; cfg = config.virtualisation.virtualbox.host;
virtualbox = cfg.package.override { virtualbox = cfg.package.override {
inherit (cfg) enableHardening headless enableWebService enableKvm; inherit (cfg)
enableHardening
headless
enableWebService
enableKvm
;
extensionPack = if cfg.enableExtensionPack then pkgs.virtualboxExtpack else null; extensionPack = if cfg.enableExtensionPack then pkgs.virtualboxExtpack else null;
}; };
@ -93,93 +103,119 @@ in
}; };
}; };
config = lib.mkIf cfg.enable (lib.mkMerge [{ config = lib.mkIf cfg.enable (
warnings = lib.mkIf (pkgs.config.virtualbox.enableExtensionPack or false) lib.mkMerge [
["'nixpkgs.virtualbox.enableExtensionPack' has no effect, please use 'virtualisation.virtualbox.host.enableExtensionPack'"]; {
warnings = lib.mkIf (pkgs.config.virtualbox.enableExtensionPack or false) [
"'nixpkgs.virtualbox.enableExtensionPack' has no effect, please use 'virtualisation.virtualbox.host.enableExtensionPack'"
];
environment.systemPackages = [ virtualbox ]; environment.systemPackages = [ virtualbox ];
security.wrappers = let security.wrappers =
let
mkSuid = program: { mkSuid = program: {
source = "${virtualbox}/libexec/virtualbox/${program}"; source = "${virtualbox}/libexec/virtualbox/${program}";
owner = "root"; owner = "root";
group = "vboxusers"; group = "vboxusers";
setuid = true; setuid = true;
}; };
executables = [ executables =
[
"VBoxHeadless" "VBoxHeadless"
"VBoxNetAdpCtl" "VBoxNetAdpCtl"
"VBoxNetDHCP" "VBoxNetDHCP"
"VBoxNetNAT" "VBoxNetNAT"
"VBoxVolInfo" "VBoxVolInfo"
] ++ (lib.optionals (!cfg.headless) [ ]
++ (lib.optionals (!cfg.headless) [
"VBoxSDL" "VBoxSDL"
"VirtualBoxVM" "VirtualBoxVM"
]); ]);
in lib.mkIf cfg.enableHardening in
(builtins.listToAttrs (map (x: { name = x; value = mkSuid x; }) executables)); lib.mkIf cfg.enableHardening (
builtins.listToAttrs (
map (x: {
name = x;
value = mkSuid x;
}) executables
)
);
users.groups.vboxusers.gid = config.ids.gids.vboxusers; users.groups.vboxusers.gid = config.ids.gids.vboxusers;
services.udev.extraRules = services.udev.extraRules = ''
''
SUBSYSTEM=="usb_device", ACTION=="add", RUN+="${virtualbox}/libexec/virtualbox/VBoxCreateUSBNode.sh $major $minor $attr{bDeviceClass}" SUBSYSTEM=="usb_device", ACTION=="add", RUN+="${virtualbox}/libexec/virtualbox/VBoxCreateUSBNode.sh $major $minor $attr{bDeviceClass}"
SUBSYSTEM=="usb", ACTION=="add", ENV{DEVTYPE}=="usb_device", RUN+="${virtualbox}/libexec/virtualbox/VBoxCreateUSBNode.sh $major $minor $attr{bDeviceClass}" SUBSYSTEM=="usb", ACTION=="add", ENV{DEVTYPE}=="usb_device", RUN+="${virtualbox}/libexec/virtualbox/VBoxCreateUSBNode.sh $major $minor $attr{bDeviceClass}"
SUBSYSTEM=="usb_device", ACTION=="remove", RUN+="${virtualbox}/libexec/virtualbox/VBoxCreateUSBNode.sh --remove $major $minor" SUBSYSTEM=="usb_device", ACTION=="remove", RUN+="${virtualbox}/libexec/virtualbox/VBoxCreateUSBNode.sh --remove $major $minor"
SUBSYSTEM=="usb", ACTION=="remove", ENV{DEVTYPE}=="usb_device", RUN+="${virtualbox}/libexec/virtualbox/VBoxCreateUSBNode.sh --remove $major $minor" SUBSYSTEM=="usb", ACTION=="remove", ENV{DEVTYPE}=="usb_device", RUN+="${virtualbox}/libexec/virtualbox/VBoxCreateUSBNode.sh --remove $major $minor"
''; '';
} (lib.mkIf cfg.enableKvm { }
(lib.mkIf cfg.enableKvm {
assertions = [ assertions = [
{ {
assertion = !cfg.addNetworkInterface; assertion = !cfg.addNetworkInterface;
message = "VirtualBox KVM only supports standard NAT networking for VMs. Please turn off virtualisation.virtualbox.host.addNetworkInterface."; message = "VirtualBox KVM only supports standard NAT networking for VMs. Please turn off virtualisation.virtualbox.host.addNetworkInterface.";
} }
]; ];
}) (lib.mkIf (!cfg.enableKvm) { })
boot.kernelModules = [ "vboxdrv" "vboxnetadp" "vboxnetflt" ]; (lib.mkIf (!cfg.enableKvm) {
boot.kernelModules = [
"vboxdrv"
"vboxnetadp"
"vboxnetflt"
];
boot.extraModulePackages = [ kernelModules ]; boot.extraModulePackages = [ kernelModules ];
services.udev.extraRules = services.udev.extraRules = ''
''
KERNEL=="vboxdrv", OWNER="root", GROUP="vboxusers", MODE="0660", TAG+="systemd" KERNEL=="vboxdrv", OWNER="root", GROUP="vboxusers", MODE="0660", TAG+="systemd"
KERNEL=="vboxdrvu", OWNER="root", GROUP="root", MODE="0666", TAG+="systemd" KERNEL=="vboxdrvu", OWNER="root", GROUP="root", MODE="0666", TAG+="systemd"
KERNEL=="vboxnetctl", OWNER="root", GROUP="vboxusers", MODE="0660", TAG+="systemd" KERNEL=="vboxnetctl", OWNER="root", GROUP="vboxusers", MODE="0660", TAG+="systemd"
''; '';
# Since we lack the right setuid/setcap binaries, set up a host-only network by default. # Since we lack the right setuid/setcap binaries, set up a host-only network by default.
}) (lib.mkIf cfg.addNetworkInterface { })
systemd.services.vboxnet0 = (lib.mkIf cfg.addNetworkInterface {
{ description = "VirtualBox vboxnet0 Interface"; systemd.services.vboxnet0 = {
description = "VirtualBox vboxnet0 Interface";
requires = [ "dev-vboxnetctl.device" ]; requires = [ "dev-vboxnetctl.device" ];
after = [ "dev-vboxnetctl.device" ]; after = [ "dev-vboxnetctl.device" ];
wantedBy = [ "network.target" "sys-subsystem-net-devices-vboxnet0.device" ]; wantedBy = [
"network.target"
"sys-subsystem-net-devices-vboxnet0.device"
];
path = [ virtualbox ]; path = [ virtualbox ];
serviceConfig.RemainAfterExit = true; serviceConfig.RemainAfterExit = true;
serviceConfig.Type = "oneshot"; serviceConfig.Type = "oneshot";
serviceConfig.PrivateTmp = true; serviceConfig.PrivateTmp = true;
environment.VBOX_USER_HOME = "/tmp"; environment.VBOX_USER_HOME = "/tmp";
script = script = ''
''
if ! [ -e /sys/class/net/vboxnet0 ]; then if ! [ -e /sys/class/net/vboxnet0 ]; then
VBoxManage hostonlyif create VBoxManage hostonlyif create
cat /tmp/VBoxSVC.log >&2 cat /tmp/VBoxSVC.log >&2
fi fi
''; '';
postStop = postStop = ''
''
VBoxManage hostonlyif remove vboxnet0 VBoxManage hostonlyif remove vboxnet0
''; '';
}; };
networking.interfaces.vboxnet0.ipv4.addresses = [{ address = "192.168.56.1"; prefixLength = 24; }]; networking.interfaces.vboxnet0.ipv4.addresses = [
{
address = "192.168.56.1";
prefixLength = 24;
}
];
# Make sure NetworkManager won't assume this interface being up # Make sure NetworkManager won't assume this interface being up
# means we have internet access. # means we have internet access.
networking.networkmanager.unmanaged = [ "vboxnet0" ]; networking.networkmanager.unmanaged = [ "vboxnet0" ];
}) (lib.mkIf config.networking.useNetworkd { })
(lib.mkIf config.networking.useNetworkd {
systemd.network.networks."40-vboxnet0".extraConfig = '' systemd.network.networks."40-vboxnet0".extraConfig = ''
[Link] [Link]
RequiredForOnline=no RequiredForOnline=no
''; '';
}) })
]); ]
);
} }

View File

@ -1,25 +1,74 @@
{ config, stdenv, fetchurl, fetchpatch, callPackage, lib, acpica-tools, dev86, pam, libxslt, libxml2, wrapQtAppsHook {
, libX11, xorgproto, libXext, libXcursor, libXmu, libIDL, SDL2, libcap, libGL, libGLU config,
, libpng, glib, lvm2, libXrandr, libXinerama, libopus, libtpms, qtbase, qtx11extras stdenv,
, qttools, qtsvg, qtwayland, pkg-config, which, docbook_xsl, docbook_xml_dtd_43 fetchurl,
, alsa-lib, curl, libvpx, nettools, dbus, substituteAll, gsoap, zlib, xz fetchpatch,
, yasm, glslang callPackage,
, nixosTests lib,
acpica-tools,
dev86,
pam,
libxslt,
libxml2,
wrapQtAppsHook,
libX11,
xorgproto,
libXext,
libXcursor,
libXmu,
libIDL,
SDL2,
libcap,
libGL,
libGLU,
libpng,
glib,
lvm2,
libXrandr,
libXinerama,
libopus,
libtpms,
qtbase,
qtx11extras,
qttools,
qtsvg,
qtwayland,
pkg-config,
which,
docbook_xsl,
docbook_xml_dtd_43,
alsa-lib,
curl,
libvpx,
nettools,
dbus,
substituteAll,
gsoap,
zlib,
xz,
yasm,
glslang,
nixosTests,
# If open-watcom-bin is not passed, VirtualBox will fall back to use # If open-watcom-bin is not passed, VirtualBox will fall back to use
# the shipped alternative sources (assembly). # the shipped alternative sources (assembly).
, open-watcom-bin open-watcom-bin,
, makeself, perl makeself,
, vulkan-loader perl,
, javaBindings ? true, jdk # Almost doesn't affect closure size vulkan-loader,
, pythonBindings ? false, python3 javaBindings ? true,
, extensionPack ? null, fakeroot jdk, # Almost doesn't affect closure size
, pulseSupport ? config.pulseaudio or stdenv.hostPlatform.isLinux, libpulseaudio pythonBindings ? false,
, enableHardening ? false python3,
, headless ? false extensionPack ? null,
, enable32bitGuests ? true fakeroot,
, enableWebService ? false pulseSupport ? config.pulseaudio or stdenv.hostPlatform.isLinux,
, enableKvm ? false libpulseaudio,
, extraConfigureFlags ? "" enableHardening ? false,
headless ? false,
enable32bitGuests ? true,
enableWebService ? false,
enableKvm ? false,
extraConfigureFlags ? "",
}: }:
# The web services use Java infrastructure. # The web services use Java infrastructure.
@ -41,12 +90,26 @@ let
virtualboxGuestAdditionsIso = callPackage guest-additions-iso/default.nix { }; virtualboxGuestAdditionsIso = callPackage guest-additions-iso/default.nix { };
inherit (lib) optional optionals optionalString getDev getLib; inherit (lib)
in stdenv.mkDerivation (finalAttrs: { optional
optionals
optionalString
getDev
getLib
;
in
stdenv.mkDerivation (finalAttrs: {
pname = "virtualbox"; pname = "virtualbox";
version = finalAttrs.virtualboxVersion; version = finalAttrs.virtualboxVersion;
inherit buildType virtualboxVersion virtualboxSha256 kvmPatchVersion kvmPatchHash virtualboxGuestAdditionsIso; inherit
buildType
virtualboxVersion
virtualboxSha256
kvmPatchVersion
kvmPatchHash
virtualboxGuestAdditionsIso
;
src = fetchurl { src = fetchurl {
url = "https://download.virtualbox.org/virtualbox/${finalAttrs.virtualboxVersion}/VirtualBox-${finalAttrs.virtualboxVersion}.tar.bz2"; url = "https://download.virtualbox.org/virtualbox/${finalAttrs.virtualboxVersion}/VirtualBox-${finalAttrs.virtualboxVersion}.tar.bz2";
@ -55,39 +118,84 @@ in stdenv.mkDerivation (finalAttrs: {
outputs = [ "out" ] ++ optional withModsrc "modsrc"; outputs = [ "out" ] ++ optional withModsrc "modsrc";
nativeBuildInputs = [ pkg-config which docbook_xsl docbook_xml_dtd_43 yasm glslang ] nativeBuildInputs = [
++ optional (!headless) wrapQtAppsHook; pkg-config
which
docbook_xsl
docbook_xml_dtd_43
yasm
glslang
] ++ optional (!headless) wrapQtAppsHook;
# Wrap manually because we wrap just a small number of executables. # Wrap manually because we wrap just a small number of executables.
dontWrapQtApps = true; dontWrapQtApps = true;
buildInputs = [ buildInputs =
acpica-tools dev86 libxslt libxml2 xorgproto libX11 libXext libXcursor libIDL [
libcap glib lvm2 alsa-lib curl libvpx pam makeself perl acpica-tools
libXmu libXrandr libpng libopus libtpms python3 xz ] dev86
libxslt
libxml2
xorgproto
libX11
libXext
libXcursor
libIDL
libcap
glib
lvm2
alsa-lib
curl
libvpx
pam
makeself
perl
libXmu
libXrandr
libpng
libopus
libtpms
python3
xz
]
++ optional javaBindings jdk ++ optional javaBindings jdk
++ optional pythonBindings python3 # Python is needed even when not building bindings ++ optional pythonBindings python3 # Python is needed even when not building bindings
++ optional pulseSupport libpulseaudio ++ optional pulseSupport libpulseaudio
++ optionals headless [ libGL ] ++ optionals headless [ libGL ]
++ optionals (!headless) [ qtbase qtx11extras libXinerama SDL2 libGLU ] ++ optionals (!headless) [
++ optionals enableWebService [ gsoap zlib ]; qtbase
qtx11extras
libXinerama
SDL2
libGLU
]
++ optionals enableWebService [
gsoap
zlib
];
hardeningDisable = [ "format" "fortify" "pic" "stackprotector" ]; hardeningDisable = [
"format"
"fortify"
"pic"
"stackprotector"
];
prePatch = '' prePatch = ''
set -x set -x
sed -e 's@MKISOFS --version@MKISOFS -version@' \ sed -e 's@MKISOFS --version@MKISOFS -version@' \
-e 's@PYTHONDIR=.*@PYTHONDIR=${optionalString pythonBindings python3}@' \ -e 's@PYTHONDIR=.*@PYTHONDIR=${optionalString pythonBindings python3}@' \
-e 's@CXX_FLAGS="\(.*\)"@CXX_FLAGS="-std=c++11 \1"@' \ -e 's@CXX_FLAGS="\(.*\)"@CXX_FLAGS="-std=c++11 \1"@' \
${optionalString (!headless) '' ${
optionalString (!headless) ''
-e 's@TOOLQT5BIN=.*@TOOLQT5BIN="${getDev qtbase}/bin"@' \ -e 's@TOOLQT5BIN=.*@TOOLQT5BIN="${getDev qtbase}/bin"@' \
''} -i configure ''
} -i configure
ls kBuild/bin/linux.x86/k* tools/linux.x86/bin/* | xargs -n 1 patchelf --set-interpreter ${stdenv.cc.libc}/lib/ld-linux.so.2 ls kBuild/bin/linux.x86/k* tools/linux.x86/bin/* | xargs -n 1 patchelf --set-interpreter ${stdenv.cc.libc}/lib/ld-linux.so.2
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 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
grep 'libpulse\.so\.0' src include -rI --files-with-match | xargs sed -i -e ' grep 'libpulse\.so\.0' src include -rI --files-with-match | xargs sed -i -e '
${optionalString pulseSupport ${optionalString pulseSupport ''s@"libpulse\.so\.0"@"${libpulseaudio.out}/lib/libpulse.so.0"@g''}'
''s@"libpulse\.so\.0"@"${libpulseaudio.out}/lib/libpulse.so.0"@g''}'
grep 'libdbus-1\.so\.3' src include -rI --files-with-match | xargs sed -i -e ' grep 'libdbus-1\.so\.3' src include -rI --files-with-match | xargs sed -i -e '
s@"libdbus-1\.so\.3"@"${dbus.lib}/lib/libdbus-1.so.3"@g' s@"libdbus-1\.so\.3"@"${dbus.lib}/lib/libdbus-1.so.3"@g'
@ -102,13 +210,15 @@ in stdenv.mkDerivation (finalAttrs: {
patches = patches =
optional enableHardening ./hardened.patch optional enableHardening ./hardened.patch
# Since VirtualBox 7.0.8, VBoxSDL requires SDL2, but the build framework uses SDL1 # Since VirtualBox 7.0.8, VBoxSDL requires SDL2, but the build framework uses SDL1
++ optionals (!headless) [ ./fix-sdl.patch ++ optionals (!headless) [
./fix-sdl.patch
# No update patch disables check for update function # No update patch disables check for update function
# https://bugs.launchpad.net/ubuntu/+source/virtualbox-ose/+bug/272212 # https://bugs.launchpad.net/ubuntu/+source/virtualbox-ose/+bug/272212
(fetchpatch { (fetchpatch {
url = "https://salsa.debian.org/pkg-virtualbox-team/virtualbox/-/raw/debian/7.0.14-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="; hash = "sha256-UJHpuB6QB/BbxJorlqZXUF12lgq8gbLMRHRMsbyqRpY=";
})] })
]
++ [ ./extra_symbols.patch ] ++ [ ./extra_symbols.patch ]
# When hardening is enabled, we cannot use wrapQtApp to ensure that VirtualBoxVM sees # When hardening is enabled, we cannot use wrapQtApp to ensure that VirtualBoxVM sees
# the correct environment variables needed for Qt to work, specifically QT_PLUGIN_PATH. # the correct environment variables needed for Qt to work, specifically QT_PLUGIN_PATH.
@ -213,7 +323,9 @@ in stdenv.mkDerivation (finalAttrs: {
-name src -o -exec cp -avt "$libexec" {} + -name src -o -exec cp -avt "$libexec" {} +
mkdir -p $out/bin mkdir -p $out/bin
for file in ${optionalString (!headless) "VirtualBox VBoxSDL"} ${optionalString enableWebService "vboxwebsrv"} VBoxManage VBoxBalloonCtrl VBoxHeadless; do for file in ${
optionalString (!headless) "VirtualBox VBoxSDL"
} ${optionalString enableWebService "vboxwebsrv"} VBoxManage VBoxBalloonCtrl VBoxHeadless; do
echo "Linking $file to /bin" echo "Linking $file to /bin"
test -x "$libexec/$file" test -x "$libexec/$file"
ln -s "$libexec/$file" $out/bin/$file ln -s "$libexec/$file" $out/bin/$file
@ -255,7 +367,8 @@ in stdenv.mkDerivation (finalAttrs: {
ln -s "${finalAttrs.virtualboxGuestAdditionsIso}" "$out/share/virtualbox/VBoxGuestAdditions.iso" ln -s "${finalAttrs.virtualboxGuestAdditionsIso}" "$out/share/virtualbox/VBoxGuestAdditions.iso"
''; '';
preFixup = optionalString (!headless) '' preFixup =
optionalString (!headless) ''
wrapQtApp $out/bin/VirtualBox wrapQtApp $out/bin/VirtualBox
'' ''
# If hardening is disabled, wrap the VirtualBoxVM binary instead of patching # If hardening is disabled, wrap the VirtualBoxVM binary instead of patching
@ -285,7 +398,11 @@ in stdenv.mkDerivation (finalAttrs: {
]; ];
license = lib.licenses.gpl2; license = lib.licenses.gpl2;
homepage = "https://www.virtualbox.org/"; homepage = "https://www.virtualbox.org/";
maintainers = with lib.maintainers; [ sander friedrichaltheide blitz ]; maintainers = with lib.maintainers; [
sander
friedrichaltheide
blitz
];
platforms = [ "x86_64-linux" ]; platforms = [ "x86_64-linux" ];
mainProgram = "VirtualBox"; mainProgram = "VirtualBox";
}; };

View File

@ -1,4 +1,8 @@
{ fetchurl, lib, virtualbox }: {
fetchurl,
lib,
virtualbox,
}:
let let
inherit (virtualbox) version; inherit (virtualbox) version;
in in
@ -9,14 +13,20 @@ fetchurl rec {
# Manually sha256sum the extensionPack file, must be hex! # Manually sha256sum the extensionPack file, must be hex!
# Thus do not use `nix-prefetch-url` but instead plain old `sha256sum`. # Thus do not use `nix-prefetch-url` but instead plain old `sha256sum`.
# Checksums can also be found at https://www.virtualbox.org/download/hashes/${version}/SHA256SUMS # Checksums can also be found at https://www.virtualbox.org/download/hashes/${version}/SHA256SUMS
let value = "d750fb17688d70e0cb2d7b06f1ad3a661303793f4d1ac39cfa9a54806b89da25"; let
in assert (builtins.stringLength value) == 64; value; value = "d750fb17688d70e0cb2d7b06f1ad3a661303793f4d1ac39cfa9a54806b89da25";
in
assert (builtins.stringLength value) == 64;
value;
meta = with lib; { meta = with lib; {
description = "Oracle Extension pack for VirtualBox"; description = "Oracle Extension pack for VirtualBox";
license = licenses.virtualbox-puel; license = licenses.virtualbox-puel;
homepage = "https://www.virtualbox.org/"; homepage = "https://www.virtualbox.org/";
maintainers = with maintainers; [ sander friedrichaltheide ]; maintainers = with maintainers; [
sander
friedrichaltheide
];
platforms = [ "x86_64-linux" ]; platforms = [ "x86_64-linux" ];
}; };
} }

View File

@ -1,4 +1,8 @@
{ fetchurl, lib, virtualbox}: {
fetchurl,
lib,
virtualbox,
}:
let let
inherit (virtualbox) version; inherit (virtualbox) version;
@ -13,7 +17,13 @@ fetchurl {
''; '';
sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ]; sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
license = lib.licenses.gpl2; license = lib.licenses.gpl2;
maintainers = [ lib.maintainers.sander lib.maintainers.friedrichaltheide ]; maintainers = [
platforms = [ "i686-linux" "x86_64-linux" ]; lib.maintainers.sander
lib.maintainers.friedrichaltheide
];
platforms = [
"i686-linux"
"x86_64-linux"
];
}; };
} }

View File

@ -1,14 +1,32 @@
{ stdenv, kernel, fetchurl, lib, pam, libxslt {
, libXext, libXcursor, libXmu stdenv,
, glib, libXrandr, dbus, xz kernel,
, pkg-config, which, xorg fetchurl,
, yasm, patchelf, makeself lib,
, linuxHeaders, openssl}: pam,
libxslt,
libXext,
libXcursor,
libXmu,
glib,
libXrandr,
dbus,
xz,
pkg-config,
which,
xorg,
yasm,
patchelf,
makeself,
linuxHeaders,
openssl,
}:
let let
buildType = "release"; buildType = "release";
in stdenv.mkDerivation (finalAttrs: { in
stdenv.mkDerivation (finalAttrs: {
pname = "VirtualBox-GuestAdditions-builder-${kernel.version}"; pname = "VirtualBox-GuestAdditions-builder-${kernel.version}";
version = "7.0.20"; version = "7.0.20";
@ -19,8 +37,26 @@ in stdenv.mkDerivation (finalAttrs: {
env.NIX_CFLAGS_COMPILE = "-Wno-error=incompatible-pointer-types -Wno-error=implicit-function-declaration"; env.NIX_CFLAGS_COMPILE = "-Wno-error=incompatible-pointer-types -Wno-error=implicit-function-declaration";
nativeBuildInputs = [ patchelf pkg-config which yasm makeself xorg.xorgserver openssl linuxHeaders xz ] ++ kernel.moduleBuildDependencies; nativeBuildInputs = [
buildInputs = [ dbus libxslt libXext libXcursor pam libXmu libXrandr ]; 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_DIR = "${kernel.dev}/lib/modules/${kernel.modDirVersion}/build";
KERN_INCL = "${kernel.dev}/lib/modules/${kernel.modDirVersion}/source/include"; KERN_INCL = "${kernel.dev}/lib/modules/${kernel.modDirVersion}/source/include";
@ -130,7 +166,11 @@ in stdenv.mkDerivation (finalAttrs: {
runHook preInstall runHook preInstall
mkdir -p $out mkdir -p $out
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/ 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/
runHook postInstall runHook postInstall
''; '';

View File

@ -1,5 +1,13 @@
{ stdenv, kernel, callPackage, lib, dbus {
, xorg, zlib, patchelf, makeWrapper stdenv,
kernel,
callPackage,
lib,
dbus,
xorg,
zlib,
patchelf,
makeWrapper,
}: }:
let let
virtualBoxNixGuestAdditionsBuilder = callPackage ./builder.nix { }; virtualBoxNixGuestAdditionsBuilder = callPackage ./builder.nix { };
@ -12,15 +20,27 @@ let
# dlopen are found. We grep binaries for specific library names and patch # dlopen are found. We grep binaries for specific library names and patch
# RUNPATH in matching binaries to contain the needed library paths. # RUNPATH in matching binaries to contain the needed library paths.
dlopenLibs = [ dlopenLibs = [
{ name = "libdbus-1.so"; pkg = dbus; } {
{ name = "libXfixes.so"; pkg = xorg.libXfixes; } name = "libdbus-1.so";
{ name = "libXrandr.so"; pkg = xorg.libXrandr; } pkg = dbus;
}
{
name = "libXfixes.so";
pkg = xorg.libXfixes;
}
{
name = "libXrandr.so";
pkg = xorg.libXrandr;
}
]; ];
in stdenv.mkDerivation { in
stdenv.mkDerivation {
pname = "VirtualBox-GuestAdditions"; pname = "VirtualBox-GuestAdditions";
version = "${virtualBoxNixGuestAdditionsBuilder.version}-${kernel.version}"; version = "${virtualBoxNixGuestAdditionsBuilder.version}-${kernel.version}";
src = "${virtualBoxNixGuestAdditionsBuilder}/VBoxGuestAdditions-${if stdenv.hostPlatform.is32bit then "x86" else "amd64"}.tar.bz2"; src = "${virtualBoxNixGuestAdditionsBuilder}/VBoxGuestAdditions-${
if stdenv.hostPlatform.is32bit then "x86" else "amd64"
}.tar.bz2";
sourceRoot = "."; sourceRoot = ".";
KERN_DIR = "${kernel.dev}/lib/modules/${kernel.modDirVersion}/build"; KERN_DIR = "${kernel.dev}/lib/modules/${kernel.modDirVersion}/build";
@ -30,7 +50,11 @@ in stdenv.mkDerivation {
env.NIX_CFLAGS_COMPILE = "-Wno-error=incompatible-pointer-types -Wno-error=implicit-function-declaration"; env.NIX_CFLAGS_COMPILE = "-Wno-error=incompatible-pointer-types -Wno-error=implicit-function-declaration";
nativeBuildInputs = [ patchelf makeWrapper virtualBoxNixGuestAdditionsBuilder ] ++ kernel.moduleBuildDependencies; nativeBuildInputs = [
patchelf
makeWrapper
virtualBoxNixGuestAdditionsBuilder
] ++ kernel.moduleBuildDependencies;
buildPhase = '' buildPhase = ''
runHook preBuild runHook preBuild
@ -44,8 +68,19 @@ in stdenv.mkDerivation {
# Change the interpreter for various binaries # Change the interpreter for various binaries
for i in sbin/VBoxService bin/{VBoxClient,VBoxControl,VBoxDRMClient} other/mount.vboxsf; do for i in sbin/VBoxService bin/{VBoxClient,VBoxControl,VBoxDRMClient} other/mount.vboxsf; do
patchelf --set-interpreter ${stdenv.cc.bintools.dynamicLinker} $i patchelf --set-interpreter ${stdenv.cc.bintools.dynamicLinker} $i
patchelf --set-rpath ${lib.makeLibraryPath [ stdenv.cc.cc stdenv.cc.libc zlib patchelf --set-rpath ${
xorg.libX11 xorg.libXt xorg.libXext xorg.libXmu xorg.libXfixes xorg.libXcursor ]} $i lib.makeLibraryPath [
stdenv.cc.cc
stdenv.cc.libc
zlib
xorg.libX11
xorg.libXt
xorg.libXext
xorg.libXmu
xorg.libXfixes
xorg.libXcursor
]
} $i
done done
runHook postBuild runHook postBuild
@ -100,8 +135,14 @@ in stdenv.mkDerivation {
''; '';
sourceProvenance = with lib.sourceTypes; [ fromSource ]; sourceProvenance = with lib.sourceTypes; [ fromSource ];
license = lib.licenses.gpl2; license = lib.licenses.gpl2;
maintainers = [ lib.maintainers.sander lib.maintainers.friedrichaltheide ]; maintainers = [
platforms = [ "i686-linux" "x86_64-linux" ]; lib.maintainers.sander
lib.maintainers.friedrichaltheide
];
platforms = [
"i686-linux"
"x86_64-linux"
];
broken = stdenv.hostPlatform.is32bit && (kernel.kernelAtLeast "5.10"); broken = stdenv.hostPlatform.is32bit && (kernel.kernelAtLeast "5.10");
}; };
} }