···12121313To use one or more CUDA packages in an expression, give the expression a `cudaPackages` parameter, and in case CUDA is optional
1414```nix
1515-cudaSupport ? false
1616-cudaPackages ? {}
1515+{ config
1616+, cudaSupport ? config.cudaSupport
1717+, cudaPackages ? { }
1818+, ...
1919+}:
1720```
18211922When using `callPackage`, you can choose to pass in a different variant, e.g.
···11+From 982d38084f08950863b55043f36ce5548bd73635 Mon Sep 17 00:00:00 2001
22+From: Maximilian Bosch <maximilian@mbosch.me>
33+Date: Mon, 24 Jul 2023 19:12:25 +0200
44+Subject: [PATCH] Strip away BUILDCONFIG
55+66+The `BuildConfig` field in `libsofficeapp.so` includes the entire
77+`PKG_CONFIG_PATH` and subsequently references to a lot of `dev` outputs
88+of library dependencies blowing up the closure.
99+1010+Since this is not strictly needed and the inputs are comprehensible via
1111+`nix derivation show`, this doesn't bring a real benefit in the case of
1212+nixpkgs anyways.
1313+---
1414+ desktop/source/lib/init.cxx | 2 +-
1515+ 1 file changed, 1 insertion(+), 1 deletion(-)
1616+1717+diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
1818+index 8d830c0cbd00..fbdc86aa7115 100644
1919+--- a/desktop/source/lib/init.cxx
2020++++ b/desktop/source/lib/init.cxx
2121+@@ -7097,7 +7097,7 @@ static char* lo_getVersionInfo(SAL_UNUSED_PARAMETER LibreOfficeKit* /*pThis*/)
2222+ "\"ProductVersion\": \"%PRODUCTVERSION\", "
2323+ "\"ProductExtension\": \"%PRODUCTEXTENSION\", "
2424+ "\"BuildId\": \"%BUILDID\", "
2525+- "\"BuildConfig\": \"" BUILDCONFIG "\" "
2626++ "\"BuildConfig\": \"removed to avoid runtime dependencies against dev outputs of each dependency. Use 'nix derivation show' against the package to find out details about BuildConfig.\" "
2727+ "}"));
2828+ }
2929+3030+--
3131+2.40.1
3232+
+16
pkgs/applications/office/libreoffice/default.nix
···214214 tar -xf ${srcs.translations}
215215 '';
216216217217+ # Remove build config to reduce the amount of `-dev` outputs in the
218218+ # runtime closure. This was introduced in upstream commit
219219+ # cbfac11330882c7d0a817b6c37a08b2ace2b66f4, so the patch doesn't apply
220220+ # for 7.4.
221221+ patches = lib.optionals (lib.versionAtLeast version "7.5") [
222222+ ./0001-Strip-away-BUILDCONFIG.patch
223223+ ];
224224+225225+ # libreoffice tries to reference the BUILDCONFIG (e.g. PKG_CONFIG_PATH)
226226+ # in the binary causing the closure size to blow up because of many unnecessary
227227+ # dependencies to dev outputs. This behavior was patched away in nixpkgs
228228+ # (see above), make sure these don't leak again by accident.
229229+ disallowedRequisites = lib.concatMap
230230+ (x: lib.optional (x?dev) x.dev)
231231+ buildInputs;
232232+217233 ### QT/KDE
218234 #
219235 # configure.ac assumes that the first directory that contains headers and
+1-1
pkgs/applications/radio/urh/default.nix
···3333 homepage = "https://github.com/jopohl/urh";
3434 description = "Universal Radio Hacker: investigate wireless protocols like a boss";
3535 license = licenses.gpl3;
3636- platforms = platforms.linux;
3636+ platforms = platforms.unix;
3737 maintainers = with maintainers; [ fpletz ];
3838 };
3939}
···2424, libkrb5
2525, krb5
2626, makeWrapper
2727+, markForCudatoolkitRootHook
2728, ncurses5
2829, numactl
2930, nss
···3132, python3 # FIXME: CUDAToolkit 10 may still need python27
3233, pulseaudio
3334, requireFile
3535+, setupCudaHook
3436, stdenv
3537, backendStdenv # E.g. gcc11Stdenv, set in extension.nix
3638, unixODBC
···8082 addOpenGLRunpath
8183 autoPatchelfHook
8284 autoAddOpenGLRunpathHook
8585+ markForCudatoolkitRootHook
8386 ] ++ lib.optionals (lib.versionOlder version "11") [
8487 libsForQt5.wrapQtAppsHook
8588 ] ++ lib.optionals (lib.versionAtLeast version "11.8") [
8689 qt6Packages.wrapQtAppsHook
8790 ];
9191+ depsTargetTargetPropagated = [
9292+ setupCudaHook
9393+ ];
8894 buildInputs = lib.optionals (lib.versionOlder version "11") [
8995 libsForQt5.qt5.qtwebengine
9096 freeglut
···129135 (lib.getLib libtiff)
130136 qt6Packages.qtwayland
131137 rdma-core
132132- ucx
138138+ (ucx.override { enableCuda = false; }) # Avoid infinite recursion
133139 xorg.libxshmfence
134140 xorg.libxkbfile
135141 ] ++ (lib.optionals (lib.versionAtLeast version "12.1") (map lib.getLib ([
···280286 sed -i "1 i#define _BITS_FLOATN_H" "$out/include/host_defines.h"
281287 '' +
282288 # Point NVCC at a compatible compiler
283283- # FIXME: redist cuda_nvcc copy-pastes this code
284284- # Refer to comments in the overrides for cuda_nvcc for explanation
285289 # CUDA_TOOLKIT_ROOT_DIR is legacy,
286290 # Cf. https://cmake.org/cmake/help/latest/module/FindCUDA.html#input-variables
287287- # NOTE: We unconditionally set -Xfatbin=-compress-all, which reduces the size of the compiled
288288- # binaries. If binaries grow over 2GB, they will fail to link. This is a problem for us, as
289289- # the default set of CUDA capabilities we build can regularly cause this to occur (for
290290- # example, with Magma).
291291 ''
292292 mkdir -p $out/nix-support
293293 cat <<EOF >> $out/nix-support/setup-hook
294294 cmakeFlags+=' -DCUDA_TOOLKIT_ROOT_DIR=$out'
295295- cmakeFlags+=' -DCUDA_HOST_COMPILER=${backendStdenv.cc}/bin'
296296- cmakeFlags+=' -DCMAKE_CUDA_HOST_COMPILER=${backendStdenv.cc}/bin'
297297- if [ -z "\''${CUDAHOSTCXX-}" ]; then
298298- export CUDAHOSTCXX=${backendStdenv.cc}/bin;
299299- fi
300300- export NVCC_PREPEND_FLAGS+=' --compiler-bindir=${backendStdenv.cc}/bin -Xfatbin=-compress-all'
301295 EOF
302296303297 # Move some libraries to the lib output so that programs that
···11+# shellcheck shell=bash
22+33+# CMake's enable_language(CUDA) runs a compiler test and it doesn't account for
44+# CUDAToolkit_ROOT. We have to help it locate libcudart
55+export NVCC_APPEND_FLAGS+=" -L@cudartRoot@/lib -I@cudartRoot@/include"
···11+# shellcheck shell=bash
22+33+echo Sourcing setup-cuda-hook >&2
44+55+extendCUDAToolkit_ROOT() {
66+ if [[ -f "$1/nix-support/include-in-cudatoolkit-root" ]] ; then
77+ addToSearchPathWithCustomDelimiter ";" CUDAToolkit_ROOT "$1"
88+99+ if [[ -d "$1/include" ]] ; then
1010+ addToSearchPathWithCustomDelimiter ";" CUDAToolkit_INCLUDE_DIR "$1/include"
1111+ fi
1212+ fi
1313+}
1414+1515+addEnvHooks "$targetOffset" extendCUDAToolkit_ROOT
1616+1717+setupCUDAToolkitCompilers() {
1818+ echo Executing setupCUDAToolkitCompilers >&2
1919+2020+ if [[ -n "${dontSetupCUDAToolkitCompilers-}" ]] ; then
2121+ return
2222+ fi
2323+2424+ # Point NVCC at a compatible compiler
2525+2626+ # For CMake-based projects:
2727+ # https://cmake.org/cmake/help/latest/module/FindCUDA.html#input-variables
2828+ # https://cmake.org/cmake/help/latest/envvar/CUDAHOSTCXX.html
2929+ # https://cmake.org/cmake/help/latest/variable/CMAKE_CUDA_HOST_COMPILER.html
3030+3131+ export cmakeFlags+=" -DCUDA_HOST_COMPILER=@ccFullPath@"
3232+ export cmakeFlags+=" -DCMAKE_CUDA_HOST_COMPILER=@ccFullPath@"
3333+3434+ # For non-CMake projects:
3535+ # We prepend --compiler-bindir to nvcc flags.
3636+ # Downstream packages can override these, because NVCC
3737+ # uses the last --compiler-bindir it gets on the command line.
3838+ # FIXME: this results in "incompatible redefinition" warnings.
3939+ # https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#compiler-bindir-directory-ccbin
4040+ if [ -z "${CUDAHOSTCXX-}" ]; then
4141+ export CUDAHOSTCXX="@ccFullPath@";
4242+ fi
4343+4444+ export NVCC_PREPEND_FLAGS+=" --compiler-bindir=@ccRoot@/bin"
4545+4646+ # NOTE: We set -Xfatbin=-compress-all, which reduces the size of the compiled
4747+ # binaries. If binaries grow over 2GB, they will fail to link. This is a problem for us, as
4848+ # the default set of CUDA capabilities we build can regularly cause this to occur (for
4949+ # example, with Magma).
5050+ #
5151+ # @SomeoneSerge: original comment was made by @ConnorBaker in .../cudatoolkit/common.nix
5252+ if [[ -z "${dontCompressFatbin-}" ]]; then
5353+ export NVCC_PREPEND_FLAGS+=" -Xfatbin=-compress-all"
5454+ fi
5555+5656+ # CMake's enable_language(CUDA) runs a compiler test and it doesn't account for
5757+ # CUDAToolkit_ROOT. We have to help it locate libcudart
5858+ if [[ -z "${nvccDontPrependCudartFlags-}" ]] ; then
5959+ export NVCC_APPEND_FLAGS+=" -L@cudartRoot@/lib -I@cudartRoot@/include"
6060+ fi
6161+}
6262+6363+setupCMakeCUDAToolkit_ROOT() {
6464+ export cmakeFlags+=" -DCUDAToolkit_INCLUDE_DIR=$CUDAToolkit_INCLUDE_DIR -DCUDAToolkit_ROOT=$CUDAToolkit_ROOT"
6565+}
6666+6767+postHooks+=(setupCUDAToolkitCompilers)
6868+preConfigureHooks+=(setupCMakeCUDAToolkit_ROOT)
···2727 inherit (prev.backendStdenv) cc;
2828 in
2929 {
3030- # Point NVCC at a compatible compiler
3131- # FIXME: non-redist cudatoolkit copy-pastes this code
3030+ # Required by cmake's enable_language(CUDA) to build a test program
3131+ # When implementing cross-compilation support: this is
3232+ # final.pkgs.targetPackages.cudaPackages.cuda_cudart
3333+ env.cudartRoot = "${prev.lib.getDev final.cuda_cudart}";
32343333- # For CMake-based projects:
3434- # https://cmake.org/cmake/help/latest/module/FindCUDA.html#input-variables
3535- # https://cmake.org/cmake/help/latest/envvar/CUDAHOSTCXX.html
3636- # https://cmake.org/cmake/help/latest/variable/CMAKE_CUDA_HOST_COMPILER.html
3535+ # Point NVCC at a compatible compiler
37363838- # For non-CMake projects:
3939- # We prepend --compiler-bindir to nvcc flags.
4040- # Downstream packages can override these, because NVCC
4141- # uses the last --compiler-bindir it gets on the command line.
4242- # FIXME: this results in "incompatible redefinition" warnings.
4343- # https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#compiler-bindir-directory-ccbin
4444- # NOTE: We unconditionally set -Xfatbin=-compress-all, which reduces the size of the
4545- # compiled binaries. If binaries grow over 2GB, they will fail to link. This is a problem
4646- # for us, as the default set of CUDA capabilities we build can regularly cause this to
4747- # occur (for example, with Magma).
4848- postInstall = (oldAttrs.postInstall or "") + ''
4949- mkdir -p $out/nix-support
5050- cat <<EOF >> $out/nix-support/setup-hook
5151- cmakeFlags+=' -DCUDA_HOST_COMPILER=${cc}/bin'
5252- cmakeFlags+=' -DCMAKE_CUDA_HOST_COMPILER=${cc}/bin'
5353- if [ -z "\''${CUDAHOSTCXX-}" ]; then
5454- export CUDAHOSTCXX=${cc}/bin;
5555- fi
5656- export NVCC_PREPEND_FLAGS+=' --compiler-bindir=${cc}/bin -Xfatbin=-compress-all'
5757- EOF
5858- '';
3737+ # Desiredata: whenever a package (e.g. magma) adds cuda_nvcc to
3838+ # nativeBuildInputs (offsets `(-1, 0)`), magma should also source the
3939+ # setupCudaHook, i.e. we want it the hook to be propagated into the
4040+ # same nativeBuildInputs.
4141+ #
4242+ # Logically, cuda_nvcc should include the hook in depsHostHostPropagated,
4343+ # so that the final offsets for the propagated hook would be `(-1, 0) +
4444+ # (0, 0) = (-1, 0)`.
4545+ #
4646+ # In practice, TargetTarget appears to work:
4747+ # https://gist.github.com/fd80ff142cd25e64603618a3700e7f82
4848+ depsTargetTargetPropagated = [
4949+ final.setupCudaHook
5050+ ];
5951 });
60526153 cuda_nvprof = prev.cuda_nvprof.overrideAttrs (oldAttrs: {
···44, avxSupport ? stdenv.hostPlatform.avxSupport
55, avx2Support ? stdenv.hostPlatform.avx2Support
66, avx512Support ? stdenv.hostPlatform.avx512Support
77+, config
78# Enable NIVIA GPU support
89# Note, that this needs to be built on a system with a GPU
910# present for the tests to succeed.
1010-, enableCuda ? false
1111+, enableCuda ? config.cudaSupport
1112# type of GPU architecture
1213, nvidiaArch ? "sm_60"
1314, cudatoolkit
···1717# that in nix as well. It would make some things easier and less confusing, but
1818# it would also make the default tensorflow package unfree. See
1919# https://groups.google.com/a/tensorflow.org/forum/#!topic/developers/iRCt5m4qUz0
2020-, cudaSupport ? false
2020+, config
2121+, cudaSupport ? config.cudaSupport
2122, cudaPackages ? { }
2223, cudaCapabilities ? cudaPackages.cudaFlags.cudaCapabilities
2324, mklSupport ? false, mkl
···11-# Wrap only the haskell-related tests from tests.writers
22-# in their own derivation for Hydra CI in the haskell-updates
33-# jobset. Can presumably removed as soon as tests.writers is
44-# always green on darwin as well:
55-# https://github.com/NixOS/nixpkgs/issues/126182
66-{ runCommand, tests }:
77-88-let
99- inherit (tests.writers)
1010- writeTest
1111- bin
1212- simple
1313- path
1414- ;
1515-in
1616-1717-runCommand "test-haskell-writers" {
1818- meta = {
1919- inherit (tests.writers.meta) platforms;
2020- };
2121-} ''
2222- ${writeTest "success" "test-haskell-bin-writer" "${bin.haskell}/bin/${bin.haskell.name}"}
2323- ${writeTest "success" "test-haskell-simple-writer" simple.haskell}
2424- ${writeTest "success" "test-haskell-path-writer" path.haskell}
2525- touch $out
2626-''