Change package version (TensorRT)

Im pretty new to nix features but i worship the nix for a while

I want to change tensorrt package version from 10.8 to 10.7 but I dont understand how to do it

I found source of this package nixpkgs/pkgs/development/cuda-modules/generic-builders/manifest.nix at 5ed4e25ab58fd4c028b59d5611e14ea64de51d23 · NixOS/nixpkgs · GitHub

I found where packages versions are specified nixpkgs/pkgs/development/cuda-modules/tensorrt/releases.nix at 5ed4e25ab58fd4c028b59d5611e14ea64de51d23 · NixOS/nixpkgs · GitHub

But how to add my own version and how to use it (not in a github repo)? I would like to run it shell.nix or in nix repl to test it

I think I need something like overlays or overriding?

if you just want to use it with mkShell (for flake.nix, not shell.nix, but similar), you dont need to override, just refer the package from another source

below is a flake.nix example (use it with nix develop)

{
  description = "zv6";
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    nixpkgs-qemu8.url = "github:NixOS/nixpkgs/3eebbc5fe26801ff612f2cdd4566e76651dc8106";
  };
  outputs =
    {
      self,
      nixpkgs,
      nixpkgs-qemu8,
      ...
    }:
    let
      supportedSystems = [
        "aarch64-darwin"
        "aarch64-linux"
        "x86_64-linux"
      ];
      perSystem =
        system:
        let
          pkgs = import nixpkgs { inherit system; };
          pkgs-qemu8 = import nixpkgs-qemu8 { inherit system; };
          venvDir = "./.venv";
        in
        {
          devShells.default = pkgs.mkShellNoCC {
            name = "zv6";
            packages =
              (with pkgs; [
                zig_0_15
                lldb
                (python312.withPackages (
                  p: with p; [
                    virtualenv
                  ]
                ))
                perl
                pkgsCross.riscv64-embedded.buildPackages.binutilsNoLibc # for riscv64-none-elf-objdump
              ])
              ++ (with pkgs-qemu8; [ qemu ]);
            shellHook = with pkgs; ''
              SOURCE_DATE_EPOCH=$(date +%s)

              if [ -d "${venvDir}" ]; then
                echo "Skipping venv creation, '${venvDir}' already exists"
              else
                echo "Creating new venv environment in path: '${venvDir}'"
                # Note that the module venv was only introduced in python 3, so for 2.7
                # this needs to be replaced with a call to virtualenv
                ${python312Packages.python.interpreter} -m venv "${venvDir}"
              fi

              # Under some circumstances it might be necessary to add your virtual
              # environment to PYTHONPATH, which you can do here too;
              # PYTHONPATH=$PWD/${venvDir}/${python312Packages.python.sitePackages}/:$PYTHONPATH

              source "${venvDir}/bin/activate"
            '';
          };
        };
    in
    {
      devShells = nixpkgs.lib.genAttrs supportedSystems (system: (perSystem system).devShells);
    };
}

Main problem is that 10.7 is not in nixpkgs

I want to change something in package somehow to use my own filename and my own hash in nixpkgs/pkgs/development/cuda-modules/tensorrt/releases.nix at 5ed4e25ab58fd4c028b59d5611e14ea64de51d23 · NixOS/nixpkgs · GitHub to make it work

oops my bad, didnt read your post carefully enough, sorry for that

then overriding is a must, based on nixpkgs/pkgs/development/cuda-modules/tensorrt/shims.nix at 5ed4e25ab58fd4c028b59d5611e14ea64de51d23 · NixOS/nixpkgs · GitHub

you can try

cudaPackages.tensorrt.overrideAttrs(_: { 
  version = "10.7.0.XX";
  filename = "XXXXX";
  hash = "XXXXXXXX";
})

only have a linux setup at work, perhaps you need to override more attributes

if you don’t know what the exact hash is, you can just fill a random one first, then when build failed nix will tell you the correct one

wow its kind of trying to work but still doesn’t work

but now there are mixed logs with 10.7 and 10.8 versions

Here is my shell.nix

{ pkgs ? import <nixpkgs> { } }:
let
  tensorrt_10_7 = pkgs.cudaPackages_11.tensorrt_10_8.overrideAttrs (_: {
    version = "10.7.0.23";
    name = "TensorRT-10.7.0.23.Linux.x86_64-gnu.cuda-12.6.tar.gz";
    hash = "XXXXXXXX";
  });
in pkgs.mkShell {
  name = "cuda-env-shell";
  buildInputs = [ tensorrt_10_7 ];
  shellHook = ''
    export LD_LIBRARY_PATH=${tensorrt_10_7.lib}/lib
  '';
}

And logs

evaluation warning: CUDA versions older than 12.0 will be removed in Nixpkgs 25.05; see the 24.11 release notes for more information                                                                                                                                            
evaluation warning: tensorrt-10.8.0.43 was overridden with `version` but not `src` at /home/user/shell.nix:4:5.                                                                            
                                                                                                                                                                                                            
                    This is most likely not what you want. In order to properly change the version of a package, override                                                                                   
                    both the `version` and `src` attributes:                                                                                                                                                                                                                    
                                                                                                                                                                                                            
                    hello.overrideAttrs (oldAttrs: rec {                                              
                      version = "1.0.0";                                                                                                                                                                                                                                        
                      src = pkgs.fetchurl {                                                                                             
                        url = "mirror://gnu/hello/hello-${version}.tar.gz";                                                             
                        hash = "...";                               
                      };                                                                                                                                                                                                                                                        
                    })                                                                                                                                                                                                                                                          

                    (To silence this warning, set `__intentionallyOverridingVersion = true` in your `overrideAttrs` call.)                                                                                                                                                      
these 2 derivations will be built:                                  
  /nix/store/g229y0msry1af9dn2f0gpdyx9iphw805-TensorRT-10.8.0.43.Linux.x86_64-gnu.cuda-11.8.tar.gz.drv                                                                                                                                                                          
  /nix/store/6iyz5w3iprvm38l5l20m2z2y1p5s7gw1-TensorRT-10.7.0.23.Linux.x86_64-gnu.cuda-12.6.tar.gz.drv                                                                                                                                                                          
building '/nix/store/g229y0msry1af9dn2f0gpdyx9iphw805-TensorRT-10.8.0.43.Linux.x86_64-gnu.cuda-11.8.tar.gz.drv'...                                                                                                                                                              

***                                                                 
To use the TensorRT derivation, you must join the NVIDIA Developer Program and                                                          
download the 10.7.0.23 TAR package for CUDA 11.8 from                                                                                   
https://developer.nvidia.com/tensorrt.                              

Once you have downloaded the file, add it to the store with the following                                                               
command, and try building this derivation again.                                                                                        

$ nix-store --add-fixed sha256 TensorRT-10.8.0.43.Linux.x86_64-gnu.cuda-11.8.tar.gz                                                                                                                                                                                             

***                                                                 

error: builder for '/nix/store/g229y0msry1af9dn2f0gpdyx9iphw805-TensorRT-10.8.0.43.Linux.x86_64-gnu.cuda-11.8.tar.gz.drv' failed with exit code 1;                                                                                                                              
       last 13 log lines:                                           
       >                                                            
       > ***                                                        
       > To use the TensorRT derivation, you must join the NVIDIA Developer Program and                                                                                                                                                                                         
       > download the 10.7.0.23 TAR package for CUDA 11.8 from                                                                          
       > https://developer.nvidia.com/tensorrt.                                                                                         
       >                                                            
       > Once you have downloaded the file, add it to the store with the following                                                                                                                                                                                              
       > command, and try building this derivation again.                                                                               
       >                                                            
       > $ nix-store --add-fixed sha256 TensorRT-10.8.0.43.Linux.x86_64-gnu.cuda-11.8.tar.gz                                                                                                                                                                                    
       >                                                            
       > ***                                                        
       >                                                            
       For full logs, run 'nix-store -l /nix/store/g229y0msry1af9dn2f0gpdyx9iphw805-TensorRT-10.8.0.43.Linux.x86_64-gnu.cuda-11.8.tar.gz.drv'.                                                                                                                                  
error: 1 dependencies of derivation '/nix/store/6iyz5w3iprvm38l5l20m2z2y1p5s7gw1-TensorRT-10.7.0.23.Linux.x86_64-gnu.cuda-12.6.tar.gz.drv' failed to build

And also I found this line which generates wrong filename nixpkgs/pkgs/development/cuda-modules/_cuda/fixups/tensorrt.nix at 53253907100a809583c0344bba5743abc45a64b7 · NixOS/nixpkgs · GitHub

I found out that i need to override a filename in passthru.redistribRelease.filename. But it is a set with many other parameters and if i write something like

  tensorrt_10_7 = pkgs.cudaPackages_11.tensorrt_10_8.overrideAttrs (_: {
    version = "10.7.0.23";
    name = "TensorRT-10.7.0.23.Linux.x86_64-gnu.cuda-12.6.tar.gz";
    passthru = {
      redistribRelease = {
        filename = "TensorRT-10.7.0.23.Linux.x86_64-gnu.cuda-12.6.tar.gz";
      };
    };
    hash = "XXXXXXXX";
  });

It falls with this error

error:
       … while calling the 'derivationStrict' builtin
         at <nix/derivation-internal.nix>:34:12:
           33|
           34|   strict = derivationStrict drvAttrs;
             |            ^
           35|

       … while evaluating derivation 'cuda-env-shell'
         whose name attribute is located at /nix/store/m85c2rx3rh5km3aarlm4hhj4n6invskp-nixpkgs/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:461:13

       … while evaluating attribute 'buildInputs' of derivation 'cuda-env-shell'
         at /nix/store/m85c2rx3rh5km3aarlm4hhj4n6invskp-nixpkgs/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:516:13:
          515|             depsHostHost = elemAt (elemAt dependencies 1) 0;
          516|             buildInputs = elemAt (elemAt dependencies 1) 1;
             |             ^
          517|             depsTargetTarget = elemAt (elemAt dependencies 2) 0;

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

       error: attribute 'featureRelease' missing
       at /nix/store/m85c2rx3rh5km3aarlm4hhj4n6invskp-nixpkgs/nixpkgs/pkgs/development/cuda-modules/_cuda/fixups/tensorrt.nix:32:10:
           31|       cudaTooNew =
           32|         (finalAttrs.passthru.featureRelease.maxCudaVersion != null)
             |          ^
           33|         && strings.versionOlder finalAttrs.passthru.featureRelease.maxCudaVersion cudaMajorMinorVersion;

I don’t know what this error mean but I guess I’m overriding a whole set with a single value and I don’t know how don’t do this

Hi! Glad to see the progress you’ve made deciphering our tech debt since starting this thread. First, an important disclaimer: much of this code that confused you, including e.g. the “fixups” and “shims” is being phased out: cudaPackages: build redists from manifests and add CUDA 13 by ConnorBaker · Pull Request #437723 · NixOS/nixpkgs · GitHub https://github.com/NixOS/nixpkgs/pull/406740

But how to add my own version and how to use it (not in a github repo)?

This question is answered in the Nixpkgs Manual. The generic answer for “scopes” is:

let
  cudaPackages = pkgs.cudaPackages.overrideScope (fi: pre: {
    tensorrt = pre.overrideAttrs (oldAttrs: { version = ...; src = requireFile { ... }; });
  });
in

Cf. the manual for the hacks specific to the current implementation of cudaPackages.

       error: attribute 'featureRelease' missing
      at /nix/store/m85c2rx3rh5km3aarlm4hhj4n6invskp-nixpkgs/nixpkgs/pkgs development/cuda-modules/_cuda/fixups/tensorrt.nix:32:10:

Short answer: ignore it, just override with your own brand-new src attribute. The hack that causes the error is being removed anyway.

To use the TensorRT derivation, you must join the NVIDIA Developer Program and        

The error already says so, but I’ll just re-iterate that we have no URL from which we can legally download TensorRT in a hands-off way, so you are expected to add it to the store manually. The requireFile fake derivation is a FOD (“Fixed Output Derivation”) that just matches the pre-existing store path by hash.

LD_LIBRARY_PATH

I don’t know your background, so I’ll mention this just to be sure: you usually only need LD_LIBRARY_PATH at runtime, not at build time, and only when using software not built by Nix. In contrast, you use buildInputs if you do not “use” tensorrt, but only reference (link) it at build time

flake

While at it, here’s also a reminder that, no matter what you do, you don’t need flakes :slightly_smiling_face:

3 Likes

yeah i got below shell.nix working on my vps

{
  pkgs ? import <nixpkgs> { },
}:
let
  tensorrt_10_7 = pkgs.cudaPackages_11.tensorrt_10_8.overrideAttrs (_: {
    version = "10.7.0.23";
    # wget https://developer.nvidia.com/downloads/compute/machine-learning/tensorrt/10.7.0/tars/TensorRT-10.7.0.23.Linux.x86_64-gnu.cuda-12.6.tar.gz
    src = pkgs.requireFile {
      name = "TensorRT-10.7.0.23.Linux.x86_64-gnu.cuda-12.6.tar.gz";
      # hash = pkgs.lib.fakeHash;
      hash = "sha256-1/FlIEV8qvl62KfpTYAvidd67fnzYaJV8sIW4qOkChE="; # nix hash file TensorRT-10.7.0.23.Linux.x86_64-gnu.cuda-12.6.tar.gz
      message = ''
        1. wget https://developer.nvidia.com/downloads/compute/machine-learning/tensorrt/10.7.0/tars/TensorRT-10.7.0.23.Linux.x86_64-gnu.cuda-12.6.tar.gz
        2. nix-store --add-fixed sha256 TensorRT-10.7.0.23.Linux.x86_64-gnu.cuda-12.6.tar.gz
        3. nix hash file TensorRT-10.7.0.23.Linux.x86_64-gnu.cuda-12.6.tar.gz
      '';
    };
  });
in
pkgs.mkShell {
  name = "cuda-env-shell";
  buildInputs = [ tensorrt_10_7 ];
  shellHook = ''
    export LD_LIBRARY_PATH=${tensorrt_10_7.lib}/lib
  '';
}

sorry for my unprofessional guidance :sob: (also thanks @SergeK for correction)
took me a while to understand the pile of code inside cuda module

2 Likes

Wow god it’s beautiful thanks a lot!