Commit f1ddae47 authored by Someone Serge's avatar Someone Serge
Browse files

cudaPackages: make getOutput work again

(cherry picked from commit a2954dea)
parent fc5487d0
Loading
Loading
Loading
Loading
+11 −8
Original line number Diff line number Diff line
@@ -166,13 +166,17 @@ filterAndCreateOverrides {
    };

  cuda_nvcc =
    {
      backendStdenv,
      cuda_cudart,
      lib,
      setupCudaHook,
    }:
    { backendStdenv, setupCudaHook }:
    prevAttrs: {
      # Merge "bin" and "dev" into "out" to avoid circular references
      outputs = builtins.filter (
        x:
        !(builtins.elem x [
          "dev"
          "bin"
        ])
      ) prevAttrs.outputs;

      # Patch the nvcc.profile.
      # Syntax:
      # - `=` for assignment,
@@ -230,8 +234,7 @@ filterAndCreateOverrides {
      };
    };

  cuda_nvprof =
    { cuda_cupti }: prevAttrs: { buildInputs = prevAttrs.buildInputs ++ [ cuda_cupti.lib ]; };
  cuda_nvprof = { cuda_cupti }: prevAttrs: { buildInputs = prevAttrs.buildInputs ++ [ cuda_cupti ]; };

  cuda_demo_suite =
    {
+10 −31
Original line number Diff line number Diff line
@@ -290,41 +290,23 @@ backendStdenv.mkDerivation (finalAttrs: {
    "libcuda.so.*"
  ];

  # The out output leverages the same functionality which backs the `symlinkJoin` function in
  # Nixpkgs:
  # https://github.com/NixOS/nixpkgs/blob/d8b2a92df48f9b08d68b0132ce7adfbdbc1fbfac/pkgs/build-support/trivial-builders/default.nix#L510
  #
  # That should allow us to emulate "fat" default outputs without having to actually create them.
  #
  # It is important that this run after the autoPatchelfHook, otherwise the symlinks in out will reference libraries in lib, creating a circular dependency.
  postPhases = [ "postPatchelf" ];
  # _multioutPropagateDev() currently expects a space-separated string rather than an array
  preFixup = ''
    export propagatedBuildOutputs="''${propagatedBuildOutputs[@]}"
  '';

  # For each output, create a symlink to it in the out output.
  # NOTE: We must recreate the out output here, because the setup hook will have deleted it if it was empty.
  # Propagate all outputs, including `static`
  propagatedBuildOutputs = builtins.filter (x: x != "dev") finalAttrs.outputs;

  # Kept in case overrides assume postPhases have already been defined
  postPhases = [ "postPatchelf" ];
  postPatchelf = ''
    mkdir -p "$out"
    for output in $(getAllOutputNames); do
      if [[ "$output" != "out" ]]; then
        ${meta.getExe lndir} "''${!output}" "$out"
      fi
    done
    true
  '';

  # Make the CUDA-patched stdenv available
  passthru.stdenv = backendStdenv;

  # Setting propagatedBuildInputs to false will prevent outputs known to the multiple-outputs
  # from depending on `out` by default.
  # https://github.com/NixOS/nixpkgs/blob/2920b6fc16a9ed5d51429e94238b28306ceda79e/pkgs/build-support/setup-hooks/multiple-outputs.sh#L196
  # Indeed, we want to do the opposite -- fat "out" outputs that contain all the other outputs.
  propagatedBuildOutputs = false;

  # By default, if the dev output exists it just uses that.
  # However, because we disabled propagatedBuildOutputs, dev doesn't contain libraries or
  # anything of the sort. To remedy this, we set outputSpecified to true, and use
  # outputsToInstall, which tells Nix which outputs to use when the package name is used
  # unqualified (that is, without an explicit output).
  outputSpecified = true;

  meta = {
    description = "${redistribRelease.name}. By downloading and using the packages you accept the terms and conditions of the ${finalAttrs.meta.license.shortName}";
@@ -343,8 +325,5 @@ backendStdenv.mkDerivation (finalAttrs: {
      lists.optionals isBadPlatform finalAttrs.meta.platforms;
    license = licenses.unfree;
    maintainers = teams.cuda.members;
    # Force the use of the default, fat output by default (even though `dev` exists, which
    # causes Nix to prefer that output over the others if outputSpecified isn't set).
    outputsToInstall = [ "out" ];
  };
})