fundamentum-portforwarding-proto-rust 0.4.0

Port forwarding proto bindings for rust usage.
Documentation
{
  inputs = {
    rust-overlay.url = "github:oxalica/rust-overlay/stable";
    nixpkgs.follows = "rust-overlay/nixpkgs";
  };

  outputs = {
    nixpkgs,
    rust-overlay,
    ...
  }: let
    forAllSystems = f:
      nixpkgs.lib.genAttrs [
        "aarch64-linux"
        "x86_64-linux"
        "aarch64-darwin"
        "x86_64-darwin"
      ] (
        system:
          f {
            pkgs = import nixpkgs {
              inherit system;
              overlays = [(import rust-overlay)];
            };
          }
      );
  in {
    devShells = forAllSystems ({pkgs}: {
      default = with pkgs;
        mkShell {
          packages = [
            bashInteractive
            coreutils
            diffutils
            just
            pkg-config
            protobuf
            cargo-readme
            (rust-bin.fromRustupToolchainFile ./rust-toolchain.toml)
          ];

          shellHook = ''
            # Avoid polluting home dir with local project stuff.
            if command -v git  &> /dev/null; then
              CARGO_HOME="$(git rev-parse --show-toplevel)/.cargo"
              export CARGO_HOME
              export PATH=$PATH:$CARGO_HOME/bin
            fi
          '';

          # As suggested in the tonic-build documentation:
          #
          # On NixOS, it is better to specify the location of `PROTOC` and `PROTOC_INCLUDE` explicitly.
          # The reason being that if `prost_build::compile_protos` fails to generate the resultant package,
          # the failure is not obvious until the `include!(concat!(env!("OUT_DIR"), "/resultant.rs"));`
          # fails with `No such file or directory` error.
          PROTOC = "${protobuf}/bin/protoc";
          PROTOC_INCLUDE = "${protobuf}/include";
        };
    });
  };
}