Nix-darwin: override/overlay xcode + how to get a correct/working dev/build environment?

I wanted to overlay nixpkgs.darwin.xcode in a devshell flake to include newer versions that are not yet available.

I started here which gave me some basic understanding, but simply adding a modified xcode.nix to an overlay like so

final: prev: {
  darwin = prev.darwin // { inherit (prev.darwin.callPackage ./xcode.nix {}) xcode_15_2; };
  helloxx = prev.hello;
}

doesn’t work (though the overlay works (tested with hellox))
It says: error: attribute 'xcode_15_2' missing.

Did I do something wrong in the override of the darwin attribute in the overlay?

I tried to take a shortcut and directly do the derivation inline in buildInputs with the requireFile expression etc. from xcode.nix for my specific xcode version, but couldn’t get it to work, probably due to making mistakes in the chaining of expressions.

As a workaround I can get xcode working in a devShell flake without overlay by just doing the appleSDK thing in the below flake.

{
  description = "flutter shell";

  inputs = {
    # nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    flake-utils.url = "github:numtide/flake-utils";
  };

  outputs = { self, flake-utils, nixpkgs }:
    flake-utils.lib.eachDefaultSystem (system: {
      devShell =
        let
          pkgs = import nixpkgs {
            inherit system;
            config.allowUnfree = true;
            overlays =
              [ (import ./.nix/overlay) ]; # somehow doesn't work as expected?
          };

          inherit (pkgs) lib;

          appleSDK =
            if pkgs.stdenv.isDarwin then
              (pkgs.darwin.callPackage ./.nix/overlay/xcode.nix { }).xcode_15_2
            else
              { };

          myllvm = pkgs.llvmPackages_15;

          libs = with pkgs;
            if stdenv.isLinux then [
              atk
              at-spi2-core.dev
              dbus.dev
              gtk3
              pango
              cairo
              harfbuzz
              gdk-pixbuf
              glib # these are transitive but explicit here for the LD_LIBRARY_PATH
              fontconfig
              libdatrie
              libselinux
              libsepol
              pcre
              libthai
              libxkbcommon
              pcre2
              util-linux.dev
              xorg.libX11.dev
              xorg.libXdmcp
              xorg.libXtst
              libappindicator.dev
              libepoxy
              libdeflate
              gnome.zenity
            ] else if stdenv.isDarwin then
              [
                # libs needed for darwin
              ]
            else
              builtins.throw "Unsupported system (not Linux or Darwin)";
        in
        (pkgs.mkShell.override {
          stdenv =
            if pkgs.stdenv.isDarwin then
              pkgs.stdenv
            else
              myllvm.stdenv;
        }) {
          nativeBuildInputs = with pkgs;
            [ pkg-config ninja cmake dart flutter319 go envsubst ]
            ++ lib.optionals stdenv.isLinux [
              myllvm.bintools # https://matklad.github.io/2022/03/14/rpath-or-why-lld-doesnt-work-on-nixos.html
            ];

          buildInputs = libs ++ lib.optionals pkgs.stdenv.isLinux
            (with myllvm; [ libcxxClang libunwind ])
            ++ lib.optionals pkgs.stdenv.isDarwin (with pkgs;
            [
              # this whole stuff is prepared as follows:
              #    https://github.com/NixOS/nixpkgs/blob/032324fd20e3be4124ffefd00da5bd66b0550e8c/pkgs/os-specific/darwin/xcode/default.nix#L23-L32
              appleSDK
            ]);

          shellHook =
            if pkgs.stdenv.isDarwin then ''
              # PATH=${appleSDK}/Contents/Developer/usr/bin:${appleSDK}/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin:$PATH
              PATH=${appleSDK}/Contents/Developer/usr/bin:$PATH
              SDKROOT=${appleSDK}/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
            '' else
              "";
        };
    });
}

That even makes the flutter part of my project work.

BUT: depending on which PATH I set in the shellHook a go library I link into the flutter app won’t compile.

If I don’t set clang to the env’s Xcode (from Toolchain), I get

clang-16: error: cannot use 'cpp-output' output with multiple -arch options

and if I set the path I get

# runtime/cgo
_cgo_export.c:3:10: fatal error: 'stdlib.h' file not found

Anyway it seems that setting the paths for the stdenv by setting PATH in a shellHook is very hacky, is there a “natural” way to force the actually installed apple SDK?
(If I don’t set any paths I get the ancient SDK version 11). I guess that would more naturally solve library resolution?