如何覆盖默认稳定的 Nvidia 驱动程序

How to override default stable Nvidia driver

我正在尝试将我的 configuration.nix 中的稳定 nvidia 包从 nvidia 驱动程序 410 覆盖到 390,但是,它似乎无法使用覆盖配置下面。

我正在使用 services.xserver.videoDrivers = [ "nvidia" ] 选项启用驱动程序并订阅了 unstable 频道。

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;
          };
        });
    };
  };

我还尝试在以下行中将 super 更改为 self

stable = super.nvidiaPackages.stable_390;

但这也没有任何影响。

据我所知,您需要覆盖核心包集中的 linux 包和 nvidia_x11。如果我没有,我会遇到默认 nvidia 驱动程序的静默回退。

以下示例不如您的尝试精细。我的想法是,用于构建和在运行时加载的内核依赖项之间可能存在不匹配,因此我换掉了整个 linux 包集。

目前 (01/10/2019),nvidia 410.7x 已损坏(参见 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。您仍然可以固定 master 并向您的包集添加一个 unstable 命名空间,而不会干扰内核。

{ 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;
}

希望对您有所帮助!