Prototyping NixOS configuration on Ubuntu: question about graphics


I am a beginner NixOS enthusiast trying to develop my own configuration in a fast feedback loop.
At the moment, my daily driver is Ubuntu.

I would like to develop a NixOS configuration using my current Ubuntu setup first. In theory, such a configuration should more or less be usable in the final installation.
The plan is to eventually build my custom iso using GitHub - nix-community/nixos-generators: Collection of image builders [maintainer=@Lassulus].

So far, I have used this tutorial: NixOS virtual machines — documentation.

I build my NixOS prototype with

nix-build '<nixpkgs/nixos>' -A vm \
-I nixpkgs=channel:nixos-23.11 \
-I nixos-config=./configuration.nix

and I run it with

QEMU_KERNEL_PARAMS=console=ttyS0 ./result/bin/run-nixos-vm -nographic; reset

The feedback loop is very short.

Now, my goal is to somehow set up graphical environment.
My GPU is 1080Ti. It would be perfect to use it in qemu.
I don’t need full performance.
My goal is to prototype configuration of gui applications, so it can later be used in the regular NixOS installation.

I have read most of the posts related to qemu on this forum.
I have tried adding gnome to my configuration, but nothing seems to work.
When I boot up qemu with flag -display gtk I get errors like

Failed to load module "canberra-gtk-module"

Below are links to the configuration I use:

Attempts of using gpu inside of qemu:

The nvidia-gl.nix, when in the modules list, does not install nvidia-settings for some reason.

I have found a promising configuration: GitHub - donovanglover/nix-config: My NixOS configuration with Nix Flakes, Home Manager, Stylix, and Hyprland., but the building instruction will work only within NixOS.
I have tried nix build and stuff, but to no avail.

The questions are:

  1. Is the idea of prototyping NixOS configuration like that feasible? Maybe it’s better to just install NixOS and play with it directly?
  2. Is there a nix (on Ubuntu) counterpart to nixos-rebuild build-vm --flake .#nixos?
  3. Could you guide me just a little bit towards booting qemu with graphics?
  4. Perhaps there is a better tool than qemu that can help achieve fast feedback loop, while still providing graphic capabilities?

I am not expecting solving all the problems, any kind of guidance will be greatly appreciated.
I could spend another week googling, but I thought I could ask here.
Maybe someone has already tried implementing a similar NixOS configuration prototyping setup.

Thanks in advance and sorry if I missed something obvious.

Maybe that’s dumb of me, but putting aside fancy graphics modules, have you tried simply removing the -nographic flag from the QEMU invocation? Because by default that would open a graphical window.

Also, who is issuing the error you have shown? There is a possibility that the Nix package for QEMU fails to do graphics on your Ubuntu, which may have nothing to do with your configuration per se. You could check out NixGL in that case.

Anyway, awesome that the tutorial helped you get that far! @olaf wrote most of it.

1 Like

Yes, the tutorial is great. I did not have any issues following it. It just stops at the terminal stuff :slight_smile:

The behaviour without -nographic is the same as with -display gtk.
There is a window, but with console only.

So technically, there is some graphics, but it’s still far from e.g. setting
programs.hyprland.enable = true; and having some windows on a screen.

When I try running firefox, I get error that no DISPLAY environment variable is specified.
Maybe I should figure our proper flags to run run-nixos-vm with?

This is a reasonable entry point to examine tomorrow.
Thanks a lot!

It would help if you could provide a minimal reproducer from your configuration. Oftentimes it turns out to be stupid little things like forgetting to set services.xserver.enable = true (as well as services.xserver.displayManager and services.xserver.desktopManager).

Edit: In fact, browsing through your repo that’s actually it. It’s not your fault though, we didn’t provide instructions for that and it’s entirely non-obvious that you need these things. I opened an issue: Add a section to for a NixOS graphical configuration in the VM tutorial · Issue #926 · NixOS/ · GitHub


Wow! Thank you so much!
All I needed were these three lines

services.xserver.enable = true;
services.xserver.displayManager.gdm.enable = true;
services.xserver.desktopManager.gnome.enable = true;

along with removing -nographic flag.