{
  description = "STM32U575ZI-Q Rust Embedded Development Environment";

  inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; };

  outputs = { self, nixpkgs }: let
    system = "x86_64-linux";
    pkgs = import nixpkgs { inherit system; };
    rust = pkgs.rust-bin.stable.latest.default.override {
      targets = [ "thumbv8m.main-none-eabihf" ];
      extensions = [ "rust-src" "rustfmt" "clippy" ];
    };
  in {
    devShells.${system}.default = pkgs.mkShell {
      packages = with pkgs; [
        # Base toolchain
        rustup
        llvm
        gcc
        gnumake
        cmake
        pkg-config
        python3
        git
        curl
        wget
        unzip

        # ARM embedded cross toolchain
        gcc-arm-embedded

        # Flashing / Debug
        openocd
        probe-rs
        cargo-binutils
        cargo-generate
        flip-link
      ];

      shellHook = ''
        echo ">>> STM32 DevShell"

	export PATH=${pkgs.rust-analyzer}/bin:$PATH
	export PATH=$HOME/.cargo/bin:$PATH

        rustup default stable
        rustup component add rust-src rustfmt clippy 2>/dev/null || true
        rustup target add thumbv8m.main-none-eabihf 2>/dev/null || true

        export RUST_TARGET=thumbv8m.main-none-eabihf
        export CARGO_TARGET_DIR=target
	export DEFMT_LOG=info
        export PATH=$PATH:${pkgs.gcc-arm-embedded}/bin
        export RUST_SRC_PATH="$(rustc --print sysroot)/lib/rustlib/src/rust/library"

	rustc --version
	arm-none-eabi-gcc --version | head -n1
        echo "cargo build --release --target thumbv8m.main-none-eabihf"
        echo "cargo flash --release --chip STM32U575ZI"
	echo "cargo run --bin main"
	echo "probe-rs run --chip STM32U575ZITxQ target/thumbv8m.main-none-eabihf/release/main"
	echo "probe-rs erase --chip STM32U575ZITxQ"
	echo "target/**/build/embassy-stm32-*/out/_generated.rs"
      '';
    };
  };
}
