From 45c99f4fc258d97ebce0b5ea93535dd68dc46664 Mon Sep 17 00:00:00 2001 From: Gaetan Lepage Date: Sun, 31 May 2026 12:40:55 +0000 Subject: [PATCH] python3Packages.triton: better stdenv selection --- .../python-modules/triton/default.nix | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/pkgs/development/python-modules/triton/default.nix b/pkgs/development/python-modules/triton/default.nix index ee789827b3e9..72e8df58f076 100644 --- a/pkgs/development/python-modules/triton/default.nix +++ b/pkgs/development/python-modules/triton/default.nix @@ -42,7 +42,10 @@ cudaSupport ? config.cudaSupport, }: -buildPythonPackage (finalAttrs: { +let + effectiveStdenv = if cudaSupport then cudaPackages.backendStdenv else stdenv; +in +buildPythonPackage.override { stdenv = effectiveStdenv; } (finalAttrs: { pname = "triton"; version = "3.7.0"; pyproject = true; @@ -105,9 +108,7 @@ buildPythonPackage (finalAttrs: { substituteInPlace python/triton/runtime/build.py \ --replace-fail \ 'cc = os.environ.get("CC")' \ - 'cc = os.environ.get("CC", "${ - lib.getExe' (if cudaSupport then cudaPackages.backendStdenv.cc else stdenv.cc) "cc" - }")' + 'cc = os.environ.get("CC", "${lib.getExe' effectiveStdenv.cc "cc"}")' '' # triton will try dlopening libcublas.so at runtime @@ -178,9 +179,6 @@ buildPythonPackage (finalAttrs: { TRITON_OFFLINE_BUILD = true; } // lib.optionalAttrs cudaSupport { - CC = lib.getExe' cudaPackages.backendStdenv.cc "cc"; - CXX = lib.getExe' cudaPackages.backendStdenv.cc "c++"; - NIX_CFLAGS_COMPILE = toString [ # Pybind11 started generating strange errors since python 3.12. Observed only in the CUDA branch. # https://gist.github.com/SomeoneSerge/7d390b2b1313957c378e99ed57168219#file-gistfile0-txt-L1042 @@ -220,7 +218,7 @@ buildPythonPackage (finalAttrs: { ]; passthru = { - gpuCheck = stdenv.mkDerivation { + gpuCheck = effectiveStdenv.mkDerivation { pname = "triton-pytest"; inherit (triton) version src; @@ -384,7 +382,7 @@ buildPythonPackage (finalAttrs: { if os.environ.get("HOME", None) == "/homeless-shelter": os.environ["HOME"] = os.environ.get("TMPDIR", "/tmp") if "CC" not in os.environ: - os.environ["CC"] = "${lib.getExe' cudaPackages.backendStdenv.cc "cc"}" + os.environ["CC"] = "${lib.getExe' effectiveStdenv.cc "cc"}" torch.manual_seed(0) size = 12345 x = torch.rand(size, device='cuda')