Failing to build Package With CUDA

Hy, i’m including CUDA in my derivation so that StarPU can enable CUDA features. The problem is that it fails to build. The current version relates an error with GCC 14.3 which is know with CUDA.

/nix/store/82kmz7r96navanrc2fgckh2bamiqrgsw-gcc-14.3.0/include/c++/14.3.0/type_traits(1610): error: "__is_nothrow_new_constructible" is not a function or static da>
      constexpr bool __is_nothrow_new_constructible
                     ^

/nix/store/82kmz7r96navanrc2fgckh2bamiqrgsw-gcc-14.3.0/include/c++/14.3.0/type_traits(1610): error: "constexpr" is not valid here
      constexpr bool __is_nothrow_new_constructible
      ^

  CC       datawizard/data_deinitialize.o
/nix/store/82kmz7r96navanrc2fgckh2bamiqrgsw-gcc-14.3.0/include/c++/14.3.0/bits/stl_pair.h(1190): error: "__is_pair" is not a function or static data member
      inline constexpr bool __is_pair = false;
                            ^

/nix/store/82kmz7r96navanrc2fgckh2bamiqrgsw-gcc-14.3.0/include/c++/14.3.0/bits/stl_pair.h(1190): error: "constexpr" is not valid here
      inline constexpr bool __is_pair = false;
             ^

/nix/store/82kmz7r96navanrc2fgckh2bamiqrgsw-gcc-14.3.0/include/c++/14.3.0/bits/stl_pair.h(1193): error: __is_pair is not a template
      inline constexpr bool __is_pair<pair<_Tp, _Up>> = true;
                            ^

/nix/store/82kmz7r96navanrc2fgckh2bamiqrgsw-gcc-14.3.0/include/c++/14.3.0/bits/stl_pair.h(1193): error: "constexpr" is not valid here
      inline constexpr bool __is_pair<pair<_Tp, _Up>> = true;
             ^

In file included from /nix/store/gf3wh0x0rzb1dkx0wx1jvmipydwfzzd5-glibc-2.40-66-dev/include/bits/libc-header-start.h:33,
                 from /nix/store/gf3wh0x0rzb1dkx0wx1jvmipydwfzzd5-glibc-2.40-66-dev/include/stdio.h:28,
                 from datawizard/data_deinitialize.c:18:

Sadly i do not have the option to build with gcc15Stdenv because StarPU doesn’t build with it.
Reading the Nix Cuda Docs it says to not build with cudaPackages.cudatoolkit. But then i don’t know which packages should i use. What is the base CUDA package to use? By using any of them as a stub, i get the error of a missing cuda.h, which package provides that?

Any help is of help, here i’ve attached the derivation followed by the flake that invokes it.

{ 
  # derivation dependencies
  lib,
  fetchurl,
  stdenv,
  writableTmpDirAsHomeHook,
  autoreconfHook,
  # starpu dependencies
  hwloc,
  libuuid,
  libX11,
  fftw,
  fftwFloat, # Same than previous but with float precision
  pkg-config,
  libtool,
  simgrid,
  mpi,
  cudaPackages,

  python313,
  fxt,

  # Options
  buildMode ? "debug",
  maxBuffers ? 8,
  enableSimgrid ? false,
  enableMPI ? false,
  enableCUDA ? false,
  enableTrace ? false,
}:
stdenv.mkDerivation (finalAttrs: {
    pname = "StarPU";
    system = "x86_64-linux";
    version = "1.4.7";

    inherit buildMode;
    inherit maxBuffers;
    inherit enableSimgrid;
    inherit enableMPI;
    inherit enableCUDA;
    inherit enableTrace;

    src = fetchurl {
        url = "http://files.inria.fr/starpu/starpu-${finalAttrs.version}/starpu-${finalAttrs.version}.tar.gz";
        hash = "sha256-HrPfVRCJFT/m4LFyrZURhDS0qB6p6qWiw4cl0NtTsT4=";
    };
    nativeBuildInputs = [
        pkg-config
        hwloc
        libtool
        writableTmpDirAsHomeHook
        autoreconfHook
        python313
    ] 
        ++ lib.optional finalAttrs.enableSimgrid simgrid
        ++ lib.optional finalAttrs.enableMPI mpi
        ++ lib.optional finalAttrs.enableCUDA cudaPackages.cudatoolkit;

    buildInputs = [
        libuuid
        libX11
        fftw
        fftwFloat
        hwloc

        fxt
    ]
        ++ lib.optional finalAttrs.enableSimgrid simgrid
        ++ lib.optional finalAttrs.enableMPI mpi
        ++ lib.optional finalAttrs.enableCUDA cudaPackages.cudatoolkit;


    configureFlags = [
        (lib.enableFeature true "quick-check")
        (lib.enableFeature false "build-examples")
        (lib.enableFeature finalAttrs.enableSimgrid "simgrid")

        (lib.enableFeature false "starpupy")

         # Static linking is mandatory for smpi
        (lib.enableFeature finalAttrs.enableMPI "mpi")
        (lib.enableFeature finalAttrs.enableMPI "mpi-check")
        (lib.enableFeature (!finalAttrs.enableMPI) "shared") 

        (lib.optional finalAttrs.enableTrace "--with-fxt=${fxt}")
    ] ++ (
        if finalAttrs.buildMode == "debug" then 
            [ "--enable-debug" "--enable-verbose" "--enable-spinlock-check" ]
        else
            if finalAttrs.buildMode == "release" then 
                [ "--enable-fast" ]
            else builtins.throw "unrecognized build mode"
    ) ++ (lib.optional (finalAttrs.maxBuffers != 8) "--enable-maxbuffers=${toString finalAttrs.maxBuffers}");


      # No need to add flags for CUDA, it should be detected by ./configure

      patchPhase = ''
        # Patch shebangs recursively because a lot of scripts are used
        shopt -s globstar
        patchShebangs --build **/*.in
      '';

      postConfigure = ''
        # Patch shebangs recursively because a lot of scripts are used
        shopt -s globstar
        patchShebangs --build **/*.sh
      '';

      enableParallelBuilding = true;
      doCheck = true;
})
{
    description = "A very basic flake";

    inputs = {
        nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
    };

    outputs = { self, nixpkgs }: 
    let 
        system = "x86_64-linux";
        starpuOverlay = f: p: {
            StarPU = p.callPackage ./starpu.nix { enableCUDA = true; };
        };
        fxtOverlay = f: p: {
            fxt = p.callPackage ./fxt.nix { static = true; };
        };
        pkgs = import nixpkgs {
            inherit system;
            config.allowUnfree = true;
            overlays = [ starpuOverlay fxtOverlay ];
        };
    in
    {
        packages.${system}.default = pkgs.StarPU;
        devShells.${system}.default = pkgs.mkShell {
            buildInputs = with pkgs; [
                pkg-config
                StarPU
                hwloc
                # for bash to work properlly inside vscode
                bashInteractive
                gdb
                gcc
                valgrind
            ];
            # export StarPU and hwloc store locations 
            # for use in vscode intellisence
            GCC_STORE_PATH = "${pkgs.gcc}";
            STARPU_STORE_PATH = "${pkgs.StarPU}";
            HWLOC_STORE_PATH = "${pkgs.hwloc.dev}";

            shellHook = ''
                export SHELL=/run/current-system/sw/bin/bash
                echo Added StarPU, Hwloc and gcc to ENV
                echo ${pkgs.fxt}
            '';
        };
    };
}


I have the exact comment on github that tells how to solve it.

By adding the cachix support and changing some lines i was able to successfully compile with CUDA. Github repo, flake.nix and starpu.nix. It seemed that changing to gcc13Stdenv did the trick, but i can’t be sure.

Then i tried to run the flake in the sub directory that actually uses the starpu.nix and it didn’t work. I have no idea why. As a test i copied the flake.nix of the super directory that worked and deleted the local flake.lock but it did not compile. The error was the same as reported in the github issue, as in even setting to use the gcc13Stdenv the compilations issues where from headers from gcc-14.3.

StarPU>   CC       datawizard/unpartition.o
StarPU> In file included from /nix/store/rwalsamz4246k8f1zzxa54qx7w3fbzdg-glibc-2.42-47-dev/include/bits/libc-header-start.h:33,
StarPU>                  from /nix/store/rwalsamz4246k8f1zzxa54qx7w3fbzdg-glibc-2.42-47-dev/include/stdlib.h:26,
StarPU>                  from ../include/starpu.h:21,
StarPU>                  from datawizard/manual_reduction.c:17:
StarPU> /nix/store/rwalsamz4246k8f1zzxa54qx7w3fbzdg-glibc-2.42-47-dev/include/features.h:435:4: warning: #warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Wcpp]
StarPU>   435 | #  warning _FORTIFY_SOURCE requires compiling with optimization (-O)
StarPU>       |    ^~~~~~~
StarPU> /nix/store/8y1dwd1pavxc4gv47fkri5y5179yqzan-gcc-14.3.0/include/c++/14.3.0/type_traits(1610): error: "__is_nothrow_new_constructible" is not a function or static data member
StarPU>       constexpr bool __is_nothrow_new_constructible
StarPU>                      ^
StarPU> 
StarPU> /nix/store/8y1dwd1pavxc4gv47fkri5y5179yqzan-gcc-14.3.0/include/c++/14.3.0/type_traits(1610): error: "constexpr" is not valid here
StarPU>       constexpr bool __is_nothrow_new_constructible

The problem:

  • Building starpu.nix on the root directory with flake.nix works, but building it from /dev/star-fletcher/flake.nix does not, even though they are the same files (with the exception of the path to starpu.nix).
  • The error generated is a compilation error known with CUDA and GCC-14.3, but it arrises in the sub directory even though starpu.nix uses gcc13Stdenv.

Questions

why the same file, same flake in a sub directory changes if it compiles or if it doesn’t?
why is this happening?

Fixed the issue

The package locks of the flakes referred to different commits of nixpkgs. Going back a few days i was able to locate a commit that worked and with experimentation I found that the cudaPackages.cudatoolkit and linuxPackages.nvideaPackages.stable were the one’s responsible for the errors. I don’t know why the newer versions fail to this known issue, but for now it’s fixed for me. I’ll check in a few weeks to see if any newer versions fix this issue.