virtualbox: add headless build (without Qt dependency) (#18026)

This commit is contained in:
Данило Глинський (Danylo Hlynskyi) 2016-09-01 18:54:58 +00:00 committed by Domen Kožar
parent 8a7afae58b
commit 78cd9f8ebc
4 changed files with 47 additions and 14 deletions

View File

@ -5,7 +5,7 @@ with lib;
let
cfg = config.virtualisation.virtualbox.host;
virtualbox = config.boot.kernelPackages.virtualbox.override {
inherit (cfg) enableHardening;
inherit (cfg) enableHardening headless;
};
in
@ -47,6 +47,15 @@ in
</para></important>
'';
};
headless = mkOption {
type = types.bool;
default = false;
description = ''
Use VirtualBox installation without GUI and Qt dependency. Useful to enable on servers
and when virtual machines are controlled only via SSH.
'';
};
};
config = mkIf cfg.enable (mkMerge [{

View File

@ -314,6 +314,9 @@ let
test2.vmFlags = hostonlyVMFlags;
test2.vmScript = dhcpScript;
headless.virtualisation.virtualbox.headless = true;
headless.services.xserver.enable = false;
};
mkVBoxTest = name: testScript: makeTest {
@ -402,6 +405,14 @@ in mapAttrs mkVBoxTest {
shutdownVM_simple;
'';
headless = ''
createVM_headless;
$machine->succeed(ru("VBoxHeadless --startvm headless & disown %1"));
waitForStartup_headless;
waitForVMBoot_headless;
shutdownVM_headless;
'';
host-usb-permissions = ''
my $userUSB = removeUUIDs vbm("list usbhost");
print STDERR $userUSB;

View File

@ -1,5 +1,6 @@
{ stdenv, fetchurl, lib, iasl, dev86, pam, libxslt, libxml2, libX11, xproto, libXext
, libXcursor, libXmu, qt4, libIDL, SDL, libcap, zlib, libpng, glib, kernel, lvm2
, libXrandr
, which, alsaLib, curl, libvpx, gawk, nettools, dbus
, xorriso, makeself, perl, pkgconfig, nukeReferences
, javaBindings ? false, jdk ? null
@ -7,6 +8,7 @@
, enableExtensionPack ? false, requireFile ? null, patchelf ? null, fakeroot ? null
, pulseSupport ? false, libpulseaudio ? null
, enableHardening ? false
, headless ? false
}:
with stdenv.lib;
@ -67,12 +69,14 @@ in stdenv.mkDerivation {
};
buildInputs =
[ iasl dev86 libxslt libxml2 xproto libX11 libXext libXcursor qt4 libIDL SDL
[ iasl dev86 libxslt libxml2 xproto libX11 libXext libXcursor libIDL
libcap glib lvm2 python alsaLib curl libvpx pam xorriso makeself perl
pkgconfig which libXmu nukeReferences ]
++ optional javaBindings jdk
++ optional pythonBindings python
++ optional pulseSupport libpulseaudio;
++ optional pulseSupport libpulseaudio
++ optionals (headless) [ libXrandr libpng ]
++ optionals (!headless) [ qt4 SDL ];
hardeningDisable = [ "fortify" "pic" "stackprotector" ];
@ -129,7 +133,9 @@ in stdenv.mkDerivation {
''}
LOCAL_CONFIG
./configure --with-qt4-dir=${qt4} \
./configure \
${optionalString headless "--build-headless"} \
${optionalString (!headless) "--with-qt4-dir=${qt4}"} \
${optionalString (!javaBindings) "--disable-java"} \
${optionalString (!pythonBindings) "--disable-python"} \
${optionalString (!pulseSupport) "--disable-pulse"} \
@ -180,16 +186,18 @@ in stdenv.mkDerivation {
EXTHELPER
''}
# Create and fix desktop item
mkdir -p $out/share/applications
sed -i -e "s|Icon=VBox|Icon=$libexec/VBox.png|" $libexec/virtualbox.desktop
ln -sfv $libexec/virtualbox.desktop $out/share/applications
# Icons
mkdir -p $out/share/icons/hicolor
for size in `ls -1 $libexec/icons`; do
mkdir -p $out/share/icons/hicolor/$size/apps
ln -s $libexec/icons/$size/*.png $out/share/icons/hicolor/$size/apps
done
${optionalString (!headless) ''
# Create and fix desktop item
mkdir -p $out/share/applications
sed -i -e "s|Icon=VBox|Icon=$libexec/VBox.png|" $libexec/virtualbox.desktop
ln -sfv $libexec/virtualbox.desktop $out/share/applications
# Icons
mkdir -p $out/share/icons/hicolor
for size in `ls -1 $libexec/icons`; do
mkdir -p $out/share/icons/hicolor/$size/apps
ln -s $libexec/icons/$size/*.png $out/share/icons/hicolor/$size/apps
done
''}
# Get rid of a reference to linux.dev.
nuke-refs $out/lib/modules/*/misc/*.ko

View File

@ -11345,6 +11345,11 @@ in
enableHardening = true;
});
virtualboxHeadless = lowPrio (virtualbox.override {
enableHardening = true;
headless = true;
});
virtualboxGuestAdditions = callPackage ../applications/virtualization/virtualbox/guest-additions { };
wireguard = callPackage ../os-specific/linux/wireguard { };