From 5ecf72081a5c7d5d8da33282b1932dca9ab52db8 Mon Sep 17 00:00:00 2001 From: jaschutte <34577095+jaschutte@users.noreply.github.com> Date: Mon, 4 Aug 2025 13:00:48 +0200 Subject: [PATCH] Nix build circuit-notation for all Clash-GHC supported versions Instead of only building the default version clash-compiler supports, it will now expose builds for all available supported clash-compiler versions. This is a followup for the issue mentioned: https://github.com/clash-lang/clash-compiler/pull/2987 --- flake.lock | 6 ++-- flake.nix | 102 +++++++++++++++++++++++++++++++++-------------------- 2 files changed, 66 insertions(+), 42 deletions(-) diff --git a/flake.lock b/flake.lock index 6cbef75..05c26e1 100644 --- a/flake.lock +++ b/flake.lock @@ -11,11 +11,11 @@ "nixpkgs": "nixpkgs" }, "locked": { - "lastModified": 1753722205, - "narHash": "sha256-tfBkzRbiYVX6f0oSnY86Uem/JSsCmYXfAJxW+ZKmWQk=", + "lastModified": 1754301255, + "narHash": "sha256-dne2oWxOEosMYumUZZhc3c8NyJMdiqpb/xvd1saTp30=", "owner": "clash-lang", "repo": "clash-compiler", - "rev": "43a1c722af29f34c6faf18f14e6cf46a3cfba80f", + "rev": "6a0810496560e2ff2a0071f315afb573c12bba39", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 845665f..ff7d5f4 100644 --- a/flake.nix +++ b/flake.nix @@ -6,47 +6,71 @@ outputs = { self, flake-utils, clash-compiler, ... }: flake-utils.lib.eachDefaultSystem (system: let - # What version of the GHC compiler to use - compiler-version = clash-compiler.ghcVersion.${system}; - - 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; + # The package to expose as 'default' + default-package = "circuit-notation"; + # The 'default' version of ghc to use + default-version = clash-compiler.ghcVersion.${system}; + # A list of all ghc versions this package supports + supported-versions = clash-compiler.supportedGhcVersions.${system}; + + all-overlays = builtins.listToAttrs (builtins.map (compiler-version: + let + overlay = final: prev: { + circuit-notation = prev.developPackage { + root = ./.; + overrides = _: _: final; + }; + }; + in + { name = compiler-version; value = overlay; } + ) supported-versions); + + all-hs-pkgs = builtins.mapAttrs (compiler-version: overlay: + let + pkgs = (import clash-compiler.inputs.nixpkgs { + inherit system; + }).extend clash-compiler.overlays.${compiler-version}; + clash-pkgs = pkgs."clashPackages-${compiler-version}"; + + hs-pkgs = clash-pkgs.extend overlay; + in + hs-pkgs + ) all-overlays; + + all-shells = builtins.mapAttrs (_: hs-pkgs: + 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 + ] + ; + }) all-hs-pkgs; + + all-packages = builtins.mapAttrs (_: hs-pkgs: + { + circuit-notation = hs-pkgs.circuit-notation; + + default = hs-pkgs.${default-package}; + }) all-hs-pkgs; in { - # Expose the overlay which adds circuit-notation + # Expose the overlay of each supported version which adds circuit-notation # The base of the overlay is clash-pkgs - overlays.default = 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; - }; + overlays = all-overlays // { default = all-overlays.${default-version}; }; + + # A devShell for each supported version + devShells = all-shells // { default = all-shells.${default-version}; }; + + # The default directly refers to the default package of the default ghc version of this flake + # All other entries aren't packages, they're a set of packages for each supported ghc version + packages = all-packages // { default = all-packages.${default-version}.${default-package}; }; }); }