Merge pull request #179235 from alyssais/virtualbox-test

nixosTests.virtualbox: fix

authored by

Florian Klink and committed by
GitHub
f72ea3ce a1c4db68

+18 -38
+10 -19
nixos/tests/virtualbox.nix
··· 3 pkgs ? import ../.. { inherit system config; }, 4 debug ? false, 5 enableUnfree ? false, 6 - # Nested KVM virtualization (https://www.linux-kvm.org/page/Nested_Guests) 7 - # requires a modprobe flag on the build machine: (kvm-amd for AMD CPUs) 8 - # boot.extraModprobeConfig = "options kvm-intel nested=Y"; 9 - # Without this VirtualBox will use SW virtualization and will only be able 10 - # to run 32-bit guests. 11 - useKvmNestedVirt ? false, 12 - # Whether to run 64-bit guests instead of 32-bit. Requires nested KVM. 13 - use64bitGuest ? false 14 }: 15 - 16 - assert use64bitGuest -> useKvmNestedVirt; 17 18 with import ../lib/testing-python.nix { inherit system pkgs; }; 19 with pkgs.lib; ··· 26 #!${pkgs.runtimeShell} -xe 27 export PATH="${lib.makeBinPath [ pkgs.coreutils pkgs.util-linux ]}" 28 29 - mkdir -p /run/dbus 30 cat > /etc/passwd <<EOF 31 root:x:0:0::/root:/bin/false 32 messagebus:x:1:1::/run/dbus:/bin/false ··· 200 systemd.services."vboxtestlog-${name}@" = { 201 description = "VirtualBox Test Machine Log For ${name}"; 202 serviceConfig.StandardInput = "socket"; 203 serviceConfig.SyslogIdentifier = "GUEST-${name}"; 204 serviceConfig.ExecStart = "${pkgs.coreutils}/bin/cat"; 205 }; ··· 226 227 228 def create_vm_${name}(): 229 vbm("createvm --name ${name} ${createFlags}") 230 vbm("modifyvm ${name} ${vmFlags}") 231 vbm("setextradata ${name} VBoxInternal/PDM/HaltOnReset 1") ··· 233 vbm("storageattach ${name} ${diskFlags}") 234 vbm("sharedfolder add ${name} ${sharedFlags}") 235 vbm("sharedfolder add ${name} ${nixstoreFlags}") 236 - cleanup_${name}() 237 238 ${mkLog "$HOME/VirtualBox VMs/${name}/Logs/VBox.log" "HOST-${name}"} 239 ··· 317 ]; 318 319 dhcpScript = pkgs: '' 320 - ${pkgs.dhcp}/bin/dhclient \ 321 - -lf /run/dhcp.leases \ 322 - -pf /run/dhclient.pid \ 323 - -v eth0 eth1 324 325 otherIP="$(${pkgs.netcat}/bin/nc -l 1234 || :)" 326 ${pkgs.iputils}/bin/ping -I eth1 -c1 "$otherIP" ··· 359 vmConfigs = mapAttrsToList mkVMConf vms; 360 in [ ./common/user-account.nix ./common/x11.nix ] ++ vmConfigs; 361 virtualisation.memorySize = 2048; 362 - virtualisation.qemu.options = 363 - if useKvmNestedVirt then ["-cpu" "kvm64,vmx=on"] else []; 364 virtualisation.virtualbox.host.enable = true; 365 test-support.displayManager.auto.user = "alice"; 366 users.users.alice.extraGroups = let ··· 468 469 headless = '' 470 create_vm_headless() 471 - machine.succeed(ru("VBoxHeadless --startvm headless & disown %1")) 472 wait_for_startup_headless() 473 wait_for_vm_boot_headless() 474 shutdown_vm_headless() ··· 476 ''; 477 478 host-usb-permissions = '' 479 user_usb = remove_uuids(vbm("list usbhost")) 480 print(user_usb, file=sys.stderr) 481 root_usb = remove_uuids(machine.succeed("VBoxManage list usbhost"))
··· 3 pkgs ? import ../.. { inherit system config; }, 4 debug ? false, 5 enableUnfree ? false, 6 + use64bitGuest ? true 7 }: 8 9 with import ../lib/testing-python.nix { inherit system pkgs; }; 10 with pkgs.lib; ··· 17 #!${pkgs.runtimeShell} -xe 18 export PATH="${lib.makeBinPath [ pkgs.coreutils pkgs.util-linux ]}" 19 20 + mkdir -p /run/dbus /var 21 + ln -s /run /var 22 cat > /etc/passwd <<EOF 23 root:x:0:0::/root:/bin/false 24 messagebus:x:1:1::/run/dbus:/bin/false ··· 192 systemd.services."vboxtestlog-${name}@" = { 193 description = "VirtualBox Test Machine Log For ${name}"; 194 serviceConfig.StandardInput = "socket"; 195 + serviceConfig.StandardOutput = "journal"; 196 serviceConfig.SyslogIdentifier = "GUEST-${name}"; 197 serviceConfig.ExecStart = "${pkgs.coreutils}/bin/cat"; 198 }; ··· 219 220 221 def create_vm_${name}(): 222 + cleanup_${name}() 223 vbm("createvm --name ${name} ${createFlags}") 224 vbm("modifyvm ${name} ${vmFlags}") 225 vbm("setextradata ${name} VBoxInternal/PDM/HaltOnReset 1") ··· 227 vbm("storageattach ${name} ${diskFlags}") 228 vbm("sharedfolder add ${name} ${sharedFlags}") 229 vbm("sharedfolder add ${name} ${nixstoreFlags}") 230 231 ${mkLog "$HOME/VirtualBox VMs/${name}/Logs/VBox.log" "HOST-${name}"} 232 ··· 310 ]; 311 312 dhcpScript = pkgs: '' 313 + ${pkgs.dhcpcd}/bin/dhcpcd eth0 eth1 314 315 otherIP="$(${pkgs.netcat}/bin/nc -l 1234 || :)" 316 ${pkgs.iputils}/bin/ping -I eth1 -c1 "$otherIP" ··· 349 vmConfigs = mapAttrsToList mkVMConf vms; 350 in [ ./common/user-account.nix ./common/x11.nix ] ++ vmConfigs; 351 virtualisation.memorySize = 2048; 352 + virtualisation.qemu.options = ["-cpu" "kvm64,svm=on,vmx=on"]; 353 virtualisation.virtualbox.host.enable = true; 354 test-support.displayManager.auto.user = "alice"; 355 users.users.alice.extraGroups = let ··· 457 458 headless = '' 459 create_vm_headless() 460 + machine.succeed(ru("VBoxHeadless --startvm headless >&2 & disown %1")) 461 wait_for_startup_headless() 462 wait_for_vm_boot_headless() 463 shutdown_vm_headless() ··· 465 ''; 466 467 host-usb-permissions = '' 468 + import sys 469 + 470 user_usb = remove_uuids(vbm("list usbhost")) 471 print(user_usb, file=sys.stderr) 472 root_usb = remove_uuids(machine.succeed("VBoxManage list usbhost"))
+8 -19
pkgs/applications/virtualization/virtualbox/guest-additions/default.nix
··· 45 patchFlags = [ "-p1" "-d" "src/vboxguest-${version}" ]; 46 47 unpackPhase = '' 48 - ${if stdenv.hostPlatform.system == "i686-linux" || stdenv.hostPlatform.system == "x86_64-linux" then '' 49 - isoinfo -J -i $src -x /VBoxLinuxAdditions.run > ./VBoxLinuxAdditions.run 50 - chmod 755 ./VBoxLinuxAdditions.run 51 - # 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 52 - sed -i 's/\$leftspace/16383/' VBoxLinuxAdditions.run 53 - ./VBoxLinuxAdditions.run --noexec --keep 54 - '' 55 - else throw ("Architecture: "+stdenv.hostPlatform.system+" not supported for VirtualBox guest additions") 56 - } 57 58 # Unpack files 59 cd install 60 - ${if stdenv.hostPlatform.system == "i686-linux" then '' 61 - tar xfvj VBoxGuestAdditions-x86.tar.bz2 62 - '' 63 - else if stdenv.hostPlatform.system == "x86_64-linux" then '' 64 - tar xfvj VBoxGuestAdditions-amd64.tar.bz2 65 - '' 66 - else throw ("Architecture: "+stdenv.hostPlatform.system+" not supported for VirtualBox guest additions") 67 - } 68 ''; 69 70 buildPhase = '' ··· 158 sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ]; 159 license = "GPL"; 160 maintainers = [ lib.maintainers.sander ]; 161 - platforms = lib.platforms.linux; 162 - broken = kernel.kernelAtLeast "5.17"; 163 }; 164 }
··· 45 patchFlags = [ "-p1" "-d" "src/vboxguest-${version}" ]; 46 47 unpackPhase = '' 48 + isoinfo -J -i $src -x /VBoxLinuxAdditions.run > ./VBoxLinuxAdditions.run 49 + chmod 755 ./VBoxLinuxAdditions.run 50 + # 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 51 + sed -i 's/\$leftspace/16383/' VBoxLinuxAdditions.run 52 + ./VBoxLinuxAdditions.run --noexec --keep 53 54 # Unpack files 55 cd install 56 + tar xfvj VBoxGuestAdditions-${if stdenv.hostPlatform.is32bit then "x86" else "amd64"}.tar.bz2 57 ''; 58 59 buildPhase = '' ··· 147 sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ]; 148 license = "GPL"; 149 maintainers = [ lib.maintainers.sander ]; 150 + platforms = [ "i686-linux" "x86_64-linux" ]; 151 + broken = kernel.kernelAtLeast (if stdenv.hostPlatform.is32bit then "5.10" else "5.17"); 152 }; 153 }