I’m trying to replace and old shell.nix
that provided the development environment for some C++ code that needs to be compiled with cmake.
I have (essentially) replaced
{ pkgs ? import nix/pkgs.nix }:
let
derivation = pkgs.callPackage (import ./nix/derivation.nix) {};
in
pkgs.llvmPackages_13.stdenv.mkDerivation {
inherit (derivation) name;
nativeBuildInputs = derivation.nativeBuildInputs ++ [
pkgs.clang_13
];
buildInputs = derivation.buildInputs ++ [
pkgs.clang_13
pkgs.cmake
pkgs.cmake-language-server
];
}
with
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem
(system:
let pkgs = import nixpkgs {
inherit system;
overlays = [
(final: prev: {
my-derivation = final.callPackage nix/derivation.nix {};
})
];
};
in
{
devShell = pkgs.mkShell.override { stdenv = pkgs.clang13Stdenv; } {
name = "Geant4 development environment";
nativeBuildInputs = pkgs.my-derivation.nativeBuildInputs ++ [
pkgs.clang_13
];
buildInputs = pkgs.my-derivation.buildInputs ++ [
pkgs.clang_13
pkgs.cmake
pkgs.cmake-language-server
];
};
}
);
}
This environment is normally activated with direnv
, so I also changed .envrc
from use nix
to use flake
.
The code being developed in this environment needs to be compiled with C++17, so the top-level CMakeLists.txt
contains set(CMAKE_CXX_STANDARD 17)
.
Everything works as it should with the shell.nix
, but when using flake.nix
lots of compiler error along the lines of
In file included from /tmp/xxx/src/bbb/ccc/src/utils/enumerate-test.cc:1:
/tmp/xxx/src/bbb/ccc/src/utils/enumerate.hh:5:42: error: no member named 'begin' in namespace 'std'
typename TIter = decltype(std::begin(std::declval<T>())),
~~~~~^
appear.
At first I thought this was a symptom of the wrong version of the C++ standard being used, but after sifting through the diffs of the cmake-generated stuff, and thinking more about the error messages, I don’t really think that’s the case, any more.
It might be a more general problem with failure to find headers.
I’m struggling to see why/how the change from shell.nix
to flake.nix
would bring about this problem.
Any ideas?