From 76ed9f96cadcc353cec06c835ea7e2f91f4f5d26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20de=20Kok?= Date: Thu, 28 Aug 2025 07:53:10 +0000 Subject: [PATCH 1/2] Update hf-nix and remove `sanitiseHeaderPathsHook` workaround `sanitiseHeaderPathsHook` was removed upstream in favor of another solution that does not cause rebuild in CUDA packages. --- flake.lock | 20 ++++++++++---------- flake.nix | 3 ++- pkgs/stdenv-glibc-2_27/default.nix | 9 +-------- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/flake.lock b/flake.lock index 6d27cab3..05496b33 100644 --- a/flake.lock +++ b/flake.lock @@ -17,11 +17,11 @@ }, "flake-compat_2": { "locked": { - "lastModified": 1733328505, - "narHash": "sha256-NeCCThCEP3eCl2l/+27kNNK7QrwZB1IJCrXfrbv5oqU=", + "lastModified": 1747046372, + "narHash": "sha256-CIVLLkVgvHYbgI2UpXvIIBJ12HWgX+fjA8Xf8PUmqCY=", "owner": "edolstra", "repo": "flake-compat", - "rev": "ff81ac966bb2cae68946d5ed5fc4994f96d0ffec", + "rev": "9100a0f413b0c601e0533d1d94ffd501ce2e7885", "type": "github" }, "original": { @@ -73,11 +73,11 @@ "nixpkgs": "nixpkgs" }, "locked": { - "lastModified": 1754038838, - "narHash": "sha256-oHigCT4z0ayyLyEuxdZooSXRAZP8lfOkZHzY1lx1U50=", + "lastModified": 1756316789, + "narHash": "sha256-DJvw0l+PXeFq963L3sbqAQKjIwGPae+yWpZHraFES28=", "owner": "huggingface", "repo": "hf-nix", - "rev": "336f781fa284e193baa3d4c3ce3f95fb34e9ffad", + "rev": "57ea72ac74c89331005c47bb082b28cef653bed8", "type": "github" }, "original": { @@ -88,17 +88,17 @@ }, "nixpkgs": { "locked": { - "lastModified": 1752785354, - "narHash": "sha256-Y33ryUz7MPqKrZwlbQcsYCUz2jAJCacRf8jbs0tYUlA=", + "lastModified": 1755963616, + "narHash": "sha256-6yD0ww/S8n+U2uPYcJZ3DRURP8Kx036GRpR2uPNZroE=", "owner": "nixos", "repo": "nixpkgs", - "rev": "d38025438a6ee456758dc03188ca6873a415463b", + "rev": "73e96df7cff5783f45e21342a75a1540c4eddce4", "type": "github" }, "original": { "owner": "nixos", + "ref": "nixos-unstable-small", "repo": "nixpkgs", - "rev": "d38025438a6ee456758dc03188ca6873a415463b", "type": "github" } }, diff --git a/flake.nix b/flake.nix index 204d9144..0ec65c0c 100644 --- a/flake.nix +++ b/flake.nix @@ -157,7 +157,8 @@ }; } ); - } // defaultBuildPerSystem; + } + // defaultBuildPerSystem; in flake-utils.lib.eachSystem systems ( system: diff --git a/pkgs/stdenv-glibc-2_27/default.nix b/pkgs/stdenv-glibc-2_27/default.nix index e6795e04..70c07d4c 100644 --- a/pkgs/stdenv-glibc-2_27/default.nix +++ b/pkgs/stdenv-glibc-2_27/default.nix @@ -6,7 +6,6 @@ system, wrapBintoolsWith, wrapCCWith, - writeClosure, gcc12Stdenv, stdenv, bintools-unwrapped, @@ -72,11 +71,5 @@ let in overrideCC stdenv compilerWrapped; - # Workaround for: https://github.com/NixOS/nixpkgs/issues/428546 - ccWithoutHook = ((if cudaSupport then cudaPackages.backendStdenv else gcc12Stdenv).cc.cc).override { - # Just some null derivation to disable the hook. - sanitiseHeaderPathsHook = writeClosure [ ]; - }; - in -stdenvWith glibc_2_27 ccWithoutHook stdenv +stdenvWith glibc_2_27 (if cudaSupport then cudaPackages.backendStdenv else gcc12Stdenv).cc.cc stdenv From 9d8a5af355683ec2f8ff7ea80880e2f1acbfe4cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20de=20Kok?= Date: Thu, 28 Aug 2025 07:55:00 +0000 Subject: [PATCH 2/2] nix fmt --- lib/torch-extension-noarch/default.nix | 13 +- lib/torch-extension/default.nix | 158 ++++++++++++------------- pkgs/stdenv-glibc-2_27/default.nix | 8 +- 3 files changed, 86 insertions(+), 93 deletions(-) diff --git a/lib/torch-extension-noarch/default.nix b/lib/torch-extension-noarch/default.nix index 503c569e..f234b95f 100644 --- a/lib/torch-extension-noarch/default.nix +++ b/lib/torch-extension-noarch/default.nix @@ -23,13 +23,12 @@ stdenv.mkDerivation (prevAttrs: { # also get torch as a build input. buildInputs = [ torch ]; - nativeBuildInputs = - [ - build2cmake - ] - ++ lib.optionals doGetKernelCheck [ - get-kernel-check - ]; + nativeBuildInputs = [ + build2cmake + ] + ++ lib.optionals doGetKernelCheck [ + get-kernel-check + ]; dontBuild = true; diff --git a/lib/torch-extension/default.nix b/lib/torch-extension/default.nix index 84c708db..25606147 100644 --- a/lib/torch-extension/default.nix +++ b/lib/torch-extension/default.nix @@ -82,50 +82,48 @@ stdenv.mkDerivation (prevAttrs: { chmod -R u+w . ''; - nativeBuildInputs = + nativeBuildInputs = [ + kernel-abi-check + cmake + ninja + build2cmake + ] + ++ lib.optionals doGetKernelCheck [ + get-kernel-check + ] + ++ lib.optionals cudaSupport [ + cmakeNvccThreadsHook + cudaPackages.cuda_nvcc + ] + ++ lib.optionals rocmSupport [ + clr + ] + ++ lib.optionals stdenv.hostPlatform.isDarwin [ + rewrite-nix-paths-macho + ]; + + buildInputs = [ + torch + torch.cxxdev + ] + ++ lib.optionals cudaSupport ( + with cudaPackages; [ - kernel-abi-check - cmake - ninja - build2cmake + cuda_cudart + + # Make dependent on build configuration dependencies once + # the Torch dependency is gone. + cuda_cccl + libcublas + libcusolver + libcusparse ] - ++ lib.optionals doGetKernelCheck [ - get-kernel-check - ] - ++ lib.optionals cudaSupport [ - cmakeNvccThreadsHook - cudaPackages.cuda_nvcc - ] - ++ lib.optionals rocmSupport [ - clr - ] - ++ lib.optionals stdenv.hostPlatform.isDarwin [ - rewrite-nix-paths-macho - ]; - - buildInputs = - [ - torch - torch.cxxdev - ] - ++ lib.optionals cudaSupport ( - with cudaPackages; - [ - cuda_cudart - - # Make dependent on build configuration dependencies once - # the Torch dependency is gone. - cuda_cccl - libcublas - libcusolver - libcusparse - ] - ) - ++ lib.optionals rocmSupport (with rocmPackages; [ hipsparselt ]) - ++ lib.optionals stdenv.hostPlatform.isDarwin [ - apple-sdk_15 - ] - ++ extraDeps; + ) + ++ lib.optionals rocmSupport (with rocmPackages; [ hipsparselt ]) + ++ lib.optionals stdenv.hostPlatform.isDarwin [ + apple-sdk_15 + ] + ++ extraDeps; env = lib.optionalAttrs cudaSupport { @@ -143,45 +141,43 @@ stdenv.mkDerivation (prevAttrs: { # If we use the default setup, CMAKE_CUDA_HOST_COMPILER gets set to nixpkgs g++. dontSetupCUDAToolkitCompilers = true; - cmakeFlags = - [ - (lib.cmakeFeature "Python_EXECUTABLE" "${python3.withPackages (ps: [ torch ])}/bin/python") - ] - ++ lib.optionals cudaSupport [ - (lib.cmakeFeature "CMAKE_CUDA_HOST_COMPILER" "${stdenv.cc}/bin/g++") - ] - ++ lib.optionals rocmSupport [ - # Ensure sure that we use HIP from our CLR override and not HIP from - # the symlink-joined ROCm toolkit. - (lib.cmakeFeature "CMAKE_HIP_COMPILER_ROCM_ROOT" "${clr}") - (lib.cmakeFeature "HIP_ROOT_DIR" "${clr}") - ] - ++ lib.optionals stdenv.hostPlatform.isDarwin [ - # Use host compiler for Metal. Not included in the redistributable SDK. - (lib.cmakeFeature "METAL_COMPILER" "${xcrunHost}/bin/xcrunHost") - ]; - - postInstall = - '' - ( - cd .. - cp -r torch-ext/${extensionName} $out/ - ) - cp $out/_${extensionName}_*/* $out/${extensionName} - rm -rf $out/_${extensionName}_* - '' - + (lib.optionalString (stripRPath && stdenv.hostPlatform.isLinux)) '' - find $out/${extensionName} -name '*.so' \ - -exec patchelf --set-rpath "" {} \; - '' - + (lib.optionalString (stripRPath && stdenv.hostPlatform.isDarwin)) '' - find $out/${extensionName} -name '*.so' \ - -exec rewrite-nix-paths-macho {} \; - - # Stub some rpath. - find $out/${extensionName} -name '*.so' \ - -exec install_name_tool -add_rpath "@loader_path/lib" {} \; - ''; + cmakeFlags = [ + (lib.cmakeFeature "Python_EXECUTABLE" "${python3.withPackages (ps: [ torch ])}/bin/python") + ] + ++ lib.optionals cudaSupport [ + (lib.cmakeFeature "CMAKE_CUDA_HOST_COMPILER" "${stdenv.cc}/bin/g++") + ] + ++ lib.optionals rocmSupport [ + # Ensure sure that we use HIP from our CLR override and not HIP from + # the symlink-joined ROCm toolkit. + (lib.cmakeFeature "CMAKE_HIP_COMPILER_ROCM_ROOT" "${clr}") + (lib.cmakeFeature "HIP_ROOT_DIR" "${clr}") + ] + ++ lib.optionals stdenv.hostPlatform.isDarwin [ + # Use host compiler for Metal. Not included in the redistributable SDK. + (lib.cmakeFeature "METAL_COMPILER" "${xcrunHost}/bin/xcrunHost") + ]; + + postInstall = '' + ( + cd .. + cp -r torch-ext/${extensionName} $out/ + ) + cp $out/_${extensionName}_*/* $out/${extensionName} + rm -rf $out/_${extensionName}_* + '' + + (lib.optionalString (stripRPath && stdenv.hostPlatform.isLinux)) '' + find $out/${extensionName} -name '*.so' \ + -exec patchelf --set-rpath "" {} \; + '' + + (lib.optionalString (stripRPath && stdenv.hostPlatform.isDarwin)) '' + find $out/${extensionName} -name '*.so' \ + -exec rewrite-nix-paths-macho {} \; + + # Stub some rpath. + find $out/${extensionName} -name '*.so' \ + -exec install_name_tool -add_rpath "@loader_path/lib" {} \; + ''; doInstallCheck = true; diff --git a/pkgs/stdenv-glibc-2_27/default.nix b/pkgs/stdenv-glibc-2_27/default.nix index 70c07d4c..d6f85c55 100644 --- a/pkgs/stdenv-glibc-2_27/default.nix +++ b/pkgs/stdenv-glibc-2_27/default.nix @@ -32,11 +32,9 @@ let outputs = prevAttrs.outputs ++ [ "getent" ]; - postInstall = - prevAttrs.postInstall - + '' - install -Dm755 $bin/bin/getent -t $getent/bin - ''; + postInstall = prevAttrs.postInstall + '' + install -Dm755 $bin/bin/getent -t $getent/bin + ''; passthru = prevAttrs.passthru // { # Should be stdenv's gcc, but we don't have access to it.