Skip to content

Commit a8f86f8

Browse files
committed
Add flake.nix
1 parent 0009c2a commit a8f86f8

File tree

5 files changed

+128
-0
lines changed

5 files changed

+128
-0
lines changed

.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/target
22
/input/*
3+
.direnv/

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 = { self, nixpkgs, flake-utils }:
10+
flake-utils.lib.eachDefaultSystem (system:
11+
let
12+
pkgs = nixpkgs.legacyPackages.${system};
13+
# Read the file relative to the flake's root
14+
overrides = (builtins.fromTOML (builtins.readFile (self + "/rust-toolchain.toml")));
15+
libPath = with pkgs; lib.makeLibraryPath [
16+
# load external libraries that you need in your rust project here
17+
];
18+
in
19+
{
20+
devShells.default = pkgs.mkShell rec {
21+
nativeBuildInputs = [ pkgs.pkg-config ];
22+
buildInputs = with pkgs; [
23+
clang
24+
llvmPackages.bintools
25+
rustup
26+
];
27+
28+
RUSTC_VERSION = overrides.toolchain.channel;
29+
30+
# https://github.com/rust-lang/rust-bindgen#environment-variables
31+
LIBCLANG_PATH = pkgs.lib.makeLibraryPath [ pkgs.llvmPackages_latest.libclang.lib ];
32+
33+
shellHook = ''
34+
export PATH=$PATH:''${CARGO_HOME:-~/.cargo}/bin
35+
export PATH=$PATH:''${RUSTUP_HOME:-~/.rustup}/toolchains/$RUSTC_VERSION-x86_64-unknown-linux-gnu/bin/
36+
'';
37+
38+
# Add precompiled library to rustc search path
39+
RUSTFLAGS = (builtins.map (a: ''-L ${a}/lib'') [
40+
# add libraries here (e.g. pkgs.libvmi)
41+
]);
42+
43+
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath (buildInputs ++ nativeBuildInputs);
44+
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-2025-05-03"
3+
components = ["rustc", "cargo", "rust-analyzer", "rustfmt", "clippy"]

0 commit comments

Comments
 (0)