1

I'm trying to start a shell with Cuda. I have following shell.nix file

{ pkgs ? import <nixpkgs> { } }:

pkgs.mkShell {
  name = "cuda-env-shell";
  buildInputs = with pkgs; [
    unzip
    # other packages
    cudatoolkit
    # other packages
    binutils
  ];
}

But this fails due to following error. I have faced this before with large files like davinci-resolve for example. For davinci-resolve, my solution was to create a new flake using axel with 10 connections and it worked nicely every single time. Right now I'm facing this issue with Cuda.

[1/0/3 built, 4 copied (183.8/183.8 MiB), 42.8 MiB DL] building cuda_11.8.0_520.61.05_linux.run:                                  Dload  Upload   Total   Spent    Left
error: builder for '/nix/store/idz14mzbsv4k5v5ims095jcjk2r50glr-cuda_11.8.0_520.61.05_linux.run.drv' failed with exit code 1;
       last 7 log lines:
       >
       > trying https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_520.61.05_linux.run
       >   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
       >                                  Dload  Upload   Total   Spent    Left  Speed
       >  49 4135M   49 2044M    0     0   772k      0  1:31:20  0:45:08  0:46:12     0
       > curl: (56) Recv failure: Connection reset by peer

I want to get Cuda but can I retrieve the src using axel instead of curl? I tried something like following but it doesn't seem to be valid syntax?

    cudatoolkit.overrideAttrs
    (finalAttrs: previousAttrs: {
      pname = previousAttrs.pname + "-bar";
      src = runCommandLocal "${previousAttrs.pname}.run" rec { } ''
        axel \
          --num-connections=10 \
          --verbose \
          --insecure \
          --output $out \
          "https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_520.61.05_linux.run"
      '';
    })

Error:

        at /nix/store/0g53xyh39z3y90p4d8r341wbqyjy1zhl-source/pkgs/stdenv/generic/make-derivation.nix:395:7:

          394|       depsHostHost                = elemAt (elemAt dependencies 1) 0;
          395|       buildInputs                 = elemAt (elemAt dependencies 1) 1;
             |       ^
          396|       depsTargetTarget            = elemAt (elemAt dependencies 2) 0;

       error: Dependency is not of a valid type: element 13 of buildInputs for cuda-env-shell

1 Answer 1

3

In the first step, it is necessary to add parentheses around the expression (cudatoolkit.overrideAttrs (finalAttrs: previousAttrs: { .. })) to avoid breaking the list.

In the second step, it is necessary to add an outputHash to enable the builder to accept the downloaded source. Initially, you can use

src = runCommandLocal "${previousAttrs.pname}.run" {
  outputHashMode = "flat";
  outputHashAlgo = "sha256";
  outputHash = "";
}

to trigger an error that displays the hash of the source. In this case, I obtained the hash: sha256-kiPErzrr5Ke77Zq9mxY7A6GzS4VfvCtKDRtwasCaWhY=.

Finally, it is necessary to add axel to the environment executing the command. Since it is only used for downloading the source, you can add it to thenativeBuildInputs of runCommandLocal. Additionally, you can replace axel in the script with ${pkgs.axel}/bin/axel.

{pkgs ? import <nixpkgs> {}}:
pkgs.mkShell {
  name = "cuda-env-shell";
  buildInputs = with pkgs; [

    (cudatoolkit.overrideAttrs (finalAttrs: previousAttrs: {
      pname = previousAttrs.pname;
      src =
        runCommandLocal "${previousAttrs.pname}.run" {
          nativeBuildsInputs = [axel];
          # outputHashMode = "flat";
          # outputHashAlgo = "sha256";
          # outputHash = "";
          outputHash = "sha256-kiPErzrr5Ke77Zq9mxY7A6GzS4VfvCtKDRtwasCaWhY=";
        } ''
          # ${pkgs.axel}/bin/axel \
          axel \
            --num-connections=10 \
            --verbose \
            --insecure \
            --output "$out" \
            "https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_520.61.05_linux.run"
        '';
    }))
  ];
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .