@@ -1,17 +1,33 @@
1−{ lib, stdenv, glibcLocales, ghcForComponent, makeConfigFiles, hsPkgs }:
1+{ lib, stdenv, glibcLocales, pkgconfig, ghcForComponent, makeConfigFiles, hsPkgs }:
22
33{ packages, withHoogle ? true, ... } @ args:
44
55let
66 selected = packages hsPkgs;
7+ selectedConfigs = map (p: p.components.all.config) selected;
8+
79 name = if lib.length selected == 1
810 then "ghc-shell-for-${(lib.head selected).name}"
911 else "ghc-shell-for-packages";
12+
13+ # If `packages = [ a b ]` and `a` depends on `b`, don't build `b`,
14+ # because cabal will end up ignoring that built version, assuming
15+ # new-style commands.
16+ packageInputs = lib.filter
17+ (input: lib.all (cfg: input.identifier != cfg.identifier) selected)
18+ (lib.concatMap (cfg: cfg.depends) selectedConfigs);
19+
20+ # Add the system libraries and build tools of the selected haskell
21+ # packages to the shell.
22+ systemInputs = lib.concatMap (p: p.components.all.buildInputs) selected;
23+ nativeBuildInputs = lib.concatMap (p: p.components.all.executableToolDepends) selected;
24+
25+ # Set up a "dummy" component to use with ghcForComponent.
1026 configFiles = makeConfigFiles {
1127 fullName = args.name or name;
1228 identifier.name = name;
1329 component = {
14− depends = selected;
30+ depends = packageInputs;
1531 libs = [];
1632 frameworks = [];
1733 doExactConfig = false;
@@ -22,10 +38,6 @@ let
2238 inherit configFiles;
2339 };
2440 mkDrvArgs = builtins.removeAttrs args ["packages" "withHoogle"];
25−
26− # fixme: check if systemInputs and nativeBuildInputs are necessary
27− systemInputs = [];
28− nativeBuildInputs = [];
2941in
3042 stdenv.mkDerivation (mkDrvArgs // {
3143 name = mkDrvArgs.name or name;