Merge pull request #179235 from alyssais/virtualbox-test

nixosTests.virtualbox: fix

Changed files
+18 -38
nixos
pkgs
applications
virtualization
virtualbox
guest-additions
+10 -19
nixos/tests/virtualbox.nix
···
pkgs ? import ../.. { inherit system config; },
debug ? false,
enableUnfree ? false,
-
# Nested KVM virtualization (https://www.linux-kvm.org/page/Nested_Guests)
-
# requires a modprobe flag on the build machine: (kvm-amd for AMD CPUs)
-
# boot.extraModprobeConfig = "options kvm-intel nested=Y";
-
# Without this VirtualBox will use SW virtualization and will only be able
-
# to run 32-bit guests.
-
useKvmNestedVirt ? false,
-
# Whether to run 64-bit guests instead of 32-bit. Requires nested KVM.
-
use64bitGuest ? false
}:
-
-
assert use64bitGuest -> useKvmNestedVirt;
with import ../lib/testing-python.nix { inherit system pkgs; };
with pkgs.lib;
···
#!${pkgs.runtimeShell} -xe
export PATH="${lib.makeBinPath [ pkgs.coreutils pkgs.util-linux ]}"
-
mkdir -p /run/dbus
cat > /etc/passwd <<EOF
root:x:0:0::/root:/bin/false
messagebus:x:1:1::/run/dbus:/bin/false
···
systemd.services."vboxtestlog-${name}@" = {
description = "VirtualBox Test Machine Log For ${name}";
serviceConfig.StandardInput = "socket";
serviceConfig.SyslogIdentifier = "GUEST-${name}";
serviceConfig.ExecStart = "${pkgs.coreutils}/bin/cat";
};
···
def create_vm_${name}():
vbm("createvm --name ${name} ${createFlags}")
vbm("modifyvm ${name} ${vmFlags}")
vbm("setextradata ${name} VBoxInternal/PDM/HaltOnReset 1")
···
vbm("storageattach ${name} ${diskFlags}")
vbm("sharedfolder add ${name} ${sharedFlags}")
vbm("sharedfolder add ${name} ${nixstoreFlags}")
-
cleanup_${name}()
${mkLog "$HOME/VirtualBox VMs/${name}/Logs/VBox.log" "HOST-${name}"}
···
];
dhcpScript = pkgs: ''
-
${pkgs.dhcp}/bin/dhclient \
-
-lf /run/dhcp.leases \
-
-pf /run/dhclient.pid \
-
-v eth0 eth1
otherIP="$(${pkgs.netcat}/bin/nc -l 1234 || :)"
${pkgs.iputils}/bin/ping -I eth1 -c1 "$otherIP"
···
vmConfigs = mapAttrsToList mkVMConf vms;
in [ ./common/user-account.nix ./common/x11.nix ] ++ vmConfigs;
virtualisation.memorySize = 2048;
-
virtualisation.qemu.options =
-
if useKvmNestedVirt then ["-cpu" "kvm64,vmx=on"] else [];
virtualisation.virtualbox.host.enable = true;
test-support.displayManager.auto.user = "alice";
users.users.alice.extraGroups = let
···
headless = ''
create_vm_headless()
-
machine.succeed(ru("VBoxHeadless --startvm headless & disown %1"))
wait_for_startup_headless()
wait_for_vm_boot_headless()
shutdown_vm_headless()
···
'';
host-usb-permissions = ''
user_usb = remove_uuids(vbm("list usbhost"))
print(user_usb, file=sys.stderr)
root_usb = remove_uuids(machine.succeed("VBoxManage list usbhost"))
···
pkgs ? import ../.. { inherit system config; },
debug ? false,
enableUnfree ? false,
+
use64bitGuest ? true
}:
with import ../lib/testing-python.nix { inherit system pkgs; };
with pkgs.lib;
···
#!${pkgs.runtimeShell} -xe
export PATH="${lib.makeBinPath [ pkgs.coreutils pkgs.util-linux ]}"
+
mkdir -p /run/dbus /var
+
ln -s /run /var
cat > /etc/passwd <<EOF
root:x:0:0::/root:/bin/false
messagebus:x:1:1::/run/dbus:/bin/false
···
systemd.services."vboxtestlog-${name}@" = {
description = "VirtualBox Test Machine Log For ${name}";
serviceConfig.StandardInput = "socket";
+
serviceConfig.StandardOutput = "journal";
serviceConfig.SyslogIdentifier = "GUEST-${name}";
serviceConfig.ExecStart = "${pkgs.coreutils}/bin/cat";
};
···
def create_vm_${name}():
+
cleanup_${name}()
vbm("createvm --name ${name} ${createFlags}")
vbm("modifyvm ${name} ${vmFlags}")
vbm("setextradata ${name} VBoxInternal/PDM/HaltOnReset 1")
···
vbm("storageattach ${name} ${diskFlags}")
vbm("sharedfolder add ${name} ${sharedFlags}")
vbm("sharedfolder add ${name} ${nixstoreFlags}")
${mkLog "$HOME/VirtualBox VMs/${name}/Logs/VBox.log" "HOST-${name}"}
···
];
dhcpScript = pkgs: ''
+
${pkgs.dhcpcd}/bin/dhcpcd eth0 eth1
otherIP="$(${pkgs.netcat}/bin/nc -l 1234 || :)"
${pkgs.iputils}/bin/ping -I eth1 -c1 "$otherIP"
···
vmConfigs = mapAttrsToList mkVMConf vms;
in [ ./common/user-account.nix ./common/x11.nix ] ++ vmConfigs;
virtualisation.memorySize = 2048;
+
virtualisation.qemu.options = ["-cpu" "kvm64,svm=on,vmx=on"];
virtualisation.virtualbox.host.enable = true;
test-support.displayManager.auto.user = "alice";
users.users.alice.extraGroups = let
···
headless = ''
create_vm_headless()
+
machine.succeed(ru("VBoxHeadless --startvm headless >&2 & disown %1"))
wait_for_startup_headless()
wait_for_vm_boot_headless()
shutdown_vm_headless()
···
'';
host-usb-permissions = ''
+
import sys
+
user_usb = remove_uuids(vbm("list usbhost"))
print(user_usb, file=sys.stderr)
root_usb = remove_uuids(machine.succeed("VBoxManage list usbhost"))
+8 -19
pkgs/applications/virtualization/virtualbox/guest-additions/default.nix
···
patchFlags = [ "-p1" "-d" "src/vboxguest-${version}" ];
unpackPhase = ''
-
${if stdenv.hostPlatform.system == "i686-linux" || stdenv.hostPlatform.system == "x86_64-linux" then ''
-
isoinfo -J -i $src -x /VBoxLinuxAdditions.run > ./VBoxLinuxAdditions.run
-
chmod 755 ./VBoxLinuxAdditions.run
-
# An overflow leads the is-there-enough-space check to fail when there's too much space available, so fake how much space there is
-
sed -i 's/\$leftspace/16383/' VBoxLinuxAdditions.run
-
./VBoxLinuxAdditions.run --noexec --keep
-
''
-
else throw ("Architecture: "+stdenv.hostPlatform.system+" not supported for VirtualBox guest additions")
-
}
# Unpack files
cd install
-
${if stdenv.hostPlatform.system == "i686-linux" then ''
-
tar xfvj VBoxGuestAdditions-x86.tar.bz2
-
''
-
else if stdenv.hostPlatform.system == "x86_64-linux" then ''
-
tar xfvj VBoxGuestAdditions-amd64.tar.bz2
-
''
-
else throw ("Architecture: "+stdenv.hostPlatform.system+" not supported for VirtualBox guest additions")
-
}
'';
buildPhase = ''
···
sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
license = "GPL";
maintainers = [ lib.maintainers.sander ];
-
platforms = lib.platforms.linux;
-
broken = kernel.kernelAtLeast "5.17";
};
}
···
patchFlags = [ "-p1" "-d" "src/vboxguest-${version}" ];
unpackPhase = ''
+
isoinfo -J -i $src -x /VBoxLinuxAdditions.run > ./VBoxLinuxAdditions.run
+
chmod 755 ./VBoxLinuxAdditions.run
+
# An overflow leads the is-there-enough-space check to fail when there's too much space available, so fake how much space there is
+
sed -i 's/\$leftspace/16383/' VBoxLinuxAdditions.run
+
./VBoxLinuxAdditions.run --noexec --keep
# Unpack files
cd install
+
tar xfvj VBoxGuestAdditions-${if stdenv.hostPlatform.is32bit then "x86" else "amd64"}.tar.bz2
'';
buildPhase = ''
···
sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
license = "GPL";
maintainers = [ lib.maintainers.sander ];
+
platforms = [ "i686-linux" "x86_64-linux" ];
+
broken = kernel.kernelAtLeast (if stdenv.hostPlatform.is32bit then "5.10" else "5.17");
};
}