From 1c89e2ab92d5786dfa2ead8ba1c0f822697c5a24 Mon Sep 17 00:00:00 2001 From: Roland Coeurjoly Date: Wed, 8 May 2024 03:52:12 +0200 Subject: [PATCH 1/8] Add nix flake and lock file. Add nix build step. Pending nix flake update step --- .github/workflows/nix-github-actions.yml | 13 +++++ flake.lock | 61 ++++++++++++++++++++++++ flake.nix | 44 +++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 .github/workflows/nix-github-actions.yml create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.github/workflows/nix-github-actions.yml b/.github/workflows/nix-github-actions.yml new file mode 100644 index 00000000000..a11584bc641 --- /dev/null +++ b/.github/workflows/nix-github-actions.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.lock b/flake.lock new file mode 100644 index 00000000000..2545f4ce057 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1705309234, + "narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1708807242, + "narHash": "sha256-sRTRkhMD4delO/hPxxi+XwLqPn8BuUq6nnj4JqLwOu0=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "73de017ef2d18a04ac4bfd0c02650007ccb31c2a", + "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 00000000000..1143d538c25 --- /dev/null +++ b/flake.nix @@ -0,0 +1,44 @@ +{ + description = "A nix flake for the Yosys synthesis suite"; + + 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; + }; + customYosys = pkgs.clangStdenv.mkDerivation { + name = "yosys"; + src = ./. ; + buildInputs = with pkgs; [ clang bison flex libffi tcl readline python3 llvmPackages.libcxxClang zlib git ]; + checkInputs = with pkgs; [ gtest ]; + propagatedBuildInputs = with pkgs; [ abc-verifier ]; + preConfigure = "make config-clang"; + checkTarget = "test"; + installPhase = '' + make install PREFIX=$out + ''; + buildPhase = '' + make -j$(nproc) + ''; + meta = with pkgs.lib; { + description = "Yosys Open SYnthesis Suite"; + homepage = "https://yosyshq.net/yosys/"; + license = licenses.isc; + maintainers = with maintainers; [ ]; + }; + }; + in { + packages.default = customYosys; + defaultPackage = customYosys; + devShell = pkgs.mkShell { + buildInputs = with pkgs; [ clang bison flex libffi tcl readline python3 llvmPackages.libcxxClang zlib git gtest abc-verifier ]; + }; + } + ); +} From 6f9507a16f3c2a8838827e6695fae2b31eb9fa9b Mon Sep 17 00:00:00 2001 From: Roland Coeurjoly Date: Wed, 8 May 2024 04:47:40 +0200 Subject: [PATCH 2/8] Add pkg-config --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 1143d538c25..d97be4ef671 100644 --- a/flake.nix +++ b/flake.nix @@ -15,7 +15,7 @@ customYosys = pkgs.clangStdenv.mkDerivation { name = "yosys"; src = ./. ; - buildInputs = with pkgs; [ clang bison flex libffi tcl readline python3 llvmPackages.libcxxClang zlib git ]; + buildInputs = with pkgs; [ clang bison flex libffi tcl readline python3 llvmPackages.libcxxClang zlib git pkg-configUpstream ]; checkInputs = with pkgs; [ gtest ]; propagatedBuildInputs = with pkgs; [ abc-verifier ]; preConfigure = "make config-clang"; From 1f9f2518fc51246a1e91975f927b50d171b2c801 Mon Sep 17 00:00:00 2001 From: "Emil J. Tywoniak" Date: Sat, 11 May 2024 00:42:53 +0200 Subject: [PATCH 3/8] nix: fix abc --- flake.nix | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index d97be4ef671..26c21cc8996 100644 --- a/flake.nix +++ b/flake.nix @@ -12,19 +12,23 @@ pkgs = import nixpkgs { inherit system; }; + # TODO: don't override src when ./abc is empty + # which happens when the command used is `nix build` and not `nix build ?submodules=1` + abc-verifier = pkgs.abc-verifier.overrideAttrs(x: y: {src = ./abc;}); customYosys = pkgs.clangStdenv.mkDerivation { name = "yosys"; src = ./. ; buildInputs = with pkgs; [ clang bison flex libffi tcl readline python3 llvmPackages.libcxxClang zlib git pkg-configUpstream ]; checkInputs = with pkgs; [ gtest ]; - propagatedBuildInputs = with pkgs; [ abc-verifier ]; + propagatedBuildInputs = [ abc-verifier ]; preConfigure = "make config-clang"; checkTarget = "test"; installPhase = '' - make install PREFIX=$out + make install PREFIX=$out ABCEXTERNAL=yosys-abc + ln -s ${abc-verifier}/bin/abc $out/bin/yosys-abc ''; buildPhase = '' - make -j$(nproc) + make -j$(nproc) ABCEXTERNAL=yosys-abc ''; meta = with pkgs.lib; { description = "Yosys Open SYnthesis Suite"; From c40d43e3a9f7ac5ca01c26f0471245d69e6028ce Mon Sep 17 00:00:00 2001 From: Roland Coeurjoly Date: Mon, 13 May 2024 13:45:06 +0200 Subject: [PATCH 4/8] Ignore result dir, generated by nix --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 6f3e521d62e..e82343e8947 100644 --- a/.gitignore +++ b/.gitignore @@ -45,3 +45,4 @@ __pycache__ /tests/unit/bintest/ /tests/unit/objtest/ /tests/ystests +/result \ No newline at end of file From 8c8fb1399cb45058803a72bdf8e7219b9e3891fb Mon Sep 17 00:00:00 2001 From: Roland Coeurjoly Date: Mon, 13 May 2024 13:53:53 +0200 Subject: [PATCH 5/8] Update github action --- .github/workflows/nix-github-actions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/nix-github-actions.yml b/.github/workflows/nix-github-actions.yml index a11584bc641..256f2043eae 100644 --- a/.github/workflows/nix-github-actions.yml +++ b/.github/workflows/nix-github-actions.yml @@ -9,5 +9,5 @@ jobs: - uses: actions/checkout@v4 with: submodules: true - - uses: cachix/install-nix-action@v25 + - uses: cachix/install-nix-action@v26 - run: nix build '.?submodules=1' From dd6178c74b5b7928f43037808ae60c6fce7e09fe Mon Sep 17 00:00:00 2001 From: Roland Coeurjoly Date: Mon, 13 May 2024 14:21:35 +0200 Subject: [PATCH 6/8] Fix nix version to 2.18.1, known working version --- .github/workflows/nix-github-actions.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/nix-github-actions.yml b/.github/workflows/nix-github-actions.yml index 256f2043eae..6d5c5b4b2dd 100644 --- a/.github/workflows/nix-github-actions.yml +++ b/.github/workflows/nix-github-actions.yml @@ -10,4 +10,6 @@ jobs: with: submodules: true - uses: cachix/install-nix-action@v26 - - run: nix build '.?submodules=1' + with: + install_url: https://releases.nixos.org/nix/nix-2.18.1/install + - run: nix build .?submodules=1 From 9884bb57a10dd32e9ed73ecae91266c394567c1f Mon Sep 17 00:00:00 2001 From: Roland Coeurjoly Date: Mon, 13 May 2024 14:28:32 +0200 Subject: [PATCH 7/8] Add update flake lock github action --- .github/workflows/update-flake-lock.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .github/workflows/update-flake-lock.yml diff --git a/.github/workflows/update-flake-lock.yml b/.github/workflows/update-flake-lock.yml new file mode 100644 index 00000000000..1d4741c8c22 --- /dev/null +++ b/.github/workflows/update-flake-lock.yml @@ -0,0 +1,21 @@ +name: update-flake-lock +on: + workflow_dispatch: # allows manual triggering + schedule: + - cron: '0 0 * * 0' # runs weekly on Sunday at 00:00 + +jobs: + lockfile: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Install Nix + uses: DeterminateSystems/nix-installer-action@main + - name: Update flake.lock + uses: DeterminateSystems/update-flake-lock@main + with: + pr-title: "Update flake.lock" # Title of PR to be created + pr-labels: | # Labels to be set on the PR + dependencies + automated \ No newline at end of file From 13a6920491a01b492e35c8981a856b14ca83f3e7 Mon Sep 17 00:00:00 2001 From: Roland Coeurjoly Date: Tue, 21 May 2024 12:50:23 +0200 Subject: [PATCH 8/8] Change customYosys to yosys --- flake.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flake.nix b/flake.nix index 26c21cc8996..1e202324647 100644 --- a/flake.nix +++ b/flake.nix @@ -15,7 +15,7 @@ # TODO: don't override src when ./abc is empty # which happens when the command used is `nix build` and not `nix build ?submodules=1` abc-verifier = pkgs.abc-verifier.overrideAttrs(x: y: {src = ./abc;}); - customYosys = pkgs.clangStdenv.mkDerivation { + yosys = pkgs.clangStdenv.mkDerivation { name = "yosys"; src = ./. ; buildInputs = with pkgs; [ clang bison flex libffi tcl readline python3 llvmPackages.libcxxClang zlib git pkg-configUpstream ]; @@ -38,8 +38,8 @@ }; }; in { - packages.default = customYosys; - defaultPackage = customYosys; + packages.default = yosys; + defaultPackage = yosys; devShell = pkgs.mkShell { buildInputs = with pkgs; [ clang bison flex libffi tcl readline python3 llvmPackages.libcxxClang zlib git gtest abc-verifier ]; };