Proprietary Nvidia Specialisation?

Hello, I mostly run the open-source Nouveau drivers on my laptop (so I can use Sway). Sometimes, though, I require CUDA which (as far as I recall) is only usable with the proprietary drivers.

I’m relatively new to NixOS and stumbled across specialisations which seems like a solution to this problem (one boot profile for Nouveau, another for proprietary w/ CUDA installed). However, I haven’t the slightest idea how to use specialisations and the examples I’ve seen haven’t been all too useful.

Is there a way I can swap out graphics drivers and only install CUDA on one boot profile with specialisations?

Short answer is yes. Specialisations basically allow you to set arbitrary configuration options. It could maybe be useful if you figure out and post the minimal difference between Nouveau and proprietary versions of the configurations (as normal system configurations) you need, if you want to discuss how exactly that will look with specialisations.

1 Like

Fair point, here’s what I have for my proprietary Nvidia setup:

{
  config,
  lib,
  pkgs,
  inputs,
  ...
}: {
  hardware.graphics.enable = true;
  services.xserver.videoDrivers = ["nvidia"];
  hardware.nvidia.open = false;
  hardware.nvidia.modesetting.enable = true;
  environment.systemPackages = with pkgs; [
    nvtopPackages.nvidia
  ];
}

And I suppose for open-source, that is done by default through hardware.graphics.enable = true (I can’t remember why I have that in the config above too).

For added context: I have three machines, one with no discrete gpu, my laptop with a discrete Nvidia GPU that I mostly want to run Nouveau on but occasionally need CUDA, and my PC with a Nvidia GPU that I just run proprietary anyways due to gaming performance.

I am not sure how many times it has been renamed since I last used actual NixOS… OK, judging from Wiki and the module source, I would expect something like that to work (in main config):

…
  specialisation = {
    nvidia-proprietary = {
      configuration = {
        services.xserver.videoDrivers = ["nvidia"];
        hardware.nvidia.open = false;
        hardware.nvidia.modesetting.enable = true;
        environment.systemPackages = with pkgs; [
          nvtopPackages.nvidia
        ];
      };
    };
  };
…
2 Likes

Wow. To be honest, I wasn’t expecting that to just work which is why I hadn’t tried it beforehand, but it does work. Pretty neat.

1 Like