From 7fa6c51f9601197825dc36626759f7d3f13ba00b Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Wed, 23 Apr 2025 13:13:39 +0200 Subject: [PATCH 1/6] shell.nix: pin nixpkgs to a default revision This enables us to do more elaborate overrides (which should be gated behind a flag, though!) which are unlikely to work with _any_ Nixpkgs revision. --- shell.nix | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/shell.nix b/shell.nix index 04f9c57f..67875099 100644 --- a/shell.nix +++ b/shell.nix @@ -1,4 +1,9 @@ -{ pkgs ? import { } +{ pkgs ? + import (builtins.fetchTarball { + # nixos-unstable 2025-04-23 + url = "https://github.com/nixos/nixpkgs/archive/96d30055a2215e5c5a545872376137a5d063e804.tar.gz"; + sha256 = "0xvzkpgc8qy4q252c3x399c8ikrks970c877s4i7vppnhxp08p8n"; + }) { } , ghcVersion ? pkgs.haskellPackages.ghc.version , withHls ? true }: From 09d45c945d6c66a3b3eea29824aa3e64ec0efc01 Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Wed, 23 Apr 2025 13:14:56 +0200 Subject: [PATCH 2/6] shell.nix: add minimal flag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The minimal flag is intended to disable “superfluous” stuff, i.e. anything that isn't necessary to build the included packages and run their tests. It is used to determine withHls for now, but has a less specific meaning. The idea is that you use nix-shell --arg minimal true --arg pkgs "(import {})" when using a nixpkgs version different from the pin. --- shell.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/shell.nix b/shell.nix index 67875099..e4abaea8 100644 --- a/shell.nix +++ b/shell.nix @@ -5,7 +5,10 @@ sha256 = "0xvzkpgc8qy4q252c3x399c8ikrks970c877s4i7vppnhxp08p8n"; }) { } , ghcVersion ? pkgs.haskellPackages.ghc.version -, withHls ? true + # Pass --arg minimal true to disable tools that are not strictly necessary + # and may break when using non default GHC versions / other Nixpkgs revisions. +, minimal ? false +, withHls ? !minimal }: let From bfb7ddb984c579d9329abd3c53d8c01773f73bb1 Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Wed, 23 Apr 2025 13:23:30 +0200 Subject: [PATCH 3/6] shell.nix: update haskell-ci to current HEAD This takes a while to compile unfortunately, so it is possible to disable it using --arg minimal false. Maybe it should be excluded by default? --- shell.nix | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/shell.nix b/shell.nix index e4abaea8..25837083 100644 --- a/shell.nix +++ b/shell.nix @@ -15,6 +15,27 @@ let haskellPackages = pkgs.haskell.packages."ghc${ builtins.replaceStrings [ "." ] [ "" ] ghcVersion }"; + inherit (pkgs) lib; + haskellLib = pkgs.haskell.lib.compose; + + haskell-ci-pinned = lib.pipe + pkgs.haskell.packages.ghc9101.haskell-ci # compatible Cabal version by default + [ + (haskellLib.overrideSrc { + version = "0-unstable-2025-03-30"; + src = pkgs.fetchFromGitHub rec { + name = "haskell-ci-source-${lib.substring 0 7 rev}"; + owner = "haskell-CI"; + repo = "haskell-ci"; + rev = "f0fd898ab14070fa46e9fd542a2b487a8146d88e"; + sha256 = "1pzrnpwsamy8ld6gb7vf9acr873z5q35pixbkwxvji5y9si0x352"; + }; + }) + # Make the build a bit less expensive + haskellLib.dontCheck + haskellLib.disableLibraryProfiling + ]; + ghc = haskellPackages.ghcWithHoogle (hps: [ hps.ansi-wl-pprint hps.hopenssl @@ -38,12 +59,13 @@ in pkgs.mkShell { packages = [ ghc pkgs.cabal-install - pkgs.haskell-ci - (pkgs.lib.getLib pkgs.openssl) + (lib.getLib pkgs.openssl) # Needed to run `cabal2nix`: pkgs.nix-prefetch-scripts - ] ++ pkgs.lib.optionals withHls [ + ] ++ lib.optionals withHls [ haskellPackages.haskell-language-server + ] ++ lib.optionals (!minimal) [ + haskell-ci-pinned ]; # Make Paths_ module of distribution-nixpkgs find its data files in the shell. From eea51f2c03ab1ec220c8d847157c1790abf8d491 Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Wed, 23 Apr 2025 12:36:14 +0200 Subject: [PATCH 4/6] cabal2nix/test: support Cabal >= 3.14 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We don't pass a CWD to readGenericPackageDescription since the whole test suite uses the working directory of the process to find the test data anyways (which we could improve in principle…). --- cabal2nix/CHANGELOG.md | 4 ++++ cabal2nix/test/Main.hs | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/cabal2nix/CHANGELOG.md b/cabal2nix/CHANGELOG.md index d21474dc..bd2d3714 100644 --- a/cabal2nix/CHANGELOG.md +++ b/cabal2nix/CHANGELOG.md @@ -1,5 +1,9 @@ # Revision History for cabal2nix +## Unreleased + +- Add support for Cabal `== 3.14.*` in the test suite. + ## 2.20.0 * `cabal2nix` now [prints the commands it runs when fetching sources](https://github.com/nixOS/cabal2nix/commit/5327953d299eba0b6de4e88bacf4bba9022bb5e2). diff --git a/cabal2nix/test/Main.hs b/cabal2nix/test/Main.hs index d4a6e4e9..5201c5cd 100644 --- a/cabal2nix/test/Main.hs +++ b/cabal2nix/test/Main.hs @@ -22,6 +22,9 @@ import Distribution.PackageDescription import Distribution.PackageDescription.Parsec #endif import Distribution.System +#if MIN_VERSION_Cabal(3,14,0) +import Distribution.Utils.Path (makeSymbolicPath) +#endif import Distribution.Verbosity import Distribution.Version import Language.Nix @@ -38,6 +41,7 @@ main = do -- depend on the system environment: https://github.com/NixOS/cabal2nix/issues/333. -- -- TODO: Run this test without $HOME defined to ensure that we don't need that variable. + -- TODO: make test suite independent of working directory somehow cabal2nix <- findExecutable "cabal2nix" >>= \case Nothing -> fail "cannot find 'cabal2nix' in $PATH" Just exe -> pure exe @@ -74,7 +78,12 @@ testLibrary cabalFile = do (\ref new -> ["diff", "-u", ref, new]) goldenFile nixFile - (readGenericPackageDescription silent cabalFile >>= writeFileLn nixFile . prettyShow . cabal2nix) +#if MIN_VERSION_Cabal(3,14,0) + (readGenericPackageDescription silent Nothing (makeSymbolicPath cabalFile) +#else + (readGenericPackageDescription silent cabalFile +#endif + >>= writeFileLn nixFile . prettyShow . cabal2nix) -- | TODO: -- From 7aa42ae8dea2e129dbeb1260f258ea76c773306d Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Wed, 23 Apr 2025 13:26:48 +0200 Subject: [PATCH 5/6] Test all packages with GHC 9.12.2 --- .github/workflows/haskell-ci.yml | 5 +++++ cabal2nix/cabal2nix.cabal | 2 +- distribution-nixpkgs/distribution-nixpkgs.cabal | 2 +- hackage-db/hackage-db.cabal | 2 +- language-nix/language-nix.cabal | 2 +- 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/haskell-ci.yml b/.github/workflows/haskell-ci.yml index 18c51ebb..8011a79b 100644 --- a/.github/workflows/haskell-ci.yml +++ b/.github/workflows/haskell-ci.yml @@ -32,6 +32,11 @@ jobs: strategy: matrix: include: + - compiler: ghc-9.12.2 + compilerKind: ghc + compilerVersion: 9.12.2 + setup-method: ghcup + allow-failure: false - compiler: ghc-9.10.1 compilerKind: ghc compilerVersion: 9.10.1 diff --git a/cabal2nix/cabal2nix.cabal b/cabal2nix/cabal2nix.cabal index 3947b13a..d2d16536 100644 --- a/cabal2nix/cabal2nix.cabal +++ b/cabal2nix/cabal2nix.cabal @@ -12,7 +12,7 @@ author: Peter Simons -- list all contributors: git log --pretty='%an' | sort | uniq maintainer: sternenseemann stability: stable -tested-with: GHC == 8.10.7 || == 9.0.2 || == 9.2.8 || == 9.4.8 || == 9.6.7 || == 9.8.4 || == 9.10.1 +tested-with: GHC == 8.10.7 || == 9.0.2 || == 9.2.8 || == 9.4.8 || == 9.6.7 || == 9.8.4 || == 9.10.1 || == 9.12.2 category: Distribution, Nix homepage: https://github.com/nixos/cabal2nix#readme bug-reports: https://github.com/nixos/cabal2nix/issues diff --git a/distribution-nixpkgs/distribution-nixpkgs.cabal b/distribution-nixpkgs/distribution-nixpkgs.cabal index 32469368..5697f721 100644 --- a/distribution-nixpkgs/distribution-nixpkgs.cabal +++ b/distribution-nixpkgs/distribution-nixpkgs.cabal @@ -6,7 +6,7 @@ license: BSD3 license-file: LICENSE author: Peter Simons maintainer: sternenseemann -tested-with: GHC == 8.10.7 || == 9.0.2 || == 9.2.8 || == 9.4.8 || == 9.6.7 || == 9.8.4 || == 9.10.1 +tested-with: GHC == 8.10.7 || == 9.0.2 || == 9.2.8 || == 9.4.8 || == 9.6.7 || == 9.8.4 || == 9.10.1 || == 9.12.2 category: Distribution, Nix homepage: https://github.com/NixOS/cabal2nix/tree/master/distribution-nixpkgs#readme bug-reports: https://github.com/NixOS/cabal2nix/issues diff --git a/hackage-db/hackage-db.cabal b/hackage-db/hackage-db.cabal index 241c1438..30c64335 100644 --- a/hackage-db/hackage-db.cabal +++ b/hackage-db/hackage-db.cabal @@ -9,7 +9,7 @@ license: BSD3 license-file: LICENSE author: Peter Simons, Alexander Altman, Ben James, Kevin Quick maintainer: sternenseemann -tested-with: GHC == 8.10.7 || == 9.0.2 || == 9.2.8 || == 9.4.8 || == 9.6.7 || == 9.8.4 || == 9.10.1 +tested-with: GHC == 8.10.7 || == 9.0.2 || == 9.2.8 || == 9.4.8 || == 9.6.7 || == 9.8.4 || == 9.10.1 || == 9.12.2 category: Distribution homepage: https://github.com/NixOS/cabal2nix/tree/master/hackage-db#readme bug-reports: https://github.com/NixOS/cabal2nix/issues diff --git a/language-nix/language-nix.cabal b/language-nix/language-nix.cabal index 61074b9e..6d2edbe3 100644 --- a/language-nix/language-nix.cabal +++ b/language-nix/language-nix.cabal @@ -7,7 +7,7 @@ license: BSD3 license-file: LICENSE author: Peter Simons maintainer: simons@cryp.to -tested-with: GHC == 8.10.7, GHC == 9.0.2, GHC == 9.2.8, GHC == 9.4.8, GHC == 9.6.7 || == 9.8.4 || == 9.10.1 +tested-with: GHC == 8.10.7, GHC == 9.0.2, GHC == 9.2.8, GHC == 9.4.8, GHC == 9.6.7 || == 9.8.4 || == 9.10.1 || == 9.12.2 category: Distribution, Language, Nix homepage: https://github.com/NixOS/cabal2nix/tree/master/language-nix#readme bug-reports: https://github.com/NixOS/cabal2nix/issues From 12004c49adfb0898798578e66995e38b3d50805a Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Wed, 23 Apr 2025 14:01:30 +0200 Subject: [PATCH 6/6] .envrc: use minimal shell, but include HLS haskell-ci takes a while to compile and is probably not always necessary. We should keep HLS since many editors use direnv to find HLS and direnv will use the default GHC / HLS from the pinned nixpkgs revision which should be cached. --- .envrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.envrc b/.envrc index 5426c018..f2f9cee6 100644 --- a/.envrc +++ b/.envrc @@ -3,5 +3,5 @@ if type -p lorri; then eval "$(lorri direnv)" else echo "direnv: using direnv nix support" 1>&2 - use nix; + use nix --arg minimal true --arg withHls true; fi