I’m trying to set up a FHSEnv for a project that needs gcc and libgcc. As far as i can see this should be done by adding stdenv.cc.cc.libgcc to buildFHSEnv’s targetPkgs, but as soon as i do that, the linker’s include paths seem to get scrambled:
flake.nix:
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem
(system:
let
overlays = [ ];
pkgs = import nixpkgs {
inherit system overlays;
};
in
{
devShells.default = (pkgs.buildFHSUserEnv {
name = "my-env";
targetPkgs = pkgs: [
pkgs.stdenv.cc.libc.static
pkgs.stdenv.cc.libc_dev
pkgs.stdenv.cc.cc.libgcc
pkgs.stdenv.cc
pkgs.zlib
pkgs.zlib.dev
pkgs.cmake
pkgs.python3
];
runScript = "bash";
}).env;
}
);
}
$ nix develop
$ cat test.c
#include <stdio.h>
void main() {
printf("hello");
}
$ gcc test.c
/nix/store/p0p56gzz837fgmfd7lyisghcd7x2fdlc-binutils-2.40/bin/ld: cannot find crt1.o: No such file or directory
/nix/store/p0p56gzz837fgmfd7lyisghcd7x2fdlc-binutils-2.40/bin/ld: cannot find crti.o: No such file or directory
collect2: error: ld returned 1 exit status
When I remove pkgs.stdenv.cc.cc.libgcc from flake.nix, gcc test.c
works fine. It looks like adding libgcc also changes gcc’s configuration; Comparing the output of gcc -v test.c
, I’m seeing
COLLECT_GCC=gcc
when running with libgcc and
COLLECT_GCC=/nix/store/cmr8qd8w64w8q0cbfc30p98z2pydc1k7-gcc-13.2.0/bin/gcc
without. Furthermore all the -B
, -idirafter
and -L
options are missing in COLLECT_GCC_OPTIONS
when running with libgcc, and the #include
resolution is missing the /usr/include
path.
Am i missing something? Is pkgs.stdenv.cc.cc.libgcc just not compatible with buildFHSUserEnv?