Skip to content

Commit f7ac761

Browse files
committed
feat: nix devshell
Signed-off-by: James McCorrie <james.mccorrie@lowrisc.org>
1 parent 32d4560 commit f7ac761

3 files changed

Lines changed: 1915 additions & 0 deletions

File tree

flake.lock

Lines changed: 202 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: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# Copyright lowRISC contributors (OpenTitan project).
2+
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
# SPDX-License-Identifier: Apache-2.0
4+
{
5+
description = "OpenTitan EDA development environment";
6+
7+
inputs = {
8+
# Pinned to nixos-26.05 to match lowrisc-nix and because that channel ships
9+
# Verilator 5.048.
10+
nixpkgs.url = "github:nixos/nixpkgs/nixos-26.05";
11+
flake-utils.url = "github:numtide/flake-utils";
12+
13+
# uv2nix builds the Python environment straight from this repo's
14+
# pyproject.toml + uv.lock
15+
pyproject-nix = {
16+
url = "github:nix-community/pyproject.nix";
17+
inputs.nixpkgs.follows = "nixpkgs";
18+
};
19+
20+
uv2nix = {
21+
url = "github:pyproject-nix/uv2nix";
22+
inputs = {
23+
pyproject-nix.follows = "pyproject-nix";
24+
nixpkgs.follows = "nixpkgs";
25+
};
26+
};
27+
28+
pyproject-build-systems = {
29+
url = "github:pyproject-nix/build-system-pkgs";
30+
inputs = {
31+
pyproject-nix.follows = "pyproject-nix";
32+
uv2nix.follows = "uv2nix";
33+
nixpkgs.follows = "nixpkgs";
34+
};
35+
};
36+
37+
# Provides mkEdaShell (the EDA devshell builder)
38+
lowrisc-nix.url = "github:lowRISC/lowrisc-nix";
39+
};
40+
41+
nixConfig = {
42+
extra-substituters = ["https://nix-cache.lowrisc.org/public/"];
43+
extra-trusted-public-keys = ["nix-cache.lowrisc.org-public-1:O6JLD0yXzaJDPiQW1meVu32JIDViuaPtGDfjlOopU7o="];
44+
};
45+
46+
outputs = {
47+
nixpkgs,
48+
flake-utils,
49+
pyproject-nix,
50+
uv2nix,
51+
pyproject-build-systems,
52+
lowrisc-nix,
53+
...
54+
}:
55+
flake-utils.lib.eachDefaultSystem (system: let
56+
inherit (nixpkgs) lib;
57+
pkgs = nixpkgs.legacyPackages.${system};
58+
python = pkgs.python312;
59+
60+
# OpenTitan's Python environment, built from this repo's own pyproject.toml
61+
# + uv.lock. It bundles fusesoc and dvsim along with every other OpenTitan
62+
# Python dependency, so the sim flow's `gen_sv_flist` step (which shells out
63+
# to fusesoc) and dvsim itself are both on PATH inside the shell.
64+
workspace = uv2nix.lib.workspace.loadWorkspace {workspaceRoot = ./.;};
65+
# Prefer prebuilt wheels: they need no per-package build-system overrides
66+
# and are auto-patchelfed by pyproject.nix, which avoids building native
67+
# deps (rpds-py/libcst's Rust, libclang, ...) from source.
68+
overlay = workspace.mkPyprojectOverlay {sourcePreference = "wheel";};
69+
pythonSet = (pkgs.callPackage pyproject-nix.build.packages {inherit python;})
70+
.overrideScope (
71+
lib.composeManyExtensions [
72+
pyproject-build-systems.overlays.default
73+
overlay
74+
# Declares build systems for the sdist-only stragglers (crcmod, ...).
75+
# Inert for deps that resolve to a prebuilt wheel above.
76+
(lowrisc-nix.lib.pyprojectOverrides {inherit pkgs;})
77+
]
78+
);
79+
pythonEnv = pythonSet.mkVirtualEnv "opentitan-env" workspace.deps.default;
80+
81+
# Commercial EDA tool shell, built on lowrisc-nix's generic mkEdaShell.
82+
# Enter with `nix develop .`. It execs into a hermetic FHS sandbox, so
83+
# it is not direnv-loadable and must be entered explicitly.
84+
#
85+
# Tool install paths and license servers are supplied at *runtime* from the
86+
# JSON file named by $LOWRISC_EDA_CONFIG (the flake only declares which
87+
# vendor tools + versions are wanted); without that config the shell still
88+
# works and just warns. See lowrisc-nix lib/README-eda.md.
89+
eda = lowrisc-nix.lib.mkEdaShell {
90+
inherit pkgs;
91+
name = "opentitan-eda";
92+
tools = {
93+
cadence = {
94+
xcelium = "24.03-s007";
95+
jasper = "2025.09";
96+
};
97+
synopsys.vcs = "X-2025.06-SP2-1";
98+
realintent = {
99+
ascentlint = "2022.A.P23.1.2026_01_29";
100+
meridiancdc = "2022.A.P24.3.2025_12_16";
101+
meridianrdc = "2022.A.P14.4.RDC_.2025_12_16";
102+
};
103+
xilinx.vivado = "2025.1";
104+
};
105+
# OpenTitan Python env (fusesoc, dvsim, ...) plus the open-source tools
106+
# that ship in nixpkgs. Verilator 5.048 is the nixos-26.05 version, so no
107+
# override is needed.
108+
extraDeps = [pythonEnv];
109+
extraPkgs = [pkgs.verilator];
110+
};
111+
in {
112+
packages.pythonEnv = pythonEnv;
113+
114+
devShells = {
115+
inherit eda;
116+
default = eda;
117+
};
118+
119+
formatter = pkgs.alejandra;
120+
});
121+
}

0 commit comments

Comments
 (0)