on iko/ghcjs-patch-master help sign in
Avoid duplicated packages in ghc-pkg list (#1530)
54b86efTeo Camarasu
builder/hspkg-builder.nix+22−25
@@ -39,37 +39,28 @@ let
39
39
40 defaultSetupSrc = if stdenv.hostPlatform.isGhcjs then ./Setup.ghcjs.hs else ./Setup.hs;
40 defaultSetupSrc = if stdenv.hostPlatform.isGhcjs then ./Setup.ghcjs.hs else ./Setup.hs;
41
41
42− # Get the Cabal lib used to build `cabal-install`.
42+ # This is the `Cabal` library that was built for `cabal-install` to use.
43− # To avoid infinite recursion we have to leave this out for packages
43+ # It makes sense to use this version (when possible) because it will match the behavior of
44− # needed to build `cabal-install`.
44+ # building with `cabal-install` (including fixes that may not be in the
45− # We always do this for ghcjs as the patched version of Cabal is needed.
45+ # version of Cabal bundled with GHC).
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;
46+ cabalFromCabalInstall = buildPackages.haskell-nix.cabal-install-unchecked.${compiler-nix-name}.project.hsPkgs.Cabal.components.library;
55
47
56− # This logic is needed so that we don't get duplicate packages if we
48+ # Check there is no chance we are building `cabalFromCabalInstall`. Using `cabalFromCabalInstall`
57− # add a custom Cabal package to the dependencies. That way custom
49+ # to build itseld would cause infinite recursion.
58− # setups won't complain about e.g. binary from the Cabal dependencies
50+ useCabalFromCabalInstall =
59− # and binary from the global package-db.
51+ # `cabalFromCabalInstall` is not cross compiled
60− nonReinstallablePkgs = if (
61− stdenv.hostPlatform.isGhcjs || (
52+ stdenv.buildPlatform != stdenv.hostPlatform
53+ ||
54+ # These are the dependencies of `Cabal`
62 !builtins.elem package.identifier.name
55 !builtins.elem package.identifier.name
63 ["nix-tools" "alex" "happy" "hscolour" "Cabal" "bytestring" "aeson" "time"
56 ["nix-tools" "alex" "happy" "hscolour" "Cabal" "bytestring" "aeson" "time"
64 "filepath" "base-compat-batteries" "base-compat" "unix" "directory" "transformers"
57 "filepath" "base-compat-batteries" "base-compat" "unix" "directory" "transformers"
65− "containers" "binary" "mtl" "text" "process" "parsec"]
58+ "containers" "binary" "mtl" "text" "process" "parsec"];
66− )
67− ) then [] else null;
68
59
69 defaultSetup = setup-builder ({
60 defaultSetup = setup-builder ({
70 name = "${ghc.targetPrefix}default-Setup";
61 name = "${ghc.targetPrefix}default-Setup";
71 component = {
62 component = {
72− depends = config.setup-depends ++ cabalLibDepends;
63+ depends = config.setup-depends ++ lib.optional useCabalFromCabalInstall cabalFromCabalInstall;
73 libs = [];
64 libs = [];
74 frameworks = [];
65 frameworks = [];
75 doExactConfig = false;
66 doExactConfig = false;
@@ -103,7 +94,13 @@ let
103 cat ${defaultSetupSrc} > $out/Setup.hs
94 cat ${defaultSetupSrc} > $out/Setup.hs
104 '';
95 '';
105 inherit defaultSetupSrc;
96 inherit defaultSetupSrc;
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.
106− } // (if nonReinstallablePkgs == null then {} else { inherit nonReinstallablePkgs; }));
102+ nonReinstallablePkgs = [];
103+ });
107
104
108 # buildPackages.runCommand "default-Setup" { nativeBuildInputs = [(ghc.passthru.buildGHC or ghc)]; } ''
105 # buildPackages.runCommand "default-Setup" { nativeBuildInputs = [(ghc.passthru.buildGHC or ghc)]; } ''
109 # cat ${defaultSetupSrc} > Setup.hs
106 # cat ${defaultSetupSrc} > Setup.hs
@@ -134,7 +131,7 @@ in rec {
134 checks = pkgs.recurseIntoAttrs (builtins.mapAttrs
131 checks = pkgs.recurseIntoAttrs (builtins.mapAttrs
135 (_: d: haskellLib.check d)
132 (_: d: haskellLib.check d)
136 (lib.filterAttrs (_: d: d.config.doCheck) components.tests));
133 (lib.filterAttrs (_: d: d.config.doCheck) components.tests));
137− inherit (package) identifier detailLevel isLocal isProject;
134+ inherit (package) identifier detailLevel isLocal isProject buildType;
138 inherit setup cabalFile;
135 inherit setup cabalFile;
139 isHaskell = true;
136 isHaskell = true;
140 inherit src;
137 inherit src;
builder/shell-for.nix+5−2
@@ -71,9 +71,12 @@ let
71 removeSelectedInputs =
71 removeSelectedInputs =
72 lib.filter (input: !(isSelectedComponent input));
72 lib.filter (input: !(isSelectedComponent input));
73
73
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.
75 selectedConfigs = map (c: c.config) selectedComponents
77 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));
77
80
78 name = if lib.length selectedPackages == 1
81 name = if lib.length selectedPackages == 1
79 then "ghc-shell-for-${(lib.head selectedPackages).identifier.name}"
82 then "ghc-shell-for-${(lib.head selectedPackages).identifier.name}"