summary refs log tree commit diff
path: root/pkgs/development/haskell-modules/make-package-set.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/development/haskell-modules/make-package-set.nix')
-rw-r--r--pkgs/development/haskell-modules/make-package-set.nix42
1 files changed, 34 insertions, 8 deletions
diff --git a/pkgs/development/haskell-modules/make-package-set.nix b/pkgs/development/haskell-modules/make-package-set.nix
index b6fe399058c3..ef2c33c10915 100644
--- a/pkgs/development/haskell-modules/make-package-set.nix
+++ b/pkgs/development/haskell-modules/make-package-set.nix
@@ -43,7 +43,7 @@ let
   mkDerivationImpl = pkgs.callPackage ./generic-builder.nix {
     inherit stdenv;
     nodejs = buildPackages.nodejs-slim;
-    inherit (self) buildHaskellPackages ghc;
+    inherit (self) buildHaskellPackages ghc shellFor;
     inherit (self.buildHaskellPackages) jailbreak-cabal;
     hscolour = overrideCabal self.buildHaskellPackages.hscolour (drv: {
       isLibrary = false;
@@ -259,20 +259,46 @@ in package-set { inherit pkgs stdenv callPackage; } self // {
     shellFor = { packages, withHoogle ? false, ... } @ args:
       let
         selected = packages self;
-        packageInputs = builtins.map getBuildInputs selected;
-        haskellInputs =
-          builtins.filter
-            (input: pkgs.lib.all (p: input.outPath != p.outPath) selected)
-            (pkgs.lib.concatMap (p: p.haskellBuildInputs) packageInputs);
+
+        packageInputs = map getBuildInputs selected;
+
+        name = if pkgs.lib.length selected == 1
+          then "ghc-shell-for-${(pkgs.lib.head selected).name}"
+          else "ghc-shell-for-packages";
+
+        # If `packages = [ a b ]` and `a` depends on `b`, don't build `b`,
+        # because cabal will end up ignoring that built version, assuming
+        # new-style commands.
+        haskellInputs = pkgs.lib.filter
+          (input: pkgs.lib.all (p: input.outPath != p.outPath) selected)
+          (pkgs.lib.concatMap (p: p.haskellBuildInputs) packageInputs);
         systemInputs = pkgs.lib.concatMap (p: p.systemBuildInputs) packageInputs;
+
         withPackages = if withHoogle then self.ghcWithHoogle else self.ghcWithPackages;
+        ghcEnv = withPackages (p: haskellInputs);
+        nativeBuildInputs = pkgs.lib.concatMap (p: p.nativeBuildInputs) selected;
+
+        ghcCommand' = if ghc.isGhcjs or false then "ghcjs" else "ghc";
+        ghcCommand = "${ghc.targetPrefix}${ghcCommand'}";
+        ghcCommandCaps= pkgs.lib.toUpper ghcCommand';
+
         mkDrvArgs = builtins.removeAttrs args ["packages" "withHoogle"];
       in pkgs.stdenv.mkDerivation (mkDrvArgs // {
-        name = "ghc-shell-for-packages";
-        nativeBuildInputs = [(withPackages (_: haskellInputs))] ++ mkDrvArgs.nativeBuildInputs or [];
+        name = mkDrvArgs.name or name;
+
         buildInputs = systemInputs ++ mkDrvArgs.buildInputs or [];
+        nativeBuildInputs = [ ghcEnv ] ++ nativeBuildInputs ++ mkDrvArgs.nativeBuildInputs or [];
         phases = ["installPhase"];
         installPhase = "echo $nativeBuildInputs $buildInputs > $out";
+        LANG = "en_US.UTF-8";
+        LOCALE_ARCHIVE = pkgs.lib.optionalString (stdenv.hostPlatform.libc == "glibc") "${buildPackages.glibcLocales}/lib/locale/locale-archive";
+        "NIX_${ghcCommandCaps}" = "${ghcEnv}/bin/${ghcCommand}";
+        "NIX_${ghcCommandCaps}PKG" = "${ghcEnv}/bin/${ghcCommand}-pkg";
+        # TODO: is this still valid?
+        "NIX_${ghcCommandCaps}_DOCDIR" = "${ghcEnv}/share/doc/ghc/html";
+        "NIX_${ghcCommandCaps}_LIBDIR" = if ghc.isHaLVM or false
+          then "${ghcEnv}/lib/HaLVM-${ghc.version}"
+          else "${ghcEnv}/lib/${ghcCommand}-${ghc.version}";
       });
 
     ghc = ghc // {