Generated code contains GHC.Internal imports
When I run the generator through the nix flake, it creates types like GHC.Internal.Maybe.Maybe GHC.Types.Float, but ghc-internal is not (and IMHO shouldn't be) a dependency of the generated package. So the generated package doesn't build.
Could you provide a minimal reproducer for this?
Yes.
{
description = "openapi-bug";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable-small";
flake-utils.url = "github:numtide/flake-utils";
openapi3-code-generator.url = "github:Haskell-OpenAPI-Code-Generator/Haskell-OpenAPI-Client-Code-Generator";
};
outputs = { self, nixpkgs, flake-utils, openapi3-code-generator }:
with builtins;
with nixpkgs.lib;
flake-utils.lib.eachDefaultSystem
(system:
let
openapi3-code-generator-overlay = openapi3-code-generator.overlays.${system};
pkgs = import nixpkgs {
inherit system;
overlays = [
openapi3-code-generator-overlay
];
};
json = toFile "openapi-bug.json" ''
{
"openapi": "3.0.1",
"info": {
"title": "openapi-bug",
"version": "v1"
},
"paths": {
"/foo/bar": {
"get": {
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/someenum"
}
}
}
}
}
}
},
},
"components": {
"schemas": {
"someenum": {
"enum": [
"variant"
],
"type": "string"
}
}
}
}
'';
openapi-bug-src = pkgs.runCommand "openapi-bug-src"
{
src = json;
nativeBuildInputs = [
pkgs.openapi3-code-generator
pkgs.cabal-install
];
} ''
openapi3-code-generator-exe ${json} -f -o $out --package-name openapi-bug
ls -r $out
'';
in
{
packages.default = pkgs.haskellPackages.callCabal2nix "openapi-bug" openapi-bug-src {};
});
}
❯ nix flake info
warning: 'nix flake info' is a deprecated alias for 'nix flake metadata'
Resolved URL: path:/home/turion/haskell/openapi-bug
Locked URL: path:/home/turion/haskell/openapi-bug?lastModified=1762771795&narHash=sha256-XO%2ByUDnSUfvTDULRC8c62ESk/zjKB3TsB6gDdXEBwVQ%3D
Description: openapi-bug
Path: /nix/store/6qxvwh8vc3ikg0wfnk0ipqvq1zsmrhib-source
Last modified: 2025-11-10 11:49:55
Inputs:
├───flake-utils: github:numtide/flake-utils/11707dc2f618dd54ca8739b309ec4fc024de578b
│ Last modified: 2024-11-13 22:27:16
│ └───systems: github:nix-systems/default/da67096a3b9bf56a91d16901293e51ba5b49a27e
│ Last modified: 2023-04-09 10:27:08
├───nixpkgs: github:NixOS/nixpkgs/e5d07586ec39f74b390308f2e00040c23bdef530
│ Last modified: 2025-11-09 21:56:22
└───openapi3-code-generator: github:Haskell-OpenAPI-Code-Generator/Haskell-OpenAPI-Client-Code-Generator/311cf56a736846b4b578f30a9f894fd90ef5dd27
Last modified: 2025-11-04 15:43:23
├───flake-utils: github:numtide/flake-utils/11707dc2f618dd54ca8739b309ec4fc024de578b
│ Last modified: 2024-11-13 22:27:16
│ └───systems: github:nix-systems/default/da67096a3b9bf56a91d16901293e51ba5b49a27e
│ Last modified: 2023-04-09 10:27:08
├───nixpkgs: github:NixOS/nixpkgs/7c43f080a7f28b2774f3b3f43234ca11661bf334
│ Last modified: 2025-05-25 10:38:51
└───pre-commit-hooks: github:cachix/pre-commit-hooks.nix/dcf5072734cb576d2b0c59b2ac44f5050b5eac82
Last modified: 2025-03-22 14:26:04
├───flake-compat: github:edolstra/flake-compat/0f9255e01c2351cc7d116c072cb317785dd33b33
│ Last modified: 2023-10-04 15:37:54
├───gitignore: github:hercules-ci/gitignore.nix/637db329424fd7e46cf4185293b9cc8c88c95394
│ Last modified: 2024-02-28 03:28:52
│ └───nixpkgs follows input 'openapi3-code-generator/pre-commit-hooks/nixpkgs'
└───nixpkgs: github:NixOS/nixpkgs/a04d33c0c3f1a59a2c1cb0c6e34cd24500e5a1dc
Last modified: 2024-11-05 02:08:39
❯ nix build -v
fetching path input 'path:/home/turion/haskell/openapi-bug'
building '/nix/store/qy1879sc14dgazjwhm4h5h74zdhygphw-openapi-bug-src.drv'...
building '/nix/store/fmksk95291nx5agb032dh5d7c7pzis1j-cabal2nix-openapi-bug.drv'...
this derivation will be built:
/nix/store/13jhh23j96plrr2q3h0lkm88s19axv8w-openapi-bug-0.1.0.0.drv
building '/nix/store/13jhh23j96plrr2q3h0lkm88s19axv8w-openapi-bug-0.1.0.0.drv'...
error: builder for '/nix/store/13jhh23j96plrr2q3h0lkm88s19axv8w-openapi-bug-0.1.0.0.drv' failed with exit code 1;
last 25 log lines:
> [5 of 9] Compiling OpenAPI.Types.Someenum[boot] ( src/OpenAPI/Types/Someenum.hs-boot, dist/build/OpenAPI/Types/Someenum.o-boot, dist/build/OpenAPI/Types/Someenum.dyn_o-boot )
> [6 of 9] Compiling OpenAPI.Types.Someenum ( src/OpenAPI/Types/Someenum.hs, dist/build/OpenAPI/Types/Someenum.o, dist/build/OpenAPI/Types/Someenum.dyn_o )
> src/OpenAPI/Types/Someenum.hs:43:13: error: [8;;https://errors.haskell.org/messages/GHC-76037GHC-760378;;]
> Not in scope: type constructor or class ‘GHC.Internal.Show.Show’
> NB: no module named ‘GHC.Internal.Show’ is imported.
> |
> 43 | deriving (GHC.Internal.Show.Show, GHC.Classes.Eq)
> | ^^^^^^^^^^^^^^^^^^^^^^
>
> src/OpenAPI/Types/Someenum.hs:49:28: error: [8;;https://errors.haskell.org/messages/GHC-76037GHC-760378;;]
> Not in scope: ‘GHC.Internal.Base.pure’
> NB: no module named ‘GHC.Internal.Base’ is imported.
> |
> 49 | where {parseJSON val = GHC.Internal.Base.pure (if | val GHC.Classes.== "variant" -> SomeenumEnumVariant
> | ^^^^^^^^^^^^^^^^^^^^^^
>
> src/OpenAPI/Types/Someenum.hs:50:57: error: [8;;https://errors.haskell.org/messages/GHC-76037GHC-760378;;]
> Not in scope: ‘GHC.Internal.Base.otherwise’
> NB: no module named ‘GHC.Internal.Base’ is imported.
> Suggested fix:
> Perhaps use ‘GHC.Integer.Type.otherwise’ (imported from Prelude)
> |
> 50 | | GHC.Internal.Base.otherwise -> SomeenumOther val)}
> | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
For full logs, run 'nix log /nix/store/13jhh23j96plrr2q3h0lkm88s19axv8w-openapi-bug-0.1.0.0.drv'.
I'm pretty sure this is due to some change in more recent GHCs and/or more recent nixpkgs. In another project I have these pins:
Inputs:
├───flake-utils: github:numtide/flake-utils/11707dc2f618dd54ca8739b309ec4fc024de578b
│ Last modified: 2024-11-13 22:27:16
│ └───systems: github:nix-systems/default/da67096a3b9bf56a91d16901293e51ba5b49a27e
│ Last modified: 2023-04-09 10:27:08
├───nixpkgs: github:NixOS/nixpkgs/78e2cd1a1590f8c70b329cbc7d13bb2ab5b5a16c
│ Last modified: 2025-04-21 07:57:54
└───openapi3-code-generator: github:Haskell-OpenAPI-Code-Generator/Haskell-OpenAPI-Client-Code-Generator/665374f465f214ffa766b5a43c6a6b8b921e4673
Last modified: 2025-04-14 13:10:16
├───autodocodec: github:NorfairKing/autodocodec/7439601de128dadf562430f4216cbdb28580ed20
│ Last modified: 2025-02-14 20:54:07
├───fast-myers-diff: github:NorfairKing/fast-myers-diff/4a5c31884b8fc399085bffacd15d6cb5624b3177
│ Last modified: 2025-01-15 14:44:12
├───flake-utils: github:numtide/flake-utils/11707dc2f618dd54ca8739b309ec4fc024de578b
│ Last modified: 2024-11-13 22:27:16
│ └───systems: github:nix-systems/default/da67096a3b9bf56a91d16901293e51ba5b49a27e
│ Last modified: 2023-04-09 10:27:08
├───nixpkgs: github:NixOS/nixpkgs/26d499fc9f1d567283d5d56fcf367edd815dba1d
│ Last modified: 2025-04-12 08:55:57
├───pre-commit-hooks: github:cachix/pre-commit-hooks.nix/dcf5072734cb576d2b0c59b2ac44f5050b5eac82
│ Last modified: 2025-03-22 14:26:04
│ ├───flake-compat: github:edolstra/flake-compat/0f9255e01c2351cc7d116c072cb317785dd33b33
│ │ Last modified: 2023-10-04 15:37:54
│ ├───gitignore: github:hercules-ci/gitignore.nix/637db329424fd7e46cf4185293b9cc8c88c95394
│ │ Last modified: 2024-02-28 03:28:52
│ │ └───nixpkgs follows input 'openapi3-code-generator/pre-commit-hooks/nixpkgs'
│ └───nixpkgs: github:NixOS/nixpkgs/a04d33c0c3f1a59a2c1cb0c6e34cd24500e5a1dc
│ Last modified: 2024-11-05 02:08:39
├───safe-coloured-text: github:NorfairKing/safe-coloured-text/9ed65a40b3b2fade447c9d5fcb941d58f6367308
│ Last modified: 2024-10-13 01:01:46
├───sydtest: github:NorfairKing/sydtest/0aad7d9c41a53f5d46694c87dcacc51f6c6063d5
│ Last modified: 2025-03-20 18:57:10
└───validity: github:NorfairKing/validity/512aea6e0a112f5df09cc0b08f7fceffb122abc6
Last modified: 2024-10-13 00:32:57
And there I'm not suffering from the bug.
Thank you for the reproducer @turion ! I agree that it looks like the nixpkgs/GHC version is the reason. I've included the new imports as alias (that is how we dealt with this in the past as well) and opened a PR here: https://github.com/Haskell-OpenAPI-Code-Generator/Haskell-OpenAPI-Client-Code-Generator/pull/124 The reproducer was able to build for me with this branch, could you check if it works for you as well?
Yes, I can verify that the PR solves the problem! Thanks a lot :)
Closed by #124