From 35ce86165095543a2244b14251ca21bd5b67d824 Mon Sep 17 00:00:00 2001 From: Aliaksandr Date: Fri, 1 May 2026 03:56:57 +0300 Subject: [PATCH] ghcWithPackages: throw on non-derivation inputs Previously the user-supplied package list was passed directly through `lib.closePropagation` and an `isHaskellLibrary`-attribute filter, so mistakes such as `[ dontCheck hp.foo ]` (forgetting parentheses around the override) silently produced a GHC environment with the affected package missing instead of failing. Validate each top-level entry up front. We deliberately accept any derivation (not just Haskell libraries), because shellFor passes mixed inputs like `libraryFrameworkDepends` through here on Darwin; those are still silently dropped by the existing closure-side filter. The user-error case the issue is about -- non-derivation values like functions or strings -- is now rejected with a helpful message that points at the canonical fix. Fixes #30304 Assisted-by: claude-code with claude-opus-4-8[1m]-high --- .../haskell-modules/with-packages-wrapper.nix | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/pkgs/development/haskell-modules/with-packages-wrapper.nix b/pkgs/development/haskell-modules/with-packages-wrapper.nix index 9968ea355363..37bf1e450314 100644 --- a/pkgs/development/haskell-modules/with-packages-wrapper.nix +++ b/pkgs/development/haskell-modules/with-packages-wrapper.nix @@ -48,7 +48,24 @@ let hoogleWithPackages' = if withHoogle then hoogleWithPackages selectPackages else null; - packages = selectPackages haskellPackages ++ [ hoogleWithPackages' ]; + # Catches obviously-wrong inputs (functions, strings, etc.) but lets + # non-Haskell derivations through; shellFor passes libraryFrameworkDepends + # and similar mixed inputs in, and those are dropped later by the + # closure-side `isHaskellLibrary` filter. + checkPackage = + p: + if p == null || lib.isDerivation p then + p + else + throw '' + ghcWithPackages: expected a derivation, got a ${builtins.typeOf p}. + A common cause is missing parentheses around an override, e.g. + (hp: [ dontCheck hp.foo ]) + should be written as + (hp: [ (dontCheck hp.foo) ]). + ''; + + packages = map checkPackage (selectPackages haskellPackages ++ [ hoogleWithPackages' ]); isHaLVM = ghc.isHaLVM or false; ghcCommand' = "ghc";