|
| 1 | +# Start dev shell: nix develop |
| 2 | +# Based on: https://nixos.wiki/wiki/Rust |
| 3 | +{ |
| 4 | + description = "Rust development environment"; |
| 5 | + |
| 6 | + inputs = { |
| 7 | + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; |
| 8 | + flake-utils.url = "github:numtide/flake-utils"; |
| 9 | + }; |
| 10 | + |
| 11 | + outputs = { self, nixpkgs, flake-utils }: |
| 12 | + flake-utils.lib.eachDefaultSystem (system: |
| 13 | + let |
| 14 | + pkgs = nixpkgs.legacyPackages.${system}; |
| 15 | + # Read the file relative to the flake's root |
| 16 | + overrides = (builtins.fromTOML (builtins.readFile (self + "/rust-toolchain.toml"))); |
| 17 | + libPath = with pkgs; lib.makeLibraryPath [ |
| 18 | + # load external libraries that you need in your rust project here |
| 19 | + ]; |
| 20 | + in |
| 21 | + { |
| 22 | + devShells.default = pkgs.mkShell rec { |
| 23 | + nativeBuildInputs = [ pkgs.pkg-config ]; |
| 24 | + buildInputs = with pkgs; [ |
| 25 | + clang |
| 26 | + llvmPackages.bintools |
| 27 | + rustup |
| 28 | + ]; |
| 29 | + |
| 30 | + # RUSTC_VERSION = overrides.toolchain.channel; |
| 31 | + RUSTC_VERSION = "1.86.0"; |
| 32 | + |
| 33 | + # https://github.com/rust-lang/rust-bindgen#environment-variables |
| 34 | + LIBCLANG_PATH = pkgs.lib.makeLibraryPath [ pkgs.llvmPackages_latest.libclang.lib ]; |
| 35 | + |
| 36 | + shellHook = '' |
| 37 | + export PATH=$PATH:''${CARGO_HOME:-~/.cargo}/bin |
| 38 | + export PATH=$PATH:''${RUSTUP_HOME:-~/.rustup}/toolchains/$RUSTC_VERSION-x86_64-unknown-linux-gnu/bin/ |
| 39 | + ''; |
| 40 | + |
| 41 | + # Add precompiled library to rustc search path |
| 42 | + RUSTFLAGS = (builtins.map (a: ''-L ${a}/lib'') [ |
| 43 | + # add libraries here (e.g. pkgs.libvmi) |
| 44 | + ]); |
| 45 | + |
| 46 | + LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath (buildInputs ++ nativeBuildInputs); |
| 47 | + |
| 48 | + |
| 49 | + # Add glibc, clang, glib, and other headers to bindgen search path |
| 50 | + BINDGEN_EXTRA_CLANG_ARGS = |
| 51 | + # Includes normal include path |
| 52 | + (builtins.map (a: ''-I"${a}/include"'') [ |
| 53 | + # add dev libraries here (e.g. pkgs.libvmi.dev) |
| 54 | + pkgs.glibc.dev |
| 55 | + ]) |
| 56 | + # Includes with special directory paths |
| 57 | + ++ [ |
| 58 | + ''-I"${pkgs.llvmPackages_latest.libclang.lib}/lib/clang/${pkgs.llvmPackages_latest.libclang.version}/include"'' |
| 59 | + ''-I"${pkgs.glib.dev}/include/glib-2.0"'' |
| 60 | + ''-I${pkgs.glib.out}/lib/glib-2.0/include/'' |
| 61 | + ]; |
| 62 | + }; |
| 63 | + } |
| 64 | + ); |
| 65 | +} |
0 commit comments