Skip to content

Commit d857953

Browse files
authored
feat(nix): add nix devshell support (#60)
Basically, just do whatever `setup-tools.sh` does, using nix. We can run `nix develop` to enter devshells. Also, we can use [nix-direnv](https://github.com/nix-community/nix-direnv) and run `direnv allow .` to let direnv auto management. I'll add docs to XiangShan-doc if needed. Showcase using direnv: ```bash $ direnv allow workspace/xs-env # this will be needed only the first time $ cd workspace/xs-env/XiangShan # direnv will build & activate devshell each time you enter xs-env and subdirectories direnv: loading ~/workspace/xs-env/.envrc direnv: using flake === Welcome to XiangShan devshell! === Version info: - Verilator 5.028 2024-08-21 rev v5.028 - Mill Build Tool version 0.12.3 - gcc (GCC) 14.2.1 20250322 - riscv64-unknown-linux-gnu-gcc (GCC) 14.2.1 20250322 - openjdk version "21.0.7" 2025-04-15 You can press Ctrl + D to exit devshell. direnv: export +AR +AS +CC +CLASSPATH +CONFIG_SHELL +CXX +DETERMINISTIC_BUILD +HOST_PATH +IN_NIX_SHELL +JAVA_HOME +LD +NIX_BINTOOLS +NIX_BINTOOLS_WRAPPER_TARGET_HOST_riscv64_unknown_linux_gnu +NIX_BINTOOLS_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu +NIX_BUILD_CORES +NIX_BUILD_TOP +NIX_CC +NIX_CC_WRAPPER_TARGET_HOST_riscv64_unknown_linux_gnu +NIX_CC_WRAPPER_TARGET_HOST_x86_64_unknown_linux_gnu +NIX_CFLAGS_COMPILE +NIX_ENFORCE_NO_NATIVE +NIX_HARDENING_ENABLE +NIX_LDFLAGS +NIX_STORE +NM +OBJCOPY +OBJDUMP +PYTHONHASHSEED +PYTHONNOUSERSITE +PYTHONPATH +RANLIB +READELF +SDL2_PATH +SIZE +SOURCE_DATE_EPOCH +STRINGS +STRIP +TEMP +TEMPDIR +TMP +TMPDIR +_PYTHON_HOST_PLATFORM +_PYTHON_SYSCONFIGDATA_NAME +__structuredAttrs +buildInputs +buildPhase +builder +cmakeFlags +configureFlags +depsBuildBuild +depsBuildBuildPropagated +depsBuildTarget +depsBuildTargetPropagated +depsHostHost +depsHostHostPropagated +depsTargetTarget +depsTargetTargetPropagated +doCheck +doInstallCheck +dontAddDisableDepTrack +mesonFlags +name +nativeBuildInputs +out +outputs +patches +phases +preferLocalBuild +propagatedBuildInputs +propagatedNativeBuildInputs +shell +shellHook +stdenv +strictDeps +system ~PATH ~XDG_DATA_DIRS $ ```
1 parent 5850988 commit d857953

File tree

4 files changed

+109
-0
lines changed

4 files changed

+109
-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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
out/
3+
.direnv/

flake.lock

Lines changed: 27 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: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{
2+
description = "Nix devshells for XiangShan";
3+
4+
inputs = {
5+
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
6+
};
7+
8+
outputs = {nixpkgs, ...}: let
9+
system = "x86_64-linux";
10+
pkgs = import nixpkgs { inherit system; };
11+
in {
12+
devShells.${system}.default = pkgs.mkShell {
13+
packages = with pkgs; [
14+
# === tool ===
15+
wget
16+
git
17+
tmux
18+
curl
19+
time
20+
21+
# === runtime ===
22+
python3
23+
python3Packages.psutil # for XiangShan/scripts/xiangshan.py
24+
openjdk
25+
26+
# === toolchain ===
27+
gcc # host toolchain
28+
pkgsCross.riscv64.buildPackages.gcc # riscv64-unknown-elf-xxx toolchain
29+
llvm # for pgo
30+
clang
31+
gnumake # make
32+
dtc # device tree compiler
33+
flex
34+
autoconf
35+
bison
36+
# override mill & verilator to use our version
37+
(mill.overrideAttrs (finalAttrs: previousAttrs: {
38+
version = "0.12.3";
39+
src = fetchurl {
40+
url = "https://github.com/com-lihaoyi/mill/releases/download/${finalAttrs.version}/${finalAttrs.version}-assembly";
41+
hash = "sha256-hqzAuYadCciYPs/b6zloLUfrWF4rRtlBSMxSj7tLg7g=";
42+
};
43+
}))
44+
(verilator.overrideAttrs (finalAttrs: previousAttrs: {
45+
version = "5.028";
46+
VERILATOR_SRC_VERSION = "v${finalAttrs.version}";
47+
src = fetchFromGitHub {
48+
owner = "verilator";
49+
repo = "verilator";
50+
rev = "v${finalAttrs.version}";
51+
hash = "sha256-YgK60fAYG5575uiWmbCODqNZMbRfFdOVcJXz5h5TLuE=";
52+
};
53+
doCheck = false;
54+
}))
55+
56+
# === debug ===
57+
gtkwave
58+
59+
# === lib ===
60+
readline
61+
SDL2
62+
zlib
63+
zstd
64+
sqlite
65+
];
66+
shellHook = ''
67+
echo "=== Welcome to XiangShan devshell! ==="
68+
echo "Version info:"
69+
echo "- $(verilator --version)"
70+
echo "- $(mill --version | head -n 1)"
71+
echo "- $(gcc --version | head -n 1)"
72+
echo "- $(riscv64-unknown-linux-gnu-gcc --version | head -n 1)"
73+
echo "- $(java -version 2>&1 | head -n 1)"
74+
echo "You can press Ctrl + D to exit devshell."
75+
'';
76+
};
77+
};
78+
}

0 commit comments

Comments
 (0)