|
| 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 | +} |
0 commit comments