From 4a1e6f7cdadfdcee066369e4622099aad38b2055 Mon Sep 17 00:00:00 2001 From: jaschutte <34577095+jaschutte@users.noreply.github.com> Date: Tue, 22 Jul 2025 15:14:07 +0200 Subject: [PATCH 1/2] Update Nix infrastructure The Nix infrastructure of the current project is broken and does not compile. Rather than fixing it, I rewrote it entirely using nix flakes instead. --- default.nix | 16 ---- flake.lock | 197 ++++++++++++++++++++++++++++++++++++++++++ flake.nix | 52 +++++++++++ nix/ghcid.nix | 9 -- nix/nixpkgs.json | 5 -- nix/nixpkgs.nix | 8 -- nix/update-nixpkgs.sh | 43 --------- shell.nix | 25 ------ 8 files changed, 249 insertions(+), 106 deletions(-) delete mode 100644 default.nix create mode 100644 flake.lock create mode 100644 flake.nix delete mode 100644 nix/ghcid.nix delete mode 100644 nix/nixpkgs.json delete mode 100644 nix/nixpkgs.nix delete mode 100755 nix/update-nixpkgs.sh delete mode 100644 shell.nix diff --git a/default.nix b/default.nix deleted file mode 100644 index 25668fa..0000000 --- a/default.nix +++ /dev/null @@ -1,16 +0,0 @@ -{ nixpkgs ? import nix/nixpkgs.nix {} }: - -let lib = nixpkgs.lib; - filterHaskellSource = src: - builtins.filterSource (path: type: - lib.all (i: i != baseNameOf path) - [ ".git" "dist-newstyle" "cabal.project.local" "nix" - "dist" ".stack-work" ".DS_Store" "default.nix" "shell.nix" "result" - ] - && lib.all (i: !(lib.hasSuffix i path)) [ ".lkshf" ] - && lib.all - (i: !(lib.hasPrefix i (baseNameOf path))) - [ "cabal.project.local" ".ghc.environment." ] - ) src; - -in nixpkgs.haskellPackages.callCabal2nix "circuit-notation" (filterHaskellSource ./.) {} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..a3dc52e --- /dev/null +++ b/flake.lock @@ -0,0 +1,197 @@ +{ + "nodes": { + "clash-compiler": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "ghc-tcplugins-extra": "ghc-tcplugins-extra", + "ghc-typelits-extra": "ghc-typelits-extra", + "ghc-typelits-knownnat": "ghc-typelits-knownnat", + "ghc-typelits-natnormalise": "ghc-typelits-natnormalise", + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1752917053, + "narHash": "sha256-oI4b1MZ1MR7WLeyZw9k/g6P+707i7RMhdMxkSIBga2Q=", + "owner": "clash-lang", + "repo": "clash-compiler", + "rev": "229f243605f5ac88fc4e65076acec650ce1164df", + "type": "github" + }, + "original": { + "owner": "clash-lang", + "repo": "clash-compiler", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1726560853, + "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", + "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": { + "id": "flake-utils", + "type": "indirect" + } + }, + "ghc-tcplugins-extra": { + "flake": false, + "locked": { + "lastModified": 1716385093, + "narHash": "sha256-pXQoPP22TicWFwpWub9CX1J+rpOKfyX2IyzlCg1qG84=", + "owner": "clash-lang", + "repo": "ghc-tcplugins-extra", + "rev": "702dda2095c66c4f5148a749c8b7dbcc8a09f5c1", + "type": "github" + }, + "original": { + "owner": "clash-lang", + "repo": "ghc-tcplugins-extra", + "type": "github" + } + }, + "ghc-typelits-extra": { + "flake": false, + "locked": { + "lastModified": 1716411282, + "narHash": "sha256-YH03Ce+TEWKHGAm7BhynitZomfpYeKpqvZAviw8yEPA=", + "owner": "clash-lang", + "repo": "ghc-typelits-extra", + "rev": "4dadc824a3ef9a511fcf6605167715a5a655ba0d", + "type": "github" + }, + "original": { + "owner": "clash-lang", + "repo": "ghc-typelits-extra", + "type": "github" + } + }, + "ghc-typelits-knownnat": { + "flake": false, + "locked": { + "lastModified": 1716408841, + "narHash": "sha256-A2v6GkMtSJqZXpTwWfIcwshieyRySeR1bP+NogUHNoo=", + "owner": "clash-lang", + "repo": "ghc-typelits-knownnat", + "rev": "2e57de3b709dab085fb1657cf73d4f5e833229ee", + "type": "github" + }, + "original": { + "owner": "clash-lang", + "repo": "ghc-typelits-knownnat", + "type": "github" + } + }, + "ghc-typelits-natnormalise": { + "flake": false, + "locked": { + "lastModified": 1716387676, + "narHash": "sha256-G5p0NUy4CpjxGO1VNhb38fhkXESFPxGaZJM0qd6L74U=", + "owner": "clash-lang", + "repo": "ghc-typelits-natnormalise", + "rev": "84f500a9735675e96253181939c3473a567f6f7a", + "type": "github" + }, + "original": { + "owner": "clash-lang", + "repo": "ghc-typelits-natnormalise", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1727089097, + "narHash": "sha256-ZMHMThPsthhUREwDebXw7GX45bJnBCVbfnH1g5iuSPc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "568bfef547c14ca438c56a0bece08b8bb2b71a9c", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "clash-compiler": "clash-compiler", + "flake-utils": "flake-utils_2" + } + }, + "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 0000000..4a74d9c --- /dev/null +++ b/flake.nix @@ -0,0 +1,52 @@ +{ + description = "A flake for developing & using circuit-notation"; + inputs = { + clash-compiler.url = "github:clash-lang/clash-compiler"; + }; + outputs = { self, flake-utils, clash-compiler, ... }: + flake-utils.lib.eachDefaultSystem (system: + let + # What version of the GHC compiler to use + compiler-version = "ghc910"; + + pkgs = (import clash-compiler.inputs.nixpkgs { + inherit system; + }).extend clash-compiler.overlays.${compiler-version}; + clash-pkgs = pkgs."clashPackages-${compiler-version}"; + + overlay = final: prev: { + circuit-notation = prev.developPackage { + root = ./.; + overrides = _: _: final; + }; + }; + + hs-pkgs = clash-pkgs.extend overlay; + in + { + # Expose the overlay which adds circuit-notation + # The base of the overlay is clash-pkgs + overlay = overlay; + + devShells.default = hs-pkgs.shellFor { + packages = p: [ + p.circuit-notation + ]; + + nativeBuildInputs = + [ + # Haskell stuff + hs-pkgs.cabal-install + hs-pkgs.cabal-plan + hs-pkgs.haskell-language-server + hs-pkgs.fourmolu + ] + ; + }; + packages = { + circuit-notation = hs-pkgs.circuit-notation; + + default = hs-pkgs.circuit-notation; + }; + }); +} diff --git a/nix/ghcid.nix b/nix/ghcid.nix deleted file mode 100644 index 00f47e5..0000000 --- a/nix/ghcid.nix +++ /dev/null @@ -1,9 +0,0 @@ -self: super: -{ ghcid = super.haskellPackages.callCabal2nix "ghcid" ( - super.pkgs.fetchFromGitHub { - owner = "ndmitchell"; - repo = "ghcid"; - rev = "f572318f32b1617f6054248e5888af68222f8e50"; - sha256 = "1icg3r70lg2kmd9gdc024ih1n9nrja98yav74z9nvykqygvv5w0n"; - }) {}; - } diff --git a/nix/nixpkgs.json b/nix/nixpkgs.json deleted file mode 100644 index 02b779a..0000000 --- a/nix/nixpkgs.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "url": "https://github.com/nixos/nixpkgs-channels/archive/5659cb448e9b615d642c5fe52779c2223e72f7eb.tar.gz", - "rev": "5659cb448e9b615d642c5fe52779c2223e72f7eb", - "sha256": "1ijwr9jlvdnvr1qqpfdm61nwd871sj4dam28pcv0pvnmp8ndylak" -} diff --git a/nix/nixpkgs.nix b/nix/nixpkgs.nix deleted file mode 100644 index 974c70d..0000000 --- a/nix/nixpkgs.nix +++ /dev/null @@ -1,8 +0,0 @@ - # Grab the versions we specified in the JSON file -{ nixpkgs ? builtins.fromJSON (builtins.readFile ./nixpkgs.json) - # Bootstrap a copy of nixpkgs, based on this. -, src ? builtins.fetchTarball { inherit (nixpkgs) url sha256; } -, ... -}@args: -# Import nixpkgs, returning a lambda taking e.g. currrentSystem, config, etc -import src (builtins.removeAttrs args ["nixpkgs" "src"]) diff --git a/nix/update-nixpkgs.sh b/nix/update-nixpkgs.sh deleted file mode 100755 index 34947da..0000000 --- a/nix/update-nixpkgs.sh +++ /dev/null @@ -1,43 +0,0 @@ -#! /usr/bin/env bash -#! /usr/bin/env nix-shell -#! nix-shell -i bash -p jq curl -#! nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/nixos-18.03.tar.gz - -## Utility to automatically update nixpkgs.json quickly and easily from either -## the Nixpkgs upstream or a custom fork. Runs interactively using `nix-shell` -## for zero-install footprint. -set -e - -API="https://api.github.com/repos" -REPO="nixpkgs-channels" -BRANCH="nixos-20.03" -URL="https://github.com/nixos/${REPO}" - -if [[ "x$1" == "x" ]]; then - echo -n "No revision, so grabbing latest upstream Nixpkgs master commit... " - REV=$(curl -s "${API}/nixos/${REPO}/commits/${BRANCH}" | jq -r '.sha') - echo "OK, got ${REV:0:6}" -else - if [[ "x$2" == "x" ]]; then - REV="$1" - echo "Custom revision (but no repo) provided, using ${URL}" - else - REV="$2" - URL="$1" - echo "Custom revision in upstream ${URL} will be used" - fi -fi - -DOWNLOAD="$URL/archive/$REV.tar.gz" -echo "Updating to nixpkgs revision ${REV:0:6} from $URL" -SHA256=$(nix-prefetch-url --unpack "$DOWNLOAD") - -cat > "$(git rev-parse --show-toplevel)/nix/nixpkgs.json" <&2 echo 'Added test command. Usage: test -T ":l example/Testing.hs"' - ''; -} From b0f1fdd824779c32283dadf6bd7e461a005f547f Mon Sep 17 00:00:00 2001 From: jaschutte <34577095+jaschutte@users.noreply.github.com> Date: Wed, 23 Jul 2025 15:49:58 +0200 Subject: [PATCH 2/2] Fix CI The CI was quite outdated and flatout rejected everything. A clash upstream PR was merged which allowed me to remove the conditional cabal file. --- .github/workflows/ci.yml | 15 +++------------ cabal.ghc-9.10.project | 15 --------------- 2 files changed, 3 insertions(+), 27 deletions(-) delete mode 100644 cabal.ghc-9.10.project diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b93d35f..d8c4c55 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,14 +16,13 @@ jobs: nix: name: nix build runs-on: ubuntu-latest - container: - image: 'nixos/nix:2.3.6' steps: - uses: actions/checkout@v3 + - uses: cachix/install-nix-action@v31 - name: Build run: | - nix-build + nix build cabal: name: ${{ matrix.os }} / ghc ${{ matrix.ghc }} @@ -45,7 +44,6 @@ jobs: steps: - uses: actions/checkout@v3 - # if: github.event.action == 'opened' || github.event.action == 'synchronize' || github.event.ref == 'refs/heads/master' - uses: haskell-actions/setup@v2 id: setup-haskell-cabal @@ -54,19 +52,12 @@ jobs: ghc-version: ${{ matrix.ghc }} cabal-version: ${{ matrix.cabal }} - # This can be dropped once - # https://github.com/clash-lang/clash-compiler/pull/2790 is merged. - - name: Apply GHC-9.10 cabal project configuration - if: matrix.ghc == "9.10.1" - run: | - mv cabal.ghc-9.10.project cabal.project - - name: Freeze run: | cabal update cabal freeze - - uses: actions/cache@v1 + - uses: actions/cache@v4 name: Cache ~/.cabal/store with: path: ${{ steps.setup-haskell-cabal.outputs.cabal-store }} diff --git a/cabal.ghc-9.10.project b/cabal.ghc-9.10.project deleted file mode 100644 index 1ddb4af..0000000 --- a/cabal.ghc-9.10.project +++ /dev/null @@ -1,15 +0,0 @@ --- This can be removed once https://github.com/clash-lang/clash-compiler/pull/2790 --- is merged. - -packages: . - ------------------------------------------------------------ --- clash-prelude for GHC 9.10 ------------------------------------------------------------ - -source-repository-package - type: git - location: https://github.com/clash-lang/clash-compiler - tag: 15dc344dfa091de14c63759c0b6ea107ca0fa892 - subdir: clash-prelude -