{ inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; flake-parts.url = "github:hercules-ci/flake-parts"; naersk.url = "github:nix-community/naersk"; rust-overlay = { url = "github:oxalica/rust-overlay"; }; nixpkgs-esp-dev.url = "github:madmo/nixpkgs-esp-dev"; }; outputs = inputs@{ self, nixpkgs, flake-parts, rust-overlay, naersk , nixpkgs-esp-dev, ... }: flake-parts.lib.mkFlake { inherit inputs; } { systems = [ "x86_64-linux" ]; perSystem = { config, self', inputs', pkgs, system, ... }: let toolchain = (pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.minimal.override { extensions = [ "rust-src" "rustfmt" "clippy" ]; targets = [ "riscv32imac-unknown-none-elf" ]; })); naersk' = pkgs.callPackage naersk { cargo = toolchain; rustc = toolchain; }; ldproxy = pkgs.rustPlatform.buildRustPackage rec { pname = "ldproxy"; version = "0.3.4"; src = pkgs.fetchFromGitHub { owner = "esp-rs"; repo = "embuild"; rev = "${pname}-v${version}"; sha256 = "sha256-axqlh3wexGQ4pjphkR04k4Cr4f1ytan0y+HYJuTtYa8="; }; buildAndTestSubdir = "ldproxy"; nativeBuildInputs = [ pkgs.pkg-config ]; buildInputs = [ pkgs.udev ]; cargoSha256 = "sha256-GuxmLGcbjuWCAucWzjfJD85ERGhqdnUGLLCcq7bbr6g="; meta = with pkgs.lib; { description = "Build support for embedded Rust: Cargo integration with other embedded build ecosystems & tools, like PlatformIO, CMake and kconfig"; homepage = "https://github.com/esp-rs/embuild"; license = with licenses; [ mit # or asl20 ]; maintainers = with maintainers; [ matthiasbeyer ]; }; }; esp-idf = (pkgs.esp-idf-esp32c6.override { rev = "v5.1.3"; sha256 = "sha256-0QsIFOcSx1N15t5po3TyOaNvpzBUfKaFdsRODOBoXCI="; }); git-safe-dir-hook = pkgs.callPackage ({ }: pkgs.makeSetupHook { name = "git-safe-dir-hook"; propagatedBuildInputs = [ pkgs.git esp-idf ]; substitutions = { shell = "${pkgs.bash}/bin/bash"; }; } (pkgs.writeScript "git-safe-dir-hook.sh" '' export GIT_CONFIG_GLOBAL=$(realpath .gitconfig) ${pkgs.git}/bin/git config --global --add safe.directory \ '${esp-idf}' '')) { }; in rec { _module.args.pkgs = import inputs.nixpkgs { inherit system; overlays = [ (import rust-overlay) (import "${nixpkgs-esp-dev}/overlay.nix") ]; config = { }; }; packages.default = naersk'.buildPackage rec { src = ./.; additionalCargoLock = ./rustlib-Cargo.lock; copyBins = false; copyTarget = true; singleStep = true; nativeBuildInputs = [ git-safe-dir-hook esp-idf ldproxy ]; LIBCLANG_PATH = pkgs.llvmPackages.libclang.lib + "/lib/"; }; devShells.default = pkgs.mkShell { nativeBuildInputs = [ toolchain esp-idf ldproxy pkgs.llvmPackages.libclang ]; shellHook = '' export LIBCLANG_PATH="${pkgs.llvmPackages.libclang.lib}/lib/" ''; }; }; flake = { }; }; }