Learning NixOS & Nix


Brand new to Nix and NixOS and steadily working my way through the resources.

I am trying to understand how a few thing relate to each other.

In the NixOS Manual there is the following section;


I added the following to my configuration.nix;

  nixpkgs.config = {
    allowUnfree = true;
  boot.kernelPackages = pkgs.linuxPackages_latest;
  boot.blacklistedKernelModules = { "nouveau" ];
  services.xserver.videoDrivers = [ "nvidia" ];

After a rebuild and reboot this gave me a kernel version of 5.16.12 (as shown by uname -srm)
It also seemed to install the nvidia driver version 495.44-5.16.12 (as shown by nix-store -q -R /nix/var/nix/profiles/system-3-link | grep nvidia)

This makes sense to me as it shows the driver version for the kernel version.

Trying to make sense of what version of driver gets installed I looked in nixpkgs/default.nix at 83580a2e4f57872c25393bdf7e8c14bb402ddca8 · NixOS/nixpkgs · GitHub

This seems to show a much later driver version, early driver versions and not the version that I have installed - indicating I am looking at the wrong file.

Q1. What file should I be looking at - presumably the one that is tied to kernel 5.16.12 but I can’t work out where that is.

Q2. The file above seems like the default version, but this wasn’t the one I got. Any ideas what I did wrong here?

Q3. The manual snippet I originally referenced showed a syntax of services.xserver.videoDrivers = [ "nvidiaLegacy390" ]; to specify a particular driver version however the file above seems to use the format legacy_390. I’m guessing there is something in the middle but I am struggling to work out the connections.

Many thanks if anyone can help my learning process.

I’m not sure if this makes more sense…

I also found this statement Note that this not only replaces the kernel, but also packages that are specific to the kernel version, such as the NVIDIA video drivers. This ensures that driver packages are consistent with the kernel. in the NixOS manual.

Q4. How do you determine - before changing kernel version - what version of dependent drivers such as the Nvidia one will be installed? Can I see a list somewhere because the driver version that has been installed doesn’t seem obvious.

You’re looking at the master branch, but the default NixOS installation flow uses the 21.11 stable channel. The corresponding git branch is nixos-21.11 and should be mostly in sync with what you’re actually seeing (modulo the time it takes for the channel to actually advance).

The file on the 21.11 branch does show the 495.44 version: nixpkgs/default.nix at 9b1c7ba323732ddc85a51850a7f10ecc5269b8e9 · NixOS/nixpkgs · GitHub

There’s an important distinction to make here: kernel drivers and Xorg drivers. The file you reference is about the kernel module, whereas the attribute seems to be used to construct a Xorg module name, see nixpkgs/xserver.nix at 9b1c7ba323732ddc85a51850a7f10ecc5269b8e9 · NixOS/nixpkgs · GitHub

Because your system’s software composition depends on your configuration.nix, you’ll have to ask Nix to evaluate it.

Generally the easiest way is to use nixos-rebuild dry-build to get a list of all derivations that would be built and grep for what you’re looking for. Usually this would include your driver. If the Nix path doesn’t tell you all you need to know, run nix show-derivation <.drvpath> to print the full derivation with all of its attributes.


Thank you, this was very helpful. I should have been able to work that out for myself but I couldn’t see the wood for the trees!

Thanks again. I had this question in my head about how the configuration under services.xserver was controlling the install of the nvidia driver. This is presumably the bit in the middle! I will keep working through this trying to make sure I understand how it is working, so I can make sensible choices… It is quite a different way of doing things and I’m already liking the more deterministic nature.

I had a quick look at both of these which were useful but in the case above seemed to not reference the install of the particular nvidia driver. I will use this more as I install other packages and hopefully work out what it is telling me.

Many thanks @ius for the pointers.