Does anybody have working automatic-resizing in VirtualBox?

For context, I am trying to get this to work on a Windows host. I think this shouldn’t make a difference but don’t know enough about VirtualBox to know.

What I want is that I can resize the VirtualBox window and the desktop size of OS running inside the VM needs to adapt automatically.

  1. This doesn’t work with the usual
    virtualisation.virtualbox.guest.enable = true;
  2. It doesn’t work with the VirtualBox appliance for download here.
  3. Manually installing the guest additions by mounting the .iso does not work on NixOS. I don’t understand NixOS yet but I think it both wants to change things which it is not allowed to change and cannot find some binaries that it expects in default paths.

If anybody has this working I would appreciate some pointers.

There is a bug in the VBoxClient 6.1.6 which has been fixed in 6.1.7 IIRC, though the latter is not yet in nixpkgs.

I’m waiting for the update as well, but don’t have the time to do the PR work on my own currently.

When I’m in the office I might be able to hand out a link to the VBox issue tracker.

2 Likes

Okay, the upstream issue: https://www.virtualbox.org/ticket/19496

@smn you just become unlucky that VirtualBox deprecated VBoxVGA driver in VirtualBox version 6.0.3 (I think).

With new version you need to use VMSVGA driver, unfortunately NixOS needs a fix to work with it, and here it is: https://github.com/NixOS/nixpkgs/pull/86473 but it is hanging there, I guess it needs attention from someone who can merge it.

As a workaround you can just type sudo VBoxClient --vmsvga after starting up. I’m sure there’s a way to include the fix in configuration.nix but I didn’t spent time looking into it myself.

Thanks @takeda!

Since I am fairly new to NixOS: How do I apply the fix locally?

So here’s what I did:

  # TODO: remove me after https://github.com/NixOS/nixpkgs/pull/86473 is applied
  services.xserver.videoDrivers = lib.mkForce [ "vmware" "virtualbox" "modesetting" ];
  systemd.services.virtualbox-resize = {
    description = "VirtualBox Guest Screen Resizing";

    wantedBy = [ "multi-user.target" ];
    requires = [ "dev-vboxguest.device" ];
    after = [ "dev-vboxguest.device" ];

    unitConfig.ConditionVirtualization = "oracle";

    serviceConfig.ExecStart = "@${config.boot.kernelPackages.virtualboxGuestAdditions}/bin/VBoxClient -fv --vmsvga";
  };

You might also modify top of your configuration.nix file and change:

{ config, pkgs, ... }:

into:

{ config, pkgs, lib, ... }:

The first line changes preference to use vmware driver, which is what VMSVGA is using, this will also allow you to enable 3D acceleration option in VirtualBox and make rendering smoother.

The second one is creating a service that would run VBoxClient --vmsvga this will enable screen resizing. Note though that the patch that is waiting (https://github.com/NixOS/nixpkgs/pull/86473) is using xrandr to change screen size, once it is merged those two might conflict with each other and you should remove this from your config.

I like this method, because it seems to work better on my machine, it also resizes the login screen. It looks like it needs to run as root though (maybe there is a way to make it run as unprivileged user). From what I read other OSes also run this as a service so perhaps this is correct approach.

2 Likes

Excellent. This works. In case anybody else is wondering: Yes, this goes in your configuration.nix and yes, the adding of the lib is required.

I’m (apparently) experiencing the same issue on MacOS, so this does indeed appear to be applicable to multiple host systems.

tadeka’s workaround does not appear to work for me, unfortunately

Actually, it does work, but only when also selecting VMSVEGA as the graphics controller in the Virtualbox settings panel of the Virtual Machine.

1 Like