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

Would you mind explaining your setup more?
I had originally this issue
but since a lot has improved!

I have a flake based direnv setup for a Flutter project.

I am using mkShellNoCC, I am assuming you do still as well?
When I write

export PATH=$(echo $PATH | sd "${pkgs.xcbuild.xcrun}/bin" "")
unset DEVELOPER_DIR

to the shellHook = the Flutter command isn’t found anymore.

My flake.nix works - but I would like to setup Xcode more idiomatic, if there is a recommended way. Currently I am using this workaround in shellHook = :

                      # installs or checks for the right xcode version
                      echo "installing xcode ${xcode_version}"
                      xcodes install ${xcode_version} --experimental-unxip # --directory "$PWD/.xcode"
                      xcodes select ${xcode_version}
This is my complete flake.nix file { description = "Flutter toolchain. Installs all tools needed for flutter, with versions pinned for this project. Rust's own tooling handles the rust toolchain."; # nix flutter doesn't work: https://github.com/NixOS/nixpkgs/issues/243448 # thus using a local installation inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; flake-utils.url = "github:numtide/flake-utils"; android-nixpkgs = { url = "github:tadfisher/android-nixpkgs"; inputs = { flake-utils.follows = "flake-utils"; nixpkgs.follows = "nixpkgs"; devshell.follows = "devshell"; }; }; devshell = { url = "github:numtide/devshell"; inputs = { nixpkgs.follows = "nixpkgs"; }; }; # share rust configuration with nix ... not really needed! # rust-overlay = { # url = "github:oxalica/rust-overlay"; # inputs = { # nixpkgs.follows = "nixpkgs"; # flake-utils.follows = "flake-utils"; # }; # }; };

outputs = { nixpkgs, flake-utils, android-nixpkgs, rust-overlay, … }:

outputs = { nixpkgs, flake-utils, android-nixpkgs, … }:
flake-utils.lib.eachDefaultSystem (system:
let
# overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
# inherit system overlays;
inherit system;
config = {
allowUnfree = true;
android_sdk = {
accept_license = true;
};
};
};
# rustToolchain = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
androidCustomPackage = android-nixpkgs.sdk.${system} (
sdkPkgs: with sdkPkgs; [
cmdline-tools-latest
build-tools-30-0-3
# build-tools-33-0-2
build-tools-34-0-0
ndk-23-1-7779620
# ndk-26-2-11394342
platform-tools
emulator
#patcher-v4
# platforms-android-28
platforms-android-33
platforms-android-34
system-images-android-34-aosp-atd-arm64-v8a #basic image, 40% faster
system-images-android-34-google-apis-arm64-v8a #google branded
system-images-android-34-google-apis-playstore-arm64-v8a #google branded with playstore installed
]
);
pinnedJDK = pkgs.jdk17;
xcode_version = “15.4.0”;
frb_version = “latest”;
flutter_rust_bridge_codegen = import ./nix/flutter_rust_bridge_codegen.nix {
inherit pkgs frb_version;
};
appleInputs =
if builtins.elem system [ “aarch64-darwin” “x86_64-darwin” ] then [
pkgs.cocoapods
pkgs.xcodes
] else ;
in
{
devShells. default = pkgs.mkShellNoCC
{
name = “flutter-rust-dev-shell”;
buildInputs = with pkgs; [
just
# rustToolchain
flutter
pinnedJDK
androidCustomPackage
flutter_rust_bridge_codegen
] ++ appleInputs;
JAVA_HOME = pinnedJDK;
# ANDROID_SDK_ROOT = “${androidCustomPackage}/share/android-sdk”;

        # Use this to create an android emulator
        # however, this is not needed, as VSCode's Flutter Plugin can create emulators as well
        # AVD_package = "system-images;android-34;aosp_atd;arm64-v8a";
        # local_toolchain_path = "$PWD/.toolchain";
        # local_SDK_path = "${local_toolchain_path}/android";
        # local_AVD_path = "${local_SDK_path}/AVD";
        # avdmanager create avd --name android-34-pixel_8 --package '${AVD_package}' --device "pixel_8"
        shellHook = ''
                  # export PATH=$(echo $PATH | sd "${pkgs.xcbuild.xcrun}/bin" "")
                  # unset DEVELOPER_DIR
          	      #  uncomment to enable flutter-rust-bridge-codegen logging
          	      #  export RUST_BACKTRACE=1
          	      #  export RUST_LOG="debug" 

                  # installs or checks for the right xcode version
                  echo "installing xcode ${xcode_version}"
                  xcodes install ${xcode_version} --experimental-unxip # --directory "$PWD/.xcode"
                  xcodes select ${xcode_version}
                  echo
                  #  GRADLE_USER_HOME=$HOME/gradle-user-home
                  #  GRADLE_HOME=$HOME/gradle-home
        '';

        # GRADLE_USER_HOME = " /home/admin0101/.gradle ";
        # GRADLE_OPTS = " - Dorg.gradle.project.android.aapt2FromMavenOverride=${androidCustomPackage}/share/android-sdk/build-tools/34.0.0/aapt2";
      };
  }
);

}

Note that I am using nix only on my Mac - thus I don’t have any if Darwin (which I should …). I am using it system wide as well, with flake and home-manager. But that should not really matter here …