Skip to content

Commit c297a93

Browse files
committed
nix setup
1 parent 28fc0eb commit c297a93

3 files changed

Lines changed: 48 additions & 0 deletions

File tree

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"nixEnvSelector.nixFile": "${workspaceFolder}/shell.nix"
3+
}

rust-toolchain.toml

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

shell.nix

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{ pkgs ? import <nixpkgs> { config.allowUnfree = true; } }:
2+
let
3+
overrides = (builtins.fromTOML (builtins.readFile ./rust-toolchain.toml));
4+
libPath = with pkgs; lib.makeLibraryPath [
5+
# load external libraries that you need in your rust project here
6+
];
7+
in
8+
pkgs.mkShell rec {
9+
buildInputs = with pkgs; [
10+
clang
11+
# Replace llvmPackages with llvmPackages_X, where X is the latest LLVM version
12+
llvmPackages_21.bintools
13+
rustup
14+
openssl
15+
pkg-config
16+
gcc
17+
];
18+
RUSTC_VERSION = overrides.toolchain.channel;
19+
# https://github.com/rust-lang/rust-bindgen#environment-variables
20+
LIBCLANG_PATH = pkgs.lib.makeLibraryPath [ pkgs.llvmPackages_latest.libclang.lib ];
21+
shellHook = ''
22+
export PATH=$PATH:''${CARGO_HOME:-~/.cargo}/bin
23+
export PATH=$PATH:''${RUSTUP_HOME:-~/.rustup}/toolchains/$RUSTC_VERSION-x86_64-unknown-linux-gnu/bin/
24+
'';
25+
# Add precompiled library to rustc search path
26+
RUSTFLAGS = (builtins.map (a: ''-L ${a}/lib'') [
27+
# add libraries here (e.g. pkgs.libvmi)
28+
]);
29+
LD_LIBRARY_PATH = libPath;
30+
# Add glibc, clang, glib, and other headers to bindgen search path
31+
BINDGEN_EXTRA_CLANG_ARGS =
32+
# Includes normal include path
33+
(builtins.map (a: ''-I"${a}/include"'') [
34+
# add dev libraries here (e.g. pkgs.libvmi.dev)
35+
pkgs.glibc.dev
36+
])
37+
# Includes with special directory paths
38+
++ [
39+
''-I"${pkgs.llvmPackages_latest.libclang.lib}/lib/clang/${pkgs.llvmPackages_latest.libclang.version}/include"''
40+
''-I"${pkgs.glib.dev}/include/glib-2.0"''
41+
''-I${pkgs.glib.out}/lib/glib-2.0/include/''
42+
];
43+
}

0 commit comments

Comments
 (0)