Skip to content

Commit 3f35626

Browse files
committed
added nix development environment
added rust-toolchain.toml for the nix flake The nix flake needs a rust-toolchain.toml to rely on
1 parent 81eafe6 commit 3f35626

File tree

3 files changed

+126
-0
lines changed

3 files changed

+126
-0
lines changed

flake.lock

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

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

rust-toolchain.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[toolchain]
2+
channel = "nightly"
3+

0 commit comments

Comments
 (0)