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