@@ -1,17 +1,33 @@
1−{ lib, stdenv, glibcLocales, ghcForComponent, makeConfigFiles, hsPkgs }:
1+{ lib, stdenv, glibcLocales, pkgconfig, ghcForComponent, makeConfigFiles, hsPkgs }:
3{ packages, withHoogle ? true, ... } @ args:
3{ packages, withHoogle ? true, ... } @ args:
6 selected = packages hsPkgs;
6 selected = packages hsPkgs;
7+ selectedConfigs = map (p: p.components.all.config) selected;
7 name = if lib.length selected == 1
9 name = if lib.length selected == 1
8 then "ghc-shell-for-${(lib.head selected).name}"
10 then "ghc-shell-for-${(lib.head selected).name}"
9 else "ghc-shell-for-packages";
11 else "ghc-shell-for-packages";
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);
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;
25+ # Set up a "dummy" component to use with ghcForComponent.
10 configFiles = makeConfigFiles {
26 configFiles = makeConfigFiles {
11 fullName = args.name or name;
27 fullName = args.name or name;
12 identifier.name = name;
28 identifier.name = name;
13 component = {
29 component = {
14− depends = selected;
30+ depends = packageInputs;
15 libs = [];
31 libs = [];
16 frameworks = [];
32 frameworks = [];
17 doExactConfig = false;
33 doExactConfig = false;
@@ -22,10 +38,6 @@ let
22 inherit configFiles;
38 inherit configFiles;
24 mkDrvArgs = builtins.removeAttrs args ["packages" "withHoogle"];
40 mkDrvArgs = builtins.removeAttrs args ["packages" "withHoogle"];
26− # fixme: check if systemInputs and nativeBuildInputs are necessary
28− nativeBuildInputs = [];
30 stdenv.mkDerivation (mkDrvArgs // {
42 stdenv.mkDerivation (mkDrvArgs // {
31 name = mkDrvArgs.name or name;
43 name = mkDrvArgs.name or name;