From ec6523e73a34f390492179e2f2fcf386f821ec32 Mon Sep 17 00:00:00 2001 From: Adrian Fiergolski Date: Wed, 4 Mar 2026 14:15:06 +0100 Subject: [PATCH 1/5] build(nix): add Nix flake for reproducible SoCMake dev environment - Introduce flake.nix with inputs for nixpkgs, flake-utils, and PeakRDL-socgen - Define devShell with cmake, verible, verilator, and custom Verilog-Perl - Add Python dependencies including peakrdl-socgen and peakrdl-regblock - Add flake.lock to pin dependency versions for reproducibility --- flake.lock | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 57 ++++++++++++++++++++++++++ 2 files changed, 174 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..354e3045 --- /dev/null +++ b/flake.lock @@ -0,0 +1,117 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1771432645, + "narHash": "sha256-ZqRiU5/c+1+QoeaMJJgpqjwimCSNnIl0AUW4z7Md6Ps=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "02263f46911178e286242786fd6ea1d229583fbb", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "02263f46911178e286242786fd6ea1d229583fbb", + "type": "github" + } + }, + "peakrdl-socgen": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1773846014, + "narHash": "sha256-ZU+UKFGm4tWh0GNKAIcLr+nGg0pf4NHgrtPB7Z4wRBQ=", + "owner": "HEP-SoC", + "repo": "PeakRDL-socgen", + "rev": "a1a13b379a280b3adfb206d5ebfbf3ffdcf21b7d", + "type": "github" + }, + "original": { + "owner": "HEP-SoC", + "ref": "refs/tags/v0.1.6", + "repo": "PeakRDL-socgen", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "peakrdl-socgen": "peakrdl-socgen" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..1043378e --- /dev/null +++ b/flake.nix @@ -0,0 +1,57 @@ +{ + description = "SoCMake environment"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/02263f46911178e286242786fd6ea1d229583fbb"; + flake-utils.url = "github:numtide/flake-utils"; + + peakrdl-socgen.url = "github:HEP-SoC/PeakRDL-socgen?ref=refs/tags/v0.1.6"; + peakrdl-socgen.inputs.nixpkgs.follows = "nixpkgs"; + }; + + outputs = { self, nixpkgs, flake-utils, peakrdl-socgen } : + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { inherit system; }; + python = pkgs.python3; + + # For 'vhier' tool used by the copy_rtl_files + verilogPerl = pkgs.perlPackages.buildPerlPackage (rec { + pname = "Verilog-Perl"; + version = "3.482"; + src = pkgs.fetchFromGitHub { + owner = "veripool"; + repo = "verilog-perl"; + rev = "v${version}"; + hash = "sha256-vpgxzb3DpoIhOZKiw3d6HRwJkpor4dOJBxCY26LKqLA="; + }; + + nativeBuildInputs = [pkgs.flex pkgs.bison]; + }); + + pythonDeps = ps: [ + peakrdl-socgen.packages.${system}.default + ps.peakrdl-regblock + ]; + + deps = with pkgs; [ + cmake + gnumake + verible + verilator + verilogPerl + ]; + + in { + inherit pythonDeps deps; + + devShells.default = pkgs.mkShell { + name = "socmake-shell"; + packages = deps ++ [ (python.withPackages pythonDeps) ]; + shellHook = '' + echo "❄️ SoCMake environment loaded (cmake, verible, verilator, peakrdl)" + ''; + }; + } + ); +} From 5657e3adf7e5ca49d8eedd10233e6a9aa48d40ff Mon Sep 17 00:00:00 2001 From: Adrian Fiergolski Date: Thu, 5 Mar 2026 13:00:33 +0100 Subject: [PATCH 2/5] docs: add instructions for using Nix for reproducible development - Explain how to install Nix and enter the development environment - Describe benefits of using Nix flakes for dependency management - Provide links to installation guides and static binary download - Clarify how this approach ensures consistent builds and tooling --- README.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/README.md b/README.md index b43005ac..087349e9 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,42 @@ Hello from Adder! [100%] Built target run_adder_iverilog ``` +## Dependency management + +Once you use more advanced SoCMake targets, e.g. simulation, etc., you will have dependency on some external tools. You are free to choose how you provide all the dependencies required for your project. However, to simplify this task, a Nix-based workflow is available using the provided `flake.nix` file. + +### Using Nix for a Reproducible Environment + +Nix allows you to create a fully reproducible development environment with all necessary tools and dependencies pre-installed. + +To use the Nix flow: + +1. **Install Nix** + +Follow the instructions at https://nixos.org/download.html to install the Nix package manager on your system. +For more advanced Nix installation scenarios, check the guide at [Nix Installation Guide](https://nixos.wiki/wiki/Nix_Installation_Guide#Single-user_install). + You can also download a statically linked *nix* binary, useful e.g. in HPC environments: [Static Nix Binary](https://discourse.nixos.org/t/where-can-i-get-a-statically-built-nix/34253/15). + +2. **Enter the development environment** + +In the project directory (where `flake.nix` is located), run: + +```shell +$ nix --experimental-features 'nix-command flakes' develop +``` + +As you can see, we use [Nix flakes](https://nixos.wiki/wiki/Flakes). Nix Flakes can be enabled permanently in the configuration file ([link](https://nixos.wiki/wiki/Flakes)), and then the command is simple: + +```shell +$ nix develop +``` + +3. **Start working** + +You will be dropped into a shell with all required tools (such as `cmake`, `peakrdl`, `verible`, `verilator`, etc.) available and ready to use. + +This approach ensures that everyone working on the project uses the same versions of all dependencies, making builds and development more reliable and reproducible. + Examples -------- From 4c3bd6e51b8844c743064b0d8e010264ad06ab80 Mon Sep 17 00:00:00 2001 From: Adrian Fiergolski Date: Tue, 17 Mar 2026 09:36:39 +0100 Subject: [PATCH 3/5] build(nix): update sv-lang to v10.0 and remove verilogPerl dependency This change follows MR [1] replacing `vhier` tool with `slang`. As the referred MR requires `slang` in version 10.0 and `nixpkgs` currently provides version 9.1 (there is already a pending MR to update `nixpkgs` to version 10.0 [2]), the corresponding nix overlays are used. - Add overlay to override sv-lang with version 10.0 from upstream - Remove custom verilogPerl build and dependency from deps - Update pkgs import to include overlays for sv-lang [1] https://github.com/HEP-SoC/SoCMake/pull/198 [2] https://github.com/NixOS/nixpkgs/pull/484982 --- flake.nix | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/flake.nix b/flake.nix index 1043378e..8d2fe21f 100644 --- a/flake.nix +++ b/flake.nix @@ -12,22 +12,22 @@ outputs = { self, nixpkgs, flake-utils, peakrdl-socgen } : flake-utils.lib.eachDefaultSystem (system: let - pkgs = import nixpkgs { inherit system; }; - python = pkgs.python3; + overlays = [ + (self: super: { + sv-lang = super.sv-lang.overrideAttrs (old: { + version = "10.0"; + src = super.fetchFromGitHub { + owner = "MikePopoloski"; + repo = "slang"; + tag = "v10.0"; + hash = "sha256-rw+DztENuY+DiAhQR2oNN/dQJzrcP5neF3LoWnqri+c="; + }; + }); + }) + ]; - # For 'vhier' tool used by the copy_rtl_files - verilogPerl = pkgs.perlPackages.buildPerlPackage (rec { - pname = "Verilog-Perl"; - version = "3.482"; - src = pkgs.fetchFromGitHub { - owner = "veripool"; - repo = "verilog-perl"; - rev = "v${version}"; - hash = "sha256-vpgxzb3DpoIhOZKiw3d6HRwJkpor4dOJBxCY26LKqLA="; - }; - - nativeBuildInputs = [pkgs.flex pkgs.bison]; - }); + pkgs = import nixpkgs { inherit system overlays; }; + python = pkgs.python3; pythonDeps = ps: [ peakrdl-socgen.packages.${system}.default @@ -37,9 +37,9 @@ deps = with pkgs; [ cmake gnumake + sv-lang verible verilator - verilogPerl ]; in { From 51f58abc1dc7087798786fa50be828cfba844747 Mon Sep 17 00:00:00 2001 From: Adrian Fiergolski Date: Wed, 18 Mar 2026 14:06:59 +0100 Subject: [PATCH 4/5] build(nix): use cmake 3.25 from separate nixpkgs input for builds It follows @benoitdenkinger feedback in MR [1]. - Add nixpkgs_cmake_3_25 input for cmake 3.25 support - Update dependencies to use cmake from nixpkgs_cmake_3_25 [1] https://github.com/HEP-SoC/SoCMake/pull/195#issuecomment-4070040731 --- flake.lock | 17 +++++++++++++++++ flake.nix | 6 ++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/flake.lock b/flake.lock index 354e3045..58bd34b2 100644 --- a/flake.lock +++ b/flake.lock @@ -52,6 +52,22 @@ "type": "github" } }, + "nixpkgs_cmake_3_25": { + "locked": { + "lastModified": 1704290814, + "narHash": "sha256-LWvKHp7kGxk/GEtlrGYV68qIvPHkU9iToomNFGagixU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "70bdadeb94ffc8806c0570eb5c2695ad29f0e421", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.05", + "repo": "nixpkgs", + "type": "github" + } + }, "peakrdl-socgen": { "inputs": { "flake-utils": "flake-utils_2", @@ -78,6 +94,7 @@ "inputs": { "flake-utils": "flake-utils", "nixpkgs": "nixpkgs", + "nixpkgs_cmake_3_25": "nixpkgs_cmake_3_25", "peakrdl-socgen": "peakrdl-socgen" } }, diff --git a/flake.nix b/flake.nix index 8d2fe21f..68a56432 100644 --- a/flake.nix +++ b/flake.nix @@ -3,13 +3,14 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/02263f46911178e286242786fd6ea1d229583fbb"; + nixpkgs_cmake_3_25.url = "github:NixOS/nixpkgs/nixos-23.05"; flake-utils.url = "github:numtide/flake-utils"; peakrdl-socgen.url = "github:HEP-SoC/PeakRDL-socgen?ref=refs/tags/v0.1.6"; peakrdl-socgen.inputs.nixpkgs.follows = "nixpkgs"; }; - outputs = { self, nixpkgs, flake-utils, peakrdl-socgen } : + outputs = { self, nixpkgs, nixpkgs_cmake_3_25, flake-utils, peakrdl-socgen } : flake-utils.lib.eachDefaultSystem (system: let overlays = [ @@ -27,6 +28,7 @@ ]; pkgs = import nixpkgs { inherit system overlays; }; + pkgs_cmake_3_25 = nixpkgs_cmake_3_25.legacyPackages.${system}; python = pkgs.python3; pythonDeps = ps: [ @@ -35,7 +37,7 @@ ]; deps = with pkgs; [ - cmake + pkgs_cmake_3_25.cmake gnumake sv-lang verible From b7e07e52a9aaab9dbdce23f18aafd49ecb6c8e17 Mon Sep 17 00:00:00 2001 From: Marco Andorno Date: Mon, 23 Mar 2026 15:55:42 +0100 Subject: [PATCH 5/5] Update socgen tag: add ifdef guard on soc pkg --- flake.lock | 8 ++++---- flake.nix | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/flake.lock b/flake.lock index 58bd34b2..706c7775 100644 --- a/flake.lock +++ b/flake.lock @@ -76,16 +76,16 @@ ] }, "locked": { - "lastModified": 1773846014, - "narHash": "sha256-ZU+UKFGm4tWh0GNKAIcLr+nGg0pf4NHgrtPB7Z4wRBQ=", + "lastModified": 1774031463, + "narHash": "sha256-nQssNua8JzPRs3cZHX8DVHSO+nQTmf+QtOShZuyl7ss=", "owner": "HEP-SoC", "repo": "PeakRDL-socgen", - "rev": "a1a13b379a280b3adfb206d5ebfbf3ffdcf21b7d", + "rev": "9baa6ac91ae72415a98e9ed9e3a3a076d9276a54", "type": "github" }, "original": { "owner": "HEP-SoC", - "ref": "refs/tags/v0.1.6", + "ref": "refs/tags/v0.1.7", "repo": "PeakRDL-socgen", "type": "github" } diff --git a/flake.nix b/flake.nix index 68a56432..aa263e27 100644 --- a/flake.nix +++ b/flake.nix @@ -6,7 +6,7 @@ nixpkgs_cmake_3_25.url = "github:NixOS/nixpkgs/nixos-23.05"; flake-utils.url = "github:numtide/flake-utils"; - peakrdl-socgen.url = "github:HEP-SoC/PeakRDL-socgen?ref=refs/tags/v0.1.6"; + peakrdl-socgen.url = "github:HEP-SoC/PeakRDL-socgen?ref=refs/tags/v0.1.7"; peakrdl-socgen.inputs.nixpkgs.follows = "nixpkgs"; };