Getting nvidia driver from unstable

I am trying to get the new nvidia 560 to install on nixos. I added the unstable branch, and then specified the driver from that branch:
“{
services.xserver.videoDrivers = [ “nvidia” ];
hardware.nvidia.package = (import {}).linuxPackages.nvidiaPackages.latest;
}”
but got the error:
"error:
… while calling the ‘head’ builtin

     at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/attrsets.nix:1575:11:

     1574|         || pred here (elemAt values 1) (head values) then
     1575|           head values
         |           ^
     1576|         else

   … while evaluating the attribute 'value'

     at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:809:9:

      808|     in warnDeprecation opt //
      809|       { value = builtins.addErrorContext "while evaluating the option ${showOption loc}':" value;
         |         ^
      810|         inherit (res.defsFinal') highestPrio;

   (stack trace truncated; use '--show-trace' to show the full trace)

   error: Package ‘nvidia-x11-560.35.03-6.6.51’ in /nix/store/hwxpwash11jh29gm8hlxqxwbzcrh5kdq-nixos-unstable/nixos-unstable/pkgs/os-specific/linux/nvidia-x11/generic.nix:236 has an unfree license (‘unfreeRedistributable’), refusing to evaluate.

   a) To temporarily allow unfree packages, you can use an environment variable
      for a single invocation of the nix tools.

        $ export NIXPKGS_ALLOW_UNFREE=1

      Note: When using nix shell, nix build, nix develop, etc with a flake,
            then pass --impure in order to allow use of environment variables.

   b) For nixos-rebuild you can set
     { nixpkgs.config.allowUnfree = true; }
   in configuration.nix to override this.

   Alternatively you can configure a predicate to allow specific packages:
     { nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
         "nvidia-x11"
       ];
     }

   c) For nix-env, nix-build, nix-shell or any other Nix command you can add
     { allowUnfree = true; }
   to ~/.config/nixpkgs/config.nix."

even though I have unfree packages enabled. I found some others online with the same problem, but they didn’t explain their solutions well enough for me to recreate. Any help?

(For future reference: stick ``` on a line by itself before and after blocks of code like this to format it correctly.)

From the import {} I imagine you have a <nixpkgs> in there that got eaten by formatting. Don’t re-import Nixpkgs from your config; just use pkgs.linuxPackages.nvidiaPackages.latest. (Your config file should start with { config, lib, pkgs, ... }: which puts the pkgs variable in scope.)

that still only leaves me with driver 550.78 and not 560

If you import a second nixpkgs It’s a new instance and doesn’t have the same config settings. You would need to put config.allowUnfree = true; in the args (or inherit config; to inherit all config).

If you use flakes, use nixpkgs-unfree instead.

2 Likes

so where would either of these strings go in the config? I already have nixpkgs.config.allowUnfree = true; in my config, do I need it again somewhere else? I tried (import {nixpkgs.config.allowUnfree = true;}) but it told me it refused to elaborate and then gave me the same options for allowing unfree packages.

Assuming you have a nixpkgs-unstable channel set up:

import <nixpkgs-unstable> { config.allowUnfree = true; }

error:
… while evaluating the attribute ‘config’

     at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:322:9:

      321|         options = checked options;
      322|         config = checked (removeAttrs config [ "_module" ]);
         |         ^
      323|         _module = checked (config._module);

   … while calling the 'seq' builtin

     at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:322:18:

      321|         options = checked options;
      322|         config = checked (removeAttrs config [ "_module" ]);
         |                  ^
      323|         _module = checked (config._module);

   (stack trace truncated; use '--show-trace' to show the full trace)

   error: syntax error, unexpected SPATH, expecting '.' or '='

   at /etc/nixos/configuration.nix:56:10:

       55| # Unstable channel
       56|   import <nixpkgs-unstable> { config.allowUnfree = true: }
         |          ^
       57|

building Nix…
error:
… while evaluating the attribute ‘config’

     at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:322:9:

      321|         options = checked options;
      322|         config = checked (removeAttrs config [ "_module" ]);
         |         ^
      323|         _module = checked (config._module);

   … while calling the 'seq' builtin

     at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:322:18:

      321|         options = checked options;
      322|         config = checked (removeAttrs config [ "_module" ]);
         |                  ^
      323|         _module = checked (config._module);

   (stack trace truncated; use '--show-trace' to show the full trace)

   error: syntax error, unexpected SPATH, expecting '.' or '='

   at /etc/nixos/configuration.nix:56:10:

       55| # Unstable channel
       56|   import <nixpkgs-unstable> { config.allowUnfree = true: }
         |          ^
       57|

building the system configuration…
error:
… while evaluating the attribute ‘config.system.build.toplevel’

     at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:322:9:

      321|         options = checked options;
      322|         config = checked (removeAttrs config [ "_module" ]);
         |         ^
      323|         _module = checked (config._module);

   … while calling the 'seq' builtin

     at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:322:18:

      321|         options = checked options;
      322|         config = checked (removeAttrs config [ "_module" ]);
         |                  ^
      323|         _module = checked (config._module);

   (stack trace truncated; use '--show-trace' to show the full trace)

   error: syntax error, unexpected SPATH, expecting '.' or '='

   at /etc/nixos/configuration.nix:56:10:

       55| # Unstable channel
       56|   import <nixpkgs-unstable> { config.allowUnfree = true: }
         |          ^

ok, aside from the basic syntax errors here, you should know that you can’t get just the nvidia kernel module from unstable. That’s going to be built for the kernel from unstable, and you can’t use a kernel module for a different kernel build.

1 Like

alright then how do I fully switch to unstable then?
I have the channel added, I’m pretty sure

Frankly, I’d suggest just defining the source yourself like this: dotfiles/nixos-config/hosts/yui/nvidia/default.nix at f4ed53e9e78ff41cd2849f389499d3bfd3ffe4c7 · TLATER/dotfiles · GitHub

To switch to unstable, you need to change your nixos channel to refer to unstable.

I upgraded to unstable and got this:
$ nvidia-smi
Failed to initialize NVML: Driver/library version mismatch
NVML library version: 560.35

You need to reboot after switching kernel/driver.

I got it to work, thank you

1 Like

To clear up this, we would need to see the surrounding context. It looks like you defined this somewhere an expression is not allowed.

Also note that you use a semicolon to end attribute declarations, not a colon.