NixOS with i3 as Virtualbox guest does not resize to fit the window

I have enable the guest additions and they seem to be running. Resizing the window has no effect, though. I have not tried using i3 in a VM before so it might also be an i3 issue. Any suggestions?

I have just tried switching to Plasma but there is no resizing with that either. What am I missing guys? :slight_smile:

Possibly try using xrandr? But I think I have resizing from Windows running NixOS in a Virtualbox, so perhaps it’s a host problem

This could also be caused by a lack of virtual video memory. Does increasing it in the VM settings help?

I doubt it since it works in another VM but I will try.

And I will try using xrandr as well.

Strangely, I can change the resolution with xrandr and make the screen bigger but it immediately switches back. It seems like some background service is changing it back.

Does anybody know if this is still useful:
https://gist.github.com/cleverca22/85f6d2cd680139f7c6c8b6c2844cb132

It’s fairly old.

This seems outdated.

A regular NixOS config containing

virtualisation.virtualbox.guest.enable = true;
services.xserver = {
  enable = true;
  desktopManager.default = "none";
  windowManager.default = "i3";
  windowManager.i3.enable = true;
  displayManager.lightdm.enable = true;
}

should work fine out of the box with all recent versions of NixOS and VirtualBox.

I’m using something similar and resizing is working normally.

I’ve thrown in an extra ; after the closing } and tried your config. :slight_smile:
Unfortunately it didn’t work. I am still on Virtualbox 6.0.14 so I will try with 6.1.

I’ve tried with Virtualbox 6.1.2 and it still does not work.
@earvstedt would you mind trying with a vanilla install?
Or do you have any ideas what kind of things I might lack that could be causing this?

The following works on my system:
NixOS 19.09, rev f6dac8083874408fe287525007d3da9decd9bf44
VirtualBox 6.0.12r132055
I’m also running a similar setup on Windows with VirtualBox 5.2.

Step 1

Enable VirtualBox on the host system.

virtualisation.virtualbox.host.enable = true;

Step 2

Build VirtualBox Image.

vm=$(nix-build --no-out-link - <<'EOF'
(import <nixpkgs/nixos> {
configuration = { lib, ... }: with lib; {
  imports = [ <nixpkgs/nixos/modules/virtualisation/virtualbox-image.nix> ];
  boot.loader.timeout = 1;
  users.users.root.password = "a";
  users.users.me.isNormalUser = true;
  services.mingetty.autologinUser = "me";
  services.openssh = {
    enable = true;
    permitRootLogin = "yes";
  };
  virtualisation.virtualbox.guest.enable = true;
  services.xserver = {
    enable = true;
    desktopManager.default = "none";
    windowManager.default = "i3";
    windowManager.i3.enable = true;
    displayManager.lightdm = {
      enable = true;
      autoLogin.enable = true;
      autoLogin.user = "me";
    };
  };
};
}).config.system.build.virtualBoxOVA
EOF
)

Step 3

Import and run VM.

# Import VM. --unit 8 --ignore is for disabling USB which
# needs the vbox extension pack (https://github.com/NixOS/nixpkgs/issues/34796)
VBoxManage import $vm/*.ova --vsys 0 --vmname vbox-resize-test --unit 8 --ignore
VBoxManage startvm vbox-resize-test

# Now test resizing...

# Delete
VBoxManage controlvm vbox-resize-test poweroff
VBoxManage unregistervm vbox-resize-test --delete

Hey, this is really cool! Thanks for putting it here!

I will try to copy that configuration during the normal installation process since I am using a windows host.

Unfortunately. no luck again.

@earvstedt Is this normal:

$ lsmod | grep -i vbox
vboxsf                86016  0
vboxguest            299008  5 vboxsf

Desperation level: trying to watch videos on how to install linux

That xrandr switching back seems weird, I am not aware of (with i3 anyway) any such service.

I wonder if we have things the wrong way around, i.e. your host is not sending the right window geometry to Virtualbox on resize, so Virtualbox resizes the guest to what it thinks it should be. What host are you using, and do you have problems with guest resizing with a different linux distro?

I get

$ lsmod | grep -i vbox
vboxvideo              45056  2
ttm                   114688  1 vboxvideo
drm_kms_helper        167936  1 vboxvideo
drm                   438272  5 drm_kms_helper,vboxvideo,ttm
vboxsf                 86016  1
vboxguest             299008  5 vboxsf

However when using VMSVGA I don’t have resize and I get

$ lsmod | grep -i vbox
vboxsf                 86016  1
vboxguest             299008  6 vboxsf

(It works with VBoxVGA and VBoxSVGA in the graphics controller in Virtualbox)

Hm…it might be important that I don’t have the vboxvideo module loaded.

Indeed, which graphics controller are you using in Virtualbox for your VM?

I am using VMSVGA set to 128MB of Video Memory and 3D Acceleration enabled.

That doesn’t work (for me anyway), try VBoxVGA or VBoxSVGA

1 Like

With VBoxVGA it works. :man_facepalming:

Edit: VBoxSVGA works as well.

I’m going to cry for a while.

VBoxSVGA might be the best default, looking here https://superuser.com/questions/1403123/what-are-differences-between-vboxvga-vmsvga-and-vboxsvga-in-virtualbox