From 4459409d739d9c67a8d6f3682e30267a1d212cd6 Mon Sep 17 00:00:00 2001 From: Roland Coeurjoly Date: Thu, 29 Feb 2024 14:32:17 +0100 Subject: [PATCH 1/4] Support building nextpnr with nix flakes --- .gitignore | 1 + flake.lock | 61 +++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 131 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.gitignore b/.gitignore index d5a21ea1c7..1698190511 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,4 @@ install_manifest.txt *.phys *.dcp *.bit +result diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000000..4433cd2eb3 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1709126324, + "narHash": "sha256-q6EQdSeUZOG26WelxqkmR7kArjgWCdw5sfJVHPH/7j8=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "d465f4819400de7c8d874d50b982301f28a84605", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1709150264, + "narHash": "sha256-HofykKuisObPUfj0E9CJVfaMhawXkYx3G8UIFR/XQ38=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9099616b93301d5cf84274b184a3a5ec69e94e08", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "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 0000000000..74c5182b82 --- /dev/null +++ b/flake.nix @@ -0,0 +1,69 @@ +{ + description = "A flake for the nextpnr FPGA place and route tool"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils, ... }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { + inherit system; + overlays = []; + }; + # Define custom overrides or additional packages + myPythonPackages = pkgs.python3Packages.override { + overrides = self: super: { + apycula = super.apycula.override { + # Place any necessary overrides here + }; + }; + }; + enableGui = false; + in + { + packages = { + nextpnr = pkgs.stdenv.mkDerivation { + pname = "nextpnr"; + version = "0.6"; + src = ./.; + + nativeBuildInputs = [ pkgs.cmake ] + ++ (pkgs.lib.optional enableGui pkgs.qt6.wrapQtAppsHook); + buildInputs = [ + (pkgs.boost.override { python = pkgs.python3; enablePython = true; }) + pkgs.python3 + pkgs.eigen + myPythonPackages.apycula + pkgs.icestorm + pkgs.trellis + ] ++ (pkgs.lib.optional enableGui pkgs.qt6.qtbase) + ++ (pkgs.lib.optional pkgs.stdenv.cc.isClang pkgs.llvmPackages.openmp); + + cmakeFlags = [ + "-DARCH=generic;ice40;ecp5;gowin" + "-DBUILD_TESTS=ON" + "-DICESTORM_INSTALL_PREFIX=${pkgs.icestorm}" + "-DTRELLIS_INSTALL_PREFIX=${pkgs.trellis}" + "-DTRELLIS_LIBDIR=${pkgs.trellis}/lib/trellis" + "-DGOWIN_BBA_EXECUTABLE=${myPythonPackages.apycula}/bin/gowin_bba" + "-DUSE_OPENMP=ON" + # warning: high RAM usage + "-DSERIALIZE_CHIPDBS=OFF" + ] ++ (pkgs.lib.optional enableGui "-DBUILD_GUI=ON"); + + meta = with pkgs.lib; { + description = "Place and route tool for FPGAs"; + homepage = "https://github.com/yosyshq/nextpnr"; + license = licenses.isc; + platforms = platforms.all; + maintainers = with maintainers; [ thoughtpolice emily ]; + }; + }; + }; + + packages.default = self.packages.${system}.nextpnr; + }); +} From 8b486df0595521e7ebf1fbe807e078f8a536c70d Mon Sep 17 00:00:00 2001 From: Roland Coeurjoly Date: Fri, 1 Mar 2024 11:18:13 +0100 Subject: [PATCH 2/4] Add devShell to flake.nix. Build every available stable architecture. Remove shell.nix. Add nix github action --- .github/workflows/nix.yml | 13 +++++++ flake.nix | 82 ++++++++++++++++++++++----------------- shell.nix | 48 ----------------------- 3 files changed, 59 insertions(+), 84 deletions(-) create mode 100644 .github/workflows/nix.yml delete mode 100644 shell.nix diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml new file mode 100644 index 0000000000..a11584bc64 --- /dev/null +++ b/.github/workflows/nix.yml @@ -0,0 +1,13 @@ +name: "build nix flake" +on: + pull_request: + push: +jobs: + tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: true + - uses: cachix/install-nix-action@v25 + - run: nix build '.?submodules=1' diff --git a/flake.nix b/flake.nix index 74c5182b82..a867576247 100644 --- a/flake.nix +++ b/flake.nix @@ -23,47 +23,57 @@ }; enableGui = false; in - { - packages = { - nextpnr = pkgs.stdenv.mkDerivation { - pname = "nextpnr"; - version = "0.6"; - src = ./.; + { + packages = { + nextpnr = pkgs.stdenv.mkDerivation { + pname = "nextpnr"; + version = "0.6"; + src = ./.; - nativeBuildInputs = [ pkgs.cmake ] - ++ (pkgs.lib.optional enableGui pkgs.qt6.wrapQtAppsHook); - buildInputs = [ - (pkgs.boost.override { python = pkgs.python3; enablePython = true; }) - pkgs.python3 - pkgs.eigen - myPythonPackages.apycula - pkgs.icestorm - pkgs.trellis - ] ++ (pkgs.lib.optional enableGui pkgs.qt6.qtbase) + nativeBuildInputs = [ pkgs.cmake ] + ++ (pkgs.lib.optional enableGui pkgs.qt6.wrapQtAppsHook); + buildInputs = [ + (pkgs.boost.override { python = pkgs.python3; enablePython = true; }) + pkgs.python3 + pkgs.eigen + myPythonPackages.apycula + pkgs.icestorm + pkgs.trellis + pkgs.tcl + pkgs.zlib + pkgs.capnproto + pkgs.lzma + pkgs.tk + pkgs.wget + ] ++ (pkgs.lib.optional enableGui pkgs.qt6.qtbase) ++ (pkgs.lib.optional pkgs.stdenv.cc.isClang pkgs.llvmPackages.openmp); - cmakeFlags = [ - "-DARCH=generic;ice40;ecp5;gowin" - "-DBUILD_TESTS=ON" - "-DICESTORM_INSTALL_PREFIX=${pkgs.icestorm}" - "-DTRELLIS_INSTALL_PREFIX=${pkgs.trellis}" - "-DTRELLIS_LIBDIR=${pkgs.trellis}/lib/trellis" - "-DGOWIN_BBA_EXECUTABLE=${myPythonPackages.apycula}/bin/gowin_bba" - "-DUSE_OPENMP=ON" - # warning: high RAM usage - "-DSERIALIZE_CHIPDBS=OFF" - ] ++ (pkgs.lib.optional enableGui "-DBUILD_GUI=ON"); + cmakeFlags = [ + "-DARCH=all" + "-DBUILD_TESTS=ON" + "-DICESTORM_INSTALL_PREFIX=${pkgs.icestorm}" + "-DTRELLIS_INSTALL_PREFIX=${pkgs.trellis}" + "-DTRELLIS_LIBDIR=${pkgs.trellis}/lib/trellis" + "-DGOWIN_BBA_EXECUTABLE=${myPythonPackages.apycula}/bin/gowin_bba" + "-DUSE_OPENMP=ON" + # warning: high RAM usage + "-DSERIALIZE_CHIPDBS=OFF" + ] ++ (pkgs.lib.optional enableGui "-DBUILD_GUI=ON"); - meta = with pkgs.lib; { - description = "Place and route tool for FPGAs"; - homepage = "https://github.com/yosyshq/nextpnr"; - license = licenses.isc; - platforms = platforms.all; - maintainers = with maintainers; [ thoughtpolice emily ]; + meta = with pkgs.lib; { + description = "Place and route tool for FPGAs"; + homepage = "https://github.com/yosyshq/nextpnr"; + license = licenses.isc; + platforms = platforms.all; + maintainers = with maintainers; [ ]; + }; }; }; - }; - packages.default = self.packages.${system}.nextpnr; - }); + packages.default = self.packages.${system}.nextpnr; + + devShell = pkgs.mkShell { + buildInputs = [ self.packages.${system}.default ]; + }; + }); } diff --git a/shell.nix b/shell.nix deleted file mode 100644 index 084e318092..0000000000 --- a/shell.nix +++ /dev/null @@ -1,48 +0,0 @@ -{ pkgs ? import (fetchTarball https://github.com/NixOS/nixpkgs/archive/23.05.tar.gz) {} }: - -let - pythonPkgs = pkgs.python3Packages; - boostPython = pkgs.boost.override { python = pythonPkgs.python; enablePython = true; }; - vscode = pkgs.vscode-with-extensions.override { - vscodeExtensions = with pkgs.vscode-extensions; [ - bbenoist.nix - ms-vscode.cpptools - ms-vscode.cmake-tools - twxs.cmake - usernamehw.errorlens - llvm-vs-code-extensions.vscode-clangd - ] ++ pkgs.vscode-utils.extensionsFromVscodeMarketplace [ - { - name = "VerilogHDL"; - publisher = "mshr-h"; - version = "1.11.4"; - sha256 = "sha256-4JY0eaN2IkwHv8u8X6ejDXk6vT1qB4vJjWdIy8b/jj4="; - } - ]; - }; -in pkgs.mkShell { - buildInputs = with pkgs; [ - cmake - eigen - boostPython - pythonPkgs.python - pythonPkgs.apycula - libsForQt5.qt5.qtbase - llvmPackages.openmp - icestorm - trellis - mold - yosys - clang - valgrind - cling - gdb - vscode - ]; - - shellHook = '' - export TRELLIS_INSTALL_PREFIX=${pkgs.trellis} - export ICESTORM_INSTALL_PREFIX=${pkgs.icestorm} - export QT_QPA_PLATFORM_PLUGIN_PATH="${pkgs.libsForQt5.qt5.qtbase.bin}/lib/qt-${pkgs.libsForQt5.qt5.qtbase.version}/plugins"; - ''; -} From 0ac8b9ed62d149d0e938bb4a4800b5b9e6f20320 Mon Sep 17 00:00:00 2001 From: Roland Coeurjoly Date: Fri, 1 Mar 2024 13:05:21 +0100 Subject: [PATCH 3/4] Add shellHook from shell.nix --- flake.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/flake.nix b/flake.nix index a867576247..dd3fc23ce3 100644 --- a/flake.nix +++ b/flake.nix @@ -74,6 +74,12 @@ devShell = pkgs.mkShell { buildInputs = [ self.packages.${system}.default ]; + + shellHook = '' + export TRELLIS_INSTALL_PREFIX=${pkgs.trellis} + export ICESTORM_INSTALL_PREFIX=${pkgs.icestorm} + export QT_QPA_PLATFORM_PLUGIN_PATH="${pkgs.libsForQt5.qt5.qtbase.bin}/lib/qt-${pkgs.libsForQt5.qt5.qtbase.version}/plugins"; + ''; }; }); } From 754cfcf1225dc49c94c6696df1a05e83649365ad Mon Sep 17 00:00:00 2001 From: Roland Coeurjoly Date: Thu, 29 Feb 2024 14:59:09 +0100 Subject: [PATCH 4/4] =?UTF-8?q?=C2=B4Use=20inputsFrom?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index dd3fc23ce3..c9dd098e42 100644 --- a/flake.nix +++ b/flake.nix @@ -73,7 +73,7 @@ packages.default = self.packages.${system}.nextpnr; devShell = pkgs.mkShell { - buildInputs = [ self.packages.${system}.default ]; + inputsFrom = [ self.packages.${system}.default ]; shellHook = '' export TRELLIS_INSTALL_PREFIX=${pkgs.trellis}