Replace src of nvidia package

Hi, I’m starting with Nix using NixOS, all worked good. Now I have a HP Envy laptop with a Optimus system Intel + Nvidia, so i need to install nvidia drivers. The problem is that i can’t download the nvidia drivers from official site, so i downloaded in other PC and copied to my laptop, so i was searching the method to change the src of nvidia derivation to use my own src. I tried to use this on my nvidia.nix file:

Nix 22.05

nix-info:

stem: "x86_64-linux", multi-user?: yes, version: nix-env (Nix) 2.8.1, nixpkgs: /nix/var/nix/profiles/per-user/root/channels/nixos
{ config, pkgs, lib, linuxPackages, ... }:

let
	nvidia-offload = pkgs.writeShellScriptBin "nvidia-offload" ''
		export __NV_PRIME_RENDER_OFFLOAD=1
		export __NV_PRIME_RENDER_OFFLOAD_PROVIDER=NVIDIA-G0
		export __GLX_VENDOR_LIBRARY_NAME=nvidia
		export __VK_LAYER_NV_optimus=NVIDIA_only
		exec -a "$0" "$@"
	'';
in
{

	environment.systemPackages = [ nvidia-offload ];

	hardware.nvidia.package = pkgs.linuxPackages.nvidia_x11.overrideAttrs
		(oldAttrs: rec {
			src = /home/luis/Downloads/NVIDIA-Linux-x86_64-515.48.07.run;
			useGLVND = true;
		});

	services.xserver.videoDrivers = [ "nvidia" ];
	hardware.nvidia.prime = {
		offload.enable = true;

		intelBusId = "PCI:0:2:0";
                nvidiaBusId = "PCI:1:0:0";
	};
}

But on nixos-rebuild build start to work, use that downloaded file, compile and make the derivation, but after that… try again to download the driver from nvidia website…

building Nix...
building the system configuration...
these 14 derivations will be built:
  /nix/store/064kgrc5cwjn1228a2qpj8dd20d4cg16-NVIDIA-Linux-x86_64-515.48.07.run.drv
  /nix/store/p1zjnk55cbrc6cv3232x6iaxfmxzq744-nvidia-x11-515.48.07-5.15.43.drv
  /nix/store/lcpx89kmbjyd3apzhjy43xh3hy4mksn7-nvidia-settings-515.48.07.drv
  /nix/store/hiqq8i2yc5d1hdalpw2x6ggz0cxp68mx-system-path.drv
  /nix/store/idh5dgkx2s472d7nw5myh4i34xmvq1xz-dbus-1.drv
  /nix/store/28s2c0kjnz0bllgg2pav0cvdfbbck4zv-unit-dbus.service.drv
  /nix/store/5i40naj4njypx06cbgqqc3wfn5mik8zy-unit-accounts-daemon.service.drv
  /nix/store/i5gw2bq6756nvw5hy7qcrmyy9rq10zpq-user-units.drv
  /nix/store/iaxw0nkdab90xcgdnki4kar5c0s7vs2l-unit-dbus.service.drv
  /nix/store/iyid5hmd1hkq1lsy1ppmlsj1ihlbdgca-unit-systemd-fsck-.service.drv
  /nix/store/mpp975qvlg1iydr82njxgswgay8gz32c-unit-polkit.service.drv
  /nix/store/jbqhhjk8bwaijb4cxygk2fvdzyd7zvbz-system-units.drv
  /nix/store/g8sg644jkvddkixiv692r99kxayprgw9-etc.drv
  /nix/store/y5xc6yx6czcanisd0ff6vrji75n0xlaf-nixos-system-envy-22.05.851.dab6df51387.drv
building '/nix/store/064kgrc5cwjn1228a2qpj8dd20d4cg16-NVIDIA-Linux-x86_64-515.48.07.run.drv'...

trying https://us.download.nvidia.com/XFree86/Linux-x86_64/515.48.07/NVIDIA-Linux-x86_64-515.48.07.run
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0   345    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
curl: (22) The requested URL returned error: 403
error: cannot download NVIDIA-Linux-x86_64-515.48.07.run from any mirror
error: builder for '/nix/store/064kgrc5cwjn1228a2qpj8dd20d4cg16-NVIDIA-Linux-x86_64-515.48.07.run.drv' failed with exit code 1
error: 1 dependencies of derivation '/nix/store/p1zjnk55cbrc6cv3232x6iaxfmxzq744-nvidia-x11-515.48.07-5.15.43.drv' failed to build
error: 1 dependencies of derivation '/nix/store/lcpx89kmbjyd3apzhjy43xh3hy4mksn7-nvidia-settings-515.48.07.drv' failed to build
error: 1 dependencies of derivation '/nix/store/hiqq8i2yc5d1hdalpw2x6ggz0cxp68mx-system-path.drv' failed to build
error: 1 dependencies of derivation '/nix/store/idh5dgkx2s472d7nw5myh4i34xmvq1xz-dbus-1.drv' failed to build
error: 1 dependencies of derivation '/nix/store/5i40naj4njypx06cbgqqc3wfn5mik8zy-unit-accounts-daemon.service.drv' failed to build
error: 1 dependencies of derivation '/nix/store/mpp975qvlg1iydr82njxgswgay8gz32c-unit-polkit.service.drv' failed to build
error: 1 dependencies of derivation '/nix/store/iyid5hmd1hkq1lsy1ppmlsj1ihlbdgca-unit-systemd-fsck-.service.drv' failed to build
error: 1 dependencies of derivation '/nix/store/28s2c0kjnz0bllgg2pav0cvdfbbck4zv-unit-dbus.service.drv' failed to build
error: 1 dependencies of derivation '/nix/store/iaxw0nkdab90xcgdnki4kar5c0s7vs2l-unit-dbus.service.drv' failed to build
error: 4 dependencies of derivation '/nix/store/jbqhhjk8bwaijb4cxygk2fvdzyd7zvbz-system-units.drv' failed to build
error: 1 dependencies of derivation '/nix/store/i5gw2bq6756nvw5hy7qcrmyy9rq10zpq-user-units.drv' failed to build
error: 4 dependencies of derivation '/nix/store/g8sg644jkvddkixiv692r99kxayprgw9-etc.drv' failed to build
error: 2 dependencies of derivation '/nix/store/y5xc6yx6czcanisd0ff6vrji75n0xlaf-nixos-system-envy-22.05.851.dab6df51387.drv' failed to build

You can use nix-store --add to add the file to your nix store before the build, and then not do any of this source overriding :slight_smile:

I’m unsure why your attempt doesn’t work, my suspicion is that something else pulls in the driver as a dependency, so just overriding hardware.nvidia.package isn’t enough.

I tried that already (the nix-store --add option)…

> nix-store --add NVIDIA-Linux-x86_64-515.48.07.run 
/nix/store/11pkhy3w6v6kfkcaj6abqj6zk0b618z0-NVIDIA-Linux-x86_64-515.48.07.run

check the hash… now when run rebuild

building '/nix/store/064kgrc5cwjn1228a2qpj8dd20d4cg16-NVIDIA-Linux-x86_64-515.48.07.run.drv'...

trying https://us.download.nvidia.com/XFree86/Linux-x86_64/515.48.07/NVIDIA-Linux-x86_64-515.48.07.run
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0   345    0     0    0     0      0      0 --:--:--  0:00:02 --:--:--     0
curl: (22) The requested URL returned error: 403
error: cannot download NVIDIA-Linux-x86_64-515.48.07.run from any mirror

Check how the required hash is not same… but is the same file, because i donwloaded that file and test the sha256sum even…

It’s been years since I tried to do this, but if the derivation is anything like it was back then, then a simple overrideAttrs isn’t going to cut it, since it is nested a couple scopes deep. I figured it out eventually but it was fairly convoluted and I can’t recreate it off the top of my head.

What is the purpose of overriding the source? To use a newer version? If so, right now I am using the latest 515.57 by using a fork of nixos-unstable with this PR applied to it. It’s much easier than trying to properly override the source.

Ah, whoops, I forgot that --add uses a different hashing algorithm by default… Yeah, I know, I double took the first time I saw that too. It makes sense, since there is no standard for fetchurl, and sha256 was less common historically (and will likely be replaced some day), but it’s unfortunate the command doesn’t make this explicit.

Use nix-store --add-fixed sha256 <file> instead - the manual suggests this as well.

This has been cleaned up in the nix 3.0 CLI, I think, but that’s opt-in for now.

@nrdxp read the OP again - this is simply to circumvent some kind of network block for nvidia driver downloads from this computer. That does seem like the real problem to fix, to be fair.

The problem is the 403 of get from NVidia site

tried this… and different hash too, i dont known how the store is calculating the hash of the src from nvidia.com

Are you sure you have the right file? Running this on my end gives me:

tlater ~/Downloads/aria $ nix-store --add-fixed sha256 NVIDIA-Linux-x86_64-515.48.07.run
/nix/store/21whdvnxxanvcvcchxsk45smxnfk7402-NVIDIA-Linux-x86_64-515.48.07.run

This matches what the derivation thinks the output path should be:

tlater ~/Downloads/aria $ NIXPKGS_ALLOW_UNFREE=1 nix show-derivation --impure nixpkgs#linuxPackages.nvidia_x11
<snip>
      "src": "/nix/store/21whdvnxxanvcvcchxsk45smxnfk7402-NVIDIA-Linux-x86_64-515.48.07.run",
<snip>

For reference, the checksum of my file:

tlater ~/Downloads/aria $ sha256sum NVIDIA-Linux-x86_64-515.48.07.run
e28764cc5b13c32e76370513daeafc05c289b77ee0511552450f1a00e31ae1e3  NVIDIA-Linux-x86_64-515.48.07.run

jajaja sorry… my bad, i was adding to store the wrong failed to download file…

1 Like

this worked like a charm… thanks

@lfdominguez Hey, maybe you could add this to Nvidia - NixOS Wiki

Personally, I’d prefer we only add this if we actually know why the download is broken on that particular laptop :slight_smile:

If it’s something like a country-wide firewall, or perhaps simply an IP address blocked by cloudflare, we should have a more general page about download failures instead of adding it to the nvidia one (where most users will just be confused about why things need to be downloaded manually).

If it’s something nvidia-specific, that would make more sense, but I don’t see how that would be the case.

I actually have a use case where I need a specific version of the driver, that is the reason why I suggested it :sweat_smile:

Yep, the solution to this discussion won’t help you, sadly. Look into the reply from @nrdxp :slight_smile:

I think that this can be in a dedicated entry or something like that… because the problem was really add the .run file to the store…

And yes… the problem is that I’m on Cuba and NVidia doesnt allow enter from my country

2 Likes