From cf62cc7f1f97b13cf59768437b8f61a6984572a3 Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Tue, 10 Jun 2025 10:26:41 -0700 Subject: [PATCH] tests.haskell.ghcWithPackages: init `ghcWithPackages` broke in #411741, partially because we don't have tests for it. This adds some tests to make sure it keeps working in the future. For now these tests will fail until #415436 is fixed. This is split off of #415434. Adds a regression test for https://github.com/NixOS/nixpkgs/pull/224542 --- pkgs/test/haskell/default.nix | 5 +- pkgs/test/haskell/ghcWithPackages/default.nix | 48 +++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 pkgs/test/haskell/ghcWithPackages/default.nix diff --git a/pkgs/test/haskell/default.nix b/pkgs/test/haskell/default.nix index 8f1f21d65b51..26250ccc8f00 100644 --- a/pkgs/test/haskell/default.nix +++ b/pkgs/test/haskell/default.nix @@ -1,10 +1,11 @@ { lib, callPackage }: lib.recurseIntoAttrs { - shellFor = callPackage ./shellFor { }; cabalSdist = callPackage ./cabalSdist { }; documentationTarball = callPackage ./documentationTarball { }; - setBuildTarget = callPackage ./setBuildTarget { }; + ghcWithPackages = callPackage ./ghcWithPackages { }; incremental = callPackage ./incremental { }; + setBuildTarget = callPackage ./setBuildTarget { }; + shellFor = callPackage ./shellFor { }; upstreamStackHpackVersion = callPackage ./upstreamStackHpackVersion { }; } diff --git a/pkgs/test/haskell/ghcWithPackages/default.nix b/pkgs/test/haskell/ghcWithPackages/default.nix new file mode 100644 index 000000000000..c31721b9531e --- /dev/null +++ b/pkgs/test/haskell/ghcWithPackages/default.nix @@ -0,0 +1,48 @@ +{ + lib, + runCommand, + haskellPackages, +}: + +lib.recurseIntoAttrs { + # This is special-cased to return just `ghc`. + trivial = haskellPackages.ghcWithPackages (hsPkgs: [ ]); + + # Here we actually build a trivial package. + hello = haskellPackages.ghcWithPackages (hsPkgs: [ + hsPkgs.hello + ]); + + # Here we build a database with multiple packages. + multiple = haskellPackages.ghcWithPackages (hsPkgs: [ + hsPkgs.hspec + hsPkgs.unordered-containers + ]); + + # See: https://github.com/NixOS/nixpkgs/pull/224542 + regression-224542 = + runCommand "regression-224542" + { + buildInputs = [ + (haskellPackages.ghcWithPackages (hsPkgs: [ + hsPkgs.hspec + ])) + ]; + } + '' + ghc --interactive \ + -Werror=unrecognised-warning-flags \ + -Werror=missed-extra-shared-lib \ + 2>&1 \ + | tee ghc-output.txt + + # If GHC failed to find a shared library, linking dylibs in + # `ghcWithPackages` didn't work correctly. + if grep --quiet "error: .*-Wmissed-extra-shared-lib" ghc-output.txt \ + && grep --quiet "no such file" ghc-output.txt; then + exit 1 + fi + + touch $out + ''; +}