on iko/ghcjs-patch-master help sign in
Avoid duplicated packages in ghc-pkg list (#1530)

Filter out the setup dependencies of `Simple` packages from the shell. Fixes #1518. Co-authored-by: Hamish Mackenzie <Hamish.K.Mackenzie@gmail.com>

commit54b86efe7c2f656a3d465b9b63242f81b611e4c0 authorTeo Camarasu <teo.camarasu@tracsis.com> dateThu 30 Jun 2022, 10:16 (4 years ago) parent6786f24
2 files changed+27−27
builder/hspkg-builder.nix+22−25 builder/shell-for.nix+5−2
builder/hspkg-builder.nix+22−25
@@ -39,37 +39,28 @@ let
3939
4040 defaultSetupSrc = if stdenv.hostPlatform.isGhcjs then ./Setup.ghcjs.hs else ./Setup.hs;
4141
42− # Get the Cabal lib used to build `cabal-install`.
43− # To avoid infinite recursion we have to leave this out for packages
44− # needed to build `cabal-install`.
45− # We always do this for ghcjs as the patched version of Cabal is needed.
46− cabalLibDepends = lib.optional (
47− stdenv.hostPlatform.isGhcjs || (
48− !builtins.elem package.identifier.name
49− ["nix-tools" "alex" "happy" "hscolour" "Cabal" "bytestring" "aeson" "time"
50− "filepath" "base-compat-batteries" "base-compat" "unix" "directory" "transformers"
51− "containers" "binary" "mtl" "text" "process" "parsec"]
52− )
53− )
54− buildPackages.haskell-nix.cabal-install-unchecked.${compiler-nix-name}.project.hsPkgs.Cabal.components.library;
42+ # This is the `Cabal` library that was built for `cabal-install` to use.
43+ # It makes sense to use this version (when possible) because it will match the behavior of
44+ # building with `cabal-install` (including fixes that may not be in the
45+ # version of Cabal bundled with GHC).
46+ cabalFromCabalInstall = buildPackages.haskell-nix.cabal-install-unchecked.${compiler-nix-name}.project.hsPkgs.Cabal.components.library;
5547
56− # This logic is needed so that we don't get duplicate packages if we
57− # add a custom Cabal package to the dependencies. That way custom
58− # setups won't complain about e.g. binary from the Cabal dependencies
59− # and binary from the global package-db.
60− nonReinstallablePkgs = if (
61− stdenv.hostPlatform.isGhcjs || (
48+ # Check there is no chance we are building `cabalFromCabalInstall`. Using `cabalFromCabalInstall`
49+ # to build itseld would cause infinite recursion.
50+ useCabalFromCabalInstall =
51+ # `cabalFromCabalInstall` is not cross compiled
52+ stdenv.buildPlatform != stdenv.hostPlatform
53+ ||
54+ # These are the dependencies of `Cabal`
6255 !builtins.elem package.identifier.name
6356 ["nix-tools" "alex" "happy" "hscolour" "Cabal" "bytestring" "aeson" "time"
6457 "filepath" "base-compat-batteries" "base-compat" "unix" "directory" "transformers"
65− "containers" "binary" "mtl" "text" "process" "parsec"]
66− )
67− ) then [] else null;
58+ "containers" "binary" "mtl" "text" "process" "parsec"];
6859
6960 defaultSetup = setup-builder ({
7061 name = "${ghc.targetPrefix}default-Setup";
7162 component = {
72− depends = config.setup-depends ++ cabalLibDepends;
63+ depends = config.setup-depends ++ lib.optional useCabalFromCabalInstall cabalFromCabalInstall;
7364 libs = [];
7465 frameworks = [];
7566 doExactConfig = false;
@@ -103,7 +94,13 @@ let
10394 cat ${defaultSetupSrc} > $out/Setup.hs
10495 '';
10596 inherit defaultSetupSrc;
106− } // (if nonReinstallablePkgs == null then {} else { inherit nonReinstallablePkgs; }));
97+ } // lib.optionalAttrs useCabalFromCabalInstall {
98+ # This is needed so that we don't get duplicate packages when we
99+ # add a custom Cabal package to the dependencies. That way custom
100+ # setups won't complain about e.g. binary from the Cabal dependencies
101+ # and binary from the global package-db.
102+ nonReinstallablePkgs = [];
103+ });
107104
108105 # buildPackages.runCommand "default-Setup" { nativeBuildInputs = [(ghc.passthru.buildGHC or ghc)]; } ''
109106 # cat ${defaultSetupSrc} > Setup.hs
@@ -134,7 +131,7 @@ in rec {
134131 checks = pkgs.recurseIntoAttrs (builtins.mapAttrs
135132 (_: d: haskellLib.check d)
136133 (lib.filterAttrs (_: d: d.config.doCheck) components.tests));
137− inherit (package) identifier detailLevel isLocal isProject;
134+ inherit (package) identifier detailLevel isLocal isProject buildType;
138135 inherit setup cabalFile;
139136 isHaskell = true;
140137 inherit src;
builder/shell-for.nix+5−2
@@ -71,9 +71,12 @@ let
7171 removeSelectedInputs =
7272 lib.filter (input: !(isSelectedComponent input));
7373
74− # The configs of all the selected components
74+ # The configs of all the selected components.
75+ # This excludes the `setup` dependencies of `Simple` packages, because
76+ # `cabal-install` does not build a `Setup` executable for `Simple` packages.
7577 selectedConfigs = map (c: c.config) selectedComponents
76− ++ lib.optionals packageSetupDeps (map (p: p.setup.config) selectedPackages);
78+ ++ lib.optionals packageSetupDeps (map (p: p.setup.config)
79+ (lib.filter (p: p.buildType != "Simple") selectedPackages));
7780
7881 name = if lib.length selectedPackages == 1
7982 then "ghc-shell-for-${(lib.head selectedPackages).identifier.name}"