Skip to content

Commit 1e825fd

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

4 files changed

Lines changed: 1947 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: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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 = builtins.fromJSON (builtins.readFile ./tool_data.json);
93+
# OpenTitan Python env (fusesoc, dvsim, ...) plus the open-source tools
94+
# that ship in nixpkgs. Verilator 5.048 is the nixos-26.05 version, so no
95+
# override is needed.
96+
extraDeps = [pythonEnv];
97+
extraPkgs = [pkgs.verilator];
98+
};
99+
in {
100+
packages.pythonEnv = pythonEnv;
101+
102+
devShells = {
103+
inherit eda;
104+
default = eda;
105+
};
106+
107+
formatter = pkgs.alejandra;
108+
});
109+
}

tool_data.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
[
2+
{
3+
"name": "AscentLint",
4+
"vendor": "RealIntent",
5+
"version": "2022.A.P23.1.2026_01_29",
6+
"comment": "RTL lint (Real Intent Ascent Lint)."
7+
},
8+
{
9+
"name": "Jasper",
10+
"vendor": "Cadence",
11+
"version": "2025.09",
12+
"comment": "Formal verification."
13+
},
14+
{
15+
"name": "MeridianCDC",
16+
"vendor": "RealIntent",
17+
"version": "2022.A.P24.3.2025_12_16",
18+
"comment": "Clock-domain-crossing (CDC) analysis."
19+
},
20+
{
21+
"name": "MeridianRDC",
22+
"vendor": "RealIntent",
23+
"version": "2022.A.P14.4.RDC_.2025_12_16",
24+
"comment": "Reset-domain-crossing (RDC) analysis."
25+
},
26+
{
27+
"name": "VCS",
28+
"vendor": "Synopsys",
29+
"version": "X-2025.06-SP2-1",
30+
"comment": "RTL simulator."
31+
},
32+
{
33+
"name": "Vivado",
34+
"vendor": "Xilinx",
35+
"version": "2025.1",
36+
"comment": "Used to build FPGA bitstreams."
37+
},
38+
{
39+
"name": "Xcelium",
40+
"vendor": "Cadence",
41+
"version": "24.03-s007",
42+
"comment": "Provides xrun for simulations and is used to run our full UVM verification environment."
43+
}
44+
]

0 commit comments

Comments
 (0)