Search code examples
nixos

How to override default stable Nvidia driver


I'm trying to override the stable nvidia package from my configuration.nix from nvidia driver 410 to 390, however, it doesn't seem to work using the override config below.

I am enabling the driver using the services.xserver.videoDrivers = [ "nvidia" ] option and am subscribed to the unstable channel.

configuration.nix:

  nixpkgs.config = {
    allowUnfree = true;

    packageOverrides = super: let self = super.pkgs; in
    {
        linuxPackages = super.linuxPackages_latest.extend (self: super: {
          nvidiaPackages = super.nvidiaPackages // {
            stable = super.nvidiaPackages.stable_390;
          };
        });
    };
  };

I also tried changing from super to self in the following line:

stable = super.nvidiaPackages.stable_390;

But this doesn't have any affect either.


Solution

  • From what I've been able to figure out, you'll need to override both the linux packages and nvidia_x11 in the core package set. If I didn't, I encountered a silent fallback to the default nvidia drivers.

    The following is an example that is less fine-grained than your attempt. My thinking was that there was a possibility of a mismatch between kernel dependencies used to build and loaded at runtime, so I instead swapped out the entire linuxPackage set.

    At present (01/10/2019), nvidia 410.7x is broken (see Issue 53708). So I've pinned my configuration to the last commit with nvidia 410.6x. For more information on pinning nixpkgs, see the wiki page. You can still pin against master and add an unstable namespace to your package set without interfering with the kernel.

    { config, pkgs, nixpkgs, ... }:
    
    let
      # get the last working revision with nvidia 410.x
      nixos-unstable-pinned = import (builtins.fetchTarball {
        name = "nixos-unstable_nvidia-410-66_2018-11-03";
        url = https://github.com/nixos/nixpkgs/archive/bf084e0ed7a625b50b1b0f42b98358dfa23326ee.tar.gz;
        sha256 = "0w05cw9s2pa07vqy21ack7g7983ig67lhwkdn24bzah3z49c2d8k";
      }) { };
    
      # We'll use this twice
      pinnedKernelPackages = nixos-unstable-pinned.linuxPackages_latest;
    
    in
    
    {
      # allow nvidia drivers to be loaded 
      nixpkgs.config.allowUnfree = true;
    
      nixpkgs.config.packageOverrides = pkgs: {
        # swap out all of the linux packages
        linuxPackages_latest = pinnedKernelPackages;
    
        # make sure x11 will use the correct package as well
        nvidia_x11 = nixos-unstable-pinned.nvidia_x11;
      };
    
      # line up your kernel packages at boot
      boot.kernelPackages = pinnedKernelPackages;
    }
    

    Hope this helps!