diff --git a/README.md b/README.md index 8553482fe3..8478ea75b0 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,7 @@ Or [use Nix](https://nixos.org/nix/download.html) to get a shell with the `clash nix develop . # Start a dev shell with a specific GHC version -nix develop .#ghc961 +nix develop .#ghc9101 ``` You will need a modern version of nix with support for the new-style `nix` diff --git a/clash-cores/clash-cores.cabal b/clash-cores/clash-cores.cabal index 78d1024370..ba570e4f39 100644 --- a/clash-cores/clash-cores.cabal +++ b/clash-cores/clash-cores.cabal @@ -36,12 +36,6 @@ flag haddock default: False manual: True -flag nix - description: - Are we building this package from nix - default: False - manual: True - -- TODO: Remove this workaround. See: -- -- https://github.com/clash-lang/clash-compiler/pull/2665#issuecomment-1939044550 @@ -83,22 +77,6 @@ common basic-config if flag(haddock) ghc-options: -fdefer-type-errors - elif flag(nix) - -- It's absolutely grimy, but if we don't specify the `-package` flags here - -- then when nix eventually calls `./Setup register` on the package it will - -- still pass the `-fplugin` options to GHC and fail to create the package - -- registation file needed to finish the `installPhase`. - -- - -- These flags are something we NEVER want to manually specify in a normal - -- build, since correctly configuring this kind of thing should be solely - -- left to cabal as a build tool. - ghc-options: - -package ghc-typelits-extra - -fplugin GHC.TypeLits.Extra.Solver - -package ghc-typelits-knownnat - -fplugin GHC.TypeLits.Normalise - -package ghc-typelits-natnormalise - -fplugin GHC.TypeLits.KnownNat.Solver else ghc-options: -fplugin GHC.TypeLits.Extra.Solver diff --git a/flake.lock b/flake.lock index d6b09d79fb..18f2471dc2 100644 --- a/flake.lock +++ b/flake.lock @@ -3,11 +3,11 @@ "flake-compat": { "flake": false, "locked": { - "lastModified": 1673956053, - "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", "owner": "edolstra", "repo": "flake-compat", - "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", "type": "github" }, "original": { @@ -21,11 +21,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1694529238, - "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "lastModified": 1726560853, + "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", "owner": "numtide", "repo": "flake-utils", - "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", "type": "github" }, "original": { @@ -37,11 +37,11 @@ "ghc-tcplugins-extra": { "flake": false, "locked": { - "lastModified": 1690791784, - "narHash": "sha256-RG9UpAYOjH276sFC+XrX847WR26qVhr/KHTsEOkw3rs=", + "lastModified": 1716385093, + "narHash": "sha256-pXQoPP22TicWFwpWub9CX1J+rpOKfyX2IyzlCg1qG84=", "owner": "clash-lang", "repo": "ghc-tcplugins-extra", - "rev": "92b5215273bc219da9550799e0869ea6934648f0", + "rev": "702dda2095c66c4f5148a749c8b7dbcc8a09f5c1", "type": "github" }, "original": { @@ -53,11 +53,11 @@ "ghc-typelits-extra": { "flake": false, "locked": { - "lastModified": 1690794410, - "narHash": "sha256-Q8zXP9ZcVBkUrniBOM00tYqgGipDhbbPqkVTCrs7vYo=", + "lastModified": 1716411282, + "narHash": "sha256-YH03Ce+TEWKHGAm7BhynitZomfpYeKpqvZAviw8yEPA=", "owner": "clash-lang", "repo": "ghc-typelits-extra", - "rev": "bbe2a40d6bc640ab065dd87db74ba59e584aa9f2", + "rev": "4dadc824a3ef9a511fcf6605167715a5a655ba0d", "type": "github" }, "original": { @@ -69,11 +69,11 @@ "ghc-typelits-knownnat": { "flake": false, "locked": { - "lastModified": 1690793234, - "narHash": "sha256-Y+Qjz8r+B0hUAhRVrxddQxnJLNVKLMAz5OLsRQ5behE=", + "lastModified": 1716408841, + "narHash": "sha256-A2v6GkMtSJqZXpTwWfIcwshieyRySeR1bP+NogUHNoo=", "owner": "clash-lang", "repo": "ghc-typelits-knownnat", - "rev": "2b72c495b4158d49ef46609036b08e414bcdba5c", + "rev": "2e57de3b709dab085fb1657cf73d4f5e833229ee", "type": "github" }, "original": { @@ -85,11 +85,11 @@ "ghc-typelits-natnormalise": { "flake": false, "locked": { - "lastModified": 1690792488, - "narHash": "sha256-1ZSF6FCSmh4Pd7aUEXa5VFkBibuOyE1tqbndGikO+sA=", + "lastModified": 1716387676, + "narHash": "sha256-G5p0NUy4CpjxGO1VNhb38fhkXESFPxGaZJM0qd6L74U=", "owner": "clash-lang", "repo": "ghc-typelits-natnormalise", - "rev": "3289e1a25df3d7752d6734aa83ba04782d6e43cd", + "rev": "84f500a9735675e96253181939c3473a567f6f7a", "type": "github" }, "original": { @@ -100,11 +100,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1694948089, - "narHash": "sha256-d2B282GmQ9o8klc22/Rbbbj6r99EnELQpOQjWMyv0rU=", + "lastModified": 1727089097, + "narHash": "sha256-ZMHMThPsthhUREwDebXw7GX45bJnBCVbfnH1g5iuSPc=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "5148520bfab61f99fd25fb9ff7bfbb50dad3c9db", + "rev": "568bfef547c14ca438c56a0bece08b8bb2b71a9c", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 5bc52cb39c..c6f6284112 100644 --- a/flake.nix +++ b/flake.nix @@ -36,12 +36,12 @@ # The versions of GHC that we want to be able to build / develop against # within the nix environment. Since nix is lazy, only derivations for # versions of GHC which are used are actually evaluated. - ghcVersions = [ "ghc902" "ghc962" ]; + ghcVersions = [ "ghc964" "ghc982" "ghc9101" ]; # We pick a single version of GHC to use by default within nix. This is # probably cleaner than always having N copies of each package / app and # being forced to refer to them by their GHC version. - defaultGhcVersion = "ghc962"; + defaultGhcVersion = "ghc9101"; # Overlays are not per-system, so let's only compute them once. # For each version of GHC we produce a `pkgs.clashPackages-ghcVER`, e.g. diff --git a/nix/overlay-ghc902.nix b/nix/overlay-ghc902.nix deleted file mode 100644 index d64138de2b..0000000000 --- a/nix/overlay-ghc902.nix +++ /dev/null @@ -1,33 +0,0 @@ -{ pkgs }: -final: prev: -let - inherit (pkgs.haskell.lib) doJailbreak dontCheck markUnbroken; -in -{ - # Use an older version than the default in nixpkgs. Since rewrite-inspector - # is basically abandonware it catches fire with brick 1.0+. - brick = doJailbreak prev.brick_0_70_1; - - # Marked as broken in nixpkgs for this version of GHC. - docopt = markUnbroken prev.docopt; - - # Marked as broken in nixpkgs, since it specifies much older dependencies - # than the defaults in nixpkgs. - rewrite-inspector = doJailbreak (markUnbroken prev.rewrite-inspector); - - singletons = prev.callHackage "singletons" "3.0" { }; - - # Lower the version to match `singletons-th`. - singletons-base = prev.callHackage "singletons-base" "3.0" { }; - - # The versions on nixpkgs are too new for GHC 9.0.2, which doesn't have - # type level `Char` literals. - singletons-th = prev.callHackage "singletons-th" "3.0" { - inherit (final) th-desugar; - }; - - # We can't use newer than 1.12 here: we need singletons 3.x (due to the cabal - # file of `clash-testsuite`) but the changed `DConP` constructor in 1.13 - # stops `singletons-th` from building. - th-desugar = prev.callHackage "th-desugar" "1.12" { }; -} diff --git a/nix/overlay-ghc910.nix b/nix/overlay-ghc910.nix new file mode 100644 index 0000000000..323ade8104 --- /dev/null +++ b/nix/overlay-ghc910.nix @@ -0,0 +1,71 @@ +{ pkgs }: +final: prev: +let + inherit (pkgs.haskell.lib) dontCheck doJailbreak markUnbroken; +in +{ + # Use an older version than the default in nixpkgs. Since rewrite-inspector + # is basically abandonware it catches fire with brick 1.0+. + brick = doJailbreak prev.brick_0_70_1; + + # brick 0.70.1 requires vty < 6.0. + vty = doJailbreak (prev.callHackage "vty" "5.39" { }); + + # Relies on older versions of some libraries. + hint = doJailbreak prev.hint; + + # Marked as broken in nixpkgs, since it specifies much older dependencies + # than the defaults in nixpkgs. + rewrite-inspector = doJailbreak (markUnbroken prev.rewrite-inspector); + + # Requires some old versions of libraries, but still works. + derive-storable-plugin = doJailbreak prev.derive-storable-plugin; + + # Marken as broken, but compiles anyway. + hedgehog-fakedata = doJailbreak (markUnbroken prev.hedgehog-fakedata); + + # Fails on GHC 9.10 with: + # library/Text/Regex/PCRE/Heavy.hs:123: failure in expression `head $ scan [re|\s*entry (\d+) (\w+)\s*&?|] (" entry 1 hello &entry 2 hi" :: String)' + # expected: (" entry 1 hello &",["1","hello"]) + # but got: :55:1: warning: [GHC-63394] [-Wx-partial] + # ^ + # In the use of ‘head’ + # (imported from Prelude.Compat, but defined in GHC.Internal.List): + # "This is a partial function, it throws an error on empty lists. Use pattern matching, 'Data.List.uncons' or 'Data.Maybe.listToMaybe' instead. Consider refactoring to use "Data.List.NonEmpty"." + # (" entry 1 hello &",["1","hello"]) + + pcre-heavy = dontCheck prev.pcre-heavy; + + # Relies on older versions of text. + string-random = doJailbreak prev.string-random; + + # We need the newest version from nixpkgs for these packages. + singletons-base = prev.singletons-base_3_4; + + microstache = prev.microstache_1_0_3; + + th-desugar = prev.th-desugar_1_17; + + # We need a new tasty-flaky. The one from Hackage doesn't build for some weird + # reason.. + tasty-flaky = prev.callCabal2nix "tasty-flaky" (pkgs.fetchFromGitHub { + owner = "LaurentRDC"; + repo = "tasty-flaky"; + rev = "fc31a9d622c1eb60030a50152258a9bef785e365"; + sha256 = "sha256-irLM3aVMxpBgsM72ArulMXcoLY2glalVkG//Lrj2JBI="; + }) {}; + + tasty = prev.tasty_1_5; + + singletons-th = prev.singletons-th_3_4; + + # nixpkgs doesn't include revision 1, changing dependency on template-haskell. + string-interpolate = pkgs.haskell.lib.compose.overrideCabal (drv: { + revision = "1"; + editedCabalFile = "sha256-oh0tR+LDFcVzQnm4kSrmhAU+P7wdai536d72Cvhzipg="; + }) (prev.callHackageDirect { + pkg = "string-interpolate"; + ver = "0.3.4.0"; + sha256 = "sha256-KA8P6cc6N7pZ9/ay3edcEGx4vpKtp+EY7tn8U1NrbG8="; + } { }); +} diff --git a/nix/overlay-ghc962.nix b/nix/overlay-ghc96.nix similarity index 63% rename from nix/overlay-ghc962.nix rename to nix/overlay-ghc96.nix index 9eb95a2b5e..14543565a5 100644 --- a/nix/overlay-ghc962.nix +++ b/nix/overlay-ghc96.nix @@ -1,13 +1,19 @@ { pkgs }: final: prev: let - inherit (pkgs.haskell.lib) doJailbreak dontCheck markUnbroken; + inherit (pkgs.haskell.lib) doJailbreak markUnbroken dontCheck; in { # Use an older version than the default in nixpkgs. Since rewrite-inspector # is basically abandonware it catches fire with brick 1.0+. brick = doJailbreak prev.brick_0_70_1; + # brick 0.70.1 requires vty < 6.0. + vty = prev.callHackage "vty" "5.39" { }; + + # Marked as broken in nixpkgs, since it needs a newer hashable than the + # .cabal file currently uploaded to hackage. + concurrent-supply = doJailbreak (markUnbroken prev.concurrent-supply); # Use a branch with changes to support GHC 9.6.1. hint = @@ -25,28 +31,18 @@ in # than the defaults in nixpkgs. rewrite-inspector = doJailbreak (markUnbroken prev.rewrite-inspector); - # We want a version that matches with singletons-th, but the tests in here - # are also a bit flaky since GHC 9.6 isn't officially supported. - singletons-base = dontCheck prev.singletons-base_3_2; - - # Use a newer version than the default in nixpkgs. - singletons-th = prev.singletons-th_3_2; - # Needs a newer text than the .cabal file currently uploaded to hackage. string-qq = doJailbreak prev.string-qq; - # Needs a newer version than the default in nixpkgs. - th-desugar = prev.th-desugar_1_15; - # Needs a newer base than the .cabal file currently uploaded to hackage. vector-binary-instances = doJailbreak prev.vector-binary-instances; - # Use an older version than the default in nixpkgs. - th-abstraction = prev.th-abstraction_0_5_0_0; - # type-errors 0.2.0.2 is bounded on doctest >=0.16.0.1 && <0.22 doctest = prev.callHackage "doctest" "0.21.1" { }; + # Marken as broken, but compiles anyway. + hedgehog-fakedata = doJailbreak (markUnbroken prev.hedgehog-fakedata); + # We need a new tasty-flaky. The one from Hackage doesn't build for some weird # reason.. tasty-flaky = prev.callCabal2nix "tasty-flaky" (pkgs.fetchFromGitHub { @@ -55,4 +51,15 @@ in rev = "fc31a9d622c1eb60030a50152258a9bef785e365"; sha256 = "sha256-irLM3aVMxpBgsM72ArulMXcoLY2glalVkG//Lrj2JBI="; }) {}; + + # This version of tasty isn't available in the nix ghc96 package set + tasty = prev.callHackageDirect { + pkg = "tasty"; + ver = "1.5.3"; + sha256 = "sha256-Ogd8J4aHNeL+xmcRWuJeGBNaePyLs5yo1IoMzvWrVPY="; + } {}; + + # The tests (not the package itself!) require a tasty <1.5, which won't work as we pull in + # tasty 1.5.3. Solution: don't test! + time-compat = dontCheck prev.time-compat; } diff --git a/nix/overlay-ghc98.nix b/nix/overlay-ghc98.nix new file mode 100644 index 0000000000..aeb9151165 --- /dev/null +++ b/nix/overlay-ghc98.nix @@ -0,0 +1,43 @@ +{ pkgs }: +final: prev: +let + inherit (pkgs.haskell.lib) doJailbreak markUnbroken dontCheck; +in +{ + # Use an older version than the default in nixpkgs. Since rewrite-inspector + # is basically abandonware it catches fire with brick 1.0+. + brick = doJailbreak prev.brick_0_70_1; + + # brick 0.70.1 requires vty < 6.0. + vty = doJailbreak (prev.callHackage "vty" "5.39" { }); + + # Marked as broken in nixpkgs, since it specifies much older dependencies + # than the defaults in nixpkgs. + rewrite-inspector = doJailbreak (markUnbroken prev.rewrite-inspector); + + # Requires some old versions of libraries, but still works. + derive-storable-plugin = doJailbreak prev.derive-storable-plugin; + + # Marken as broken, but compiles anyway. + hedgehog-fakedata = doJailbreak (markUnbroken prev.hedgehog-fakedata); + + # We need a new tasty-flaky. The one from Hackage doesn't build for some weird + # reason.. + tasty-flaky = prev.callCabal2nix "tasty-flaky" (pkgs.fetchFromGitHub { + owner = "LaurentRDC"; + repo = "tasty-flaky"; + rev = "fc31a9d622c1eb60030a50152258a9bef785e365"; + sha256 = "sha256-irLM3aVMxpBgsM72ArulMXcoLY2glalVkG//Lrj2JBI="; + }) {}; + + # This version of tasty isn't available in the nix ghc98 package set + tasty = prev.callHackageDirect { + pkg = "tasty"; + ver = "1.5.3"; + sha256 = "sha256-Ogd8J4aHNeL+xmcRWuJeGBNaePyLs5yo1IoMzvWrVPY="; + } {}; + + # The tests (not the package itself!) require a tasty <1.5, which won't work as we pull in + # tasty 1.5.3. Solution: don't test! + time-compat = dontCheck prev.time-compat; +} diff --git a/nix/overlay.nix b/nix/overlay.nix index 40274a9f60..affe131d7f 100644 --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -15,7 +15,9 @@ compilerVersion: final: prev: let # An overlay with the things we need to change for the specified GHC version. - ghcOverlay = import (./. + "/overlay-${compilerVersion}.nix") { + # The overlays are named without the GHC minor version, so we need to strip the last character from the version + strippedMinorVersion = builtins.substring 0 (builtins.stringLength compilerVersion - 1) compilerVersion; + ghcOverlay = import (./. + "/overlay-${strippedMinorVersion}.nix") { pkgs = prev; }; @@ -76,9 +78,30 @@ let }); clash-cores = - hprev.callCabal2nixWithOptions "clash-cores" ../clash-cores "--flag nix" { - inherit (hfinal) clash-prelude; - }; + let + # Remove the -fplugin and Setup.hs settings in the .cabal + # For ghc9101+ these options don't matter, but for ghc964 and ghc982 this breaks installation + # When entering the installPhase something (I'm not entirely sure what) goes wrong + # between Nix and GHC, causing Setup.hs to get invoked with the wrong set of packages + # (I think?). Removing the specific flags during installation fixes the issue for Nix, + # whilst not breaking regular compilation. + # + # Do note that this patch only gets applied during *installation* and not *compilation* + # That means these flags are still in place during compilation + override-attrs = if compilerVersion == "ghc964" || compilerVersion == "ghc982" then + fAttr: pAttr: { + preInstall = pAttr.preInstall or "" + '' + sed -i "/-fplugin GHC.TypeLits.Extra.Solver/,+2d" clash-cores.cabal + ''; + } + else + {}; + + cores = hprev.callCabal2nixWithOptions "clash-cores" ../clash-cores "--flag nix" { + inherit (hfinal) clash-prelude; + }; + in + cores.overrideAttrs override-attrs; clash-cosim = let