Remove entries from NIX_CFLAGS_COMPILE?

I have a nix shell where I include the apple sdk for my dev environment:

{}:
let
  sources = import ./npins;
  pkgs = import sources.nixpkgs {};
  stdenv = pkgs.stdenv;
  apple_sdk = pkgs.darwin.apple_sdk_11_0;
  frameworks = apple_sdk.frameworks;
in
stdenv.mkDerivation {
  name = "nix-shell";
  phases = ["nobuildPhase"];
  buildInputs =
    with pkgs; [
      cmake
      ninja
      npins
      git
    ] ++ lib.optionals stdenv.isDarwin [
      apple_sdk.objc4
      frameworks.Metal
    ];

  nobuildPhase = ''
    echo
    echo "This derivation is not meant to be built, aborting";
    echo
    exit 1
  '';
}

My build fails since there’s a duplicate framework entry for libobjc:

$ echo $NIX_CFLAGS_COMPILE
-frandom-seed=ld4cls5q42 -isystem /nix/store/k8gdy8ddn735mpi11n06g92ksg34qy41-libcxx-11.1.0-dev/include -isystem /nix/store/c59mv12f7w22xkskdpf3lmlr4h2yz861-libcxxabi-11.1.0-dev/include -isystem /nix/store/1ipv848xhh75rdx3s2vzn97iy054nh5f-libobjc-11.0.0/include -iframework /nix/store/kvj89jjaj96bg2ymsw7ya1dmvxlj82b1-apple-framework-Metal-11.0.0/Library/Frameworks -iframework /nix/store/pq8lk32fvns3s3ga5qk7caml6nzg44g5-apple-framework-CoreFoundation-11.0.0/Library/Frameworks -isystem /nix/store/zds0nj0gjmyq9g4yy347vm625r6rp22i-libobjc-11.0.0/include -isystem /nix/store/k8gdy8ddn735mpi11n06g92ksg34qy41-libcxx-11.1.0-dev/include -isystem /nix/store/c59mv12f7w22xkskdpf3lmlr4h2yz861-libcxxabi-11.1.0-dev/include -isystem /nix/store/1ipv848xhh75rdx3s2vzn97iy054nh5f-libobjc-11.0.0/include -iframework /nix/store/kvj89jjaj96bg2ymsw7ya1dmvxlj82b1-apple-framework-Metal-11.0.0/Library/Frameworks -iframework /nix/store/pq8lk32fvns3s3ga5qk7caml6nzg44g5-apple-framework-CoreFoundation-11.0.0/Library/Frameworks -isystem /nix/store/zds0nj0gjmyq9g4yy347vm625r6rp22i-libobjc-11.0.0/include

As you can see, there’s /nix/store/zds0nj0gjmyq9g4yy347vm625r6rp22i-libobjc-11.0.0 and /nix/store/1ipv848xhh75rdx3s2vzn97iy054nh5f-libobjc-11.0.0 providing libobjc and that causes problems for my build. I can remove it manually, but I would like to avoid that and remove that duplicate entry from the nix file directly. Is there a way to do that cleanly? Thanks.

Someone can correct me if I’m wrong. But stdenv on darwin also has a apple_sdk included in it. You will most likely need to overrid stdenv to have the version you want. The other option is just to not explicitly include it if the one you’re introducing is causing the failures.

If someone can help me getting to know how to override parts of the stdenv I would be more than grateful :slight_smile:

the last bullet point in https://github.com/NixOS/nixpkgs/blob/7fe922b3582af42aedf05228d10702cb7d184293/doc/stdenv/platform-notes.chapter.md is what you are searching for.

Sorry for being really beginner, but I thought callPackage was useful for calling other nix scripts right? How can it be useful inside my shell file since I’m not even using callPackage, is there a way to wrap my shell in that to get only version 11 of the sdk?

That is problem, indeed.

Maybe you can use pkgs.darwin.apple_sdk_11_0.stdenv?

Hmm, it doesn’t seem to fix the problem, compiling my app still yield this error:

/nix/store/xprm48c6sprazy9hwwmf6g17ww4b30n8-libobjc-11.0.0/include/objc/module.modulemap:1:8: error: redefinition of module 'ObjectiveC'
module ObjectiveC [system] [extern_c] {
       ^
/nix/store/skfji9ww4c9in9r9m5258yzha9p7rdzw-libobjc-11.0.0/include/objc/module.modulemap:1:8: note: previously defined here
module ObjectiveC [system] [extern_c] {
       ^
1 error generated.

My nix shell has been changed to that:

{}:
let
  sources = import ./npins;
  pkgs = import sources.nixpkgs {};
  apple_sdk = pkgs.darwin.apple_sdk_11_0;
  frameworks = apple_sdk.frameworks;
  stdenv = apple_sdk.stdenv;
in
stdenv.mkDerivation {
  # ...
}

But also I wanted to use clang14 in the future, but I’ve been told I need llvmPackages_14.stdenv to have the compiler wrapper, so I wouldn’t be able to change the compiler that way.