From 9adb4d25e6a20ea3b9ae54df1cb9086c676b7d4c Mon Sep 17 00:00:00 2001 From: Will Fancher Date: Tue, 6 Mar 2018 15:37:05 -0500 Subject: Haskell: Added haskellPackages.shellFor --- .../haskell-modules/make-package-set.nix | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/pkgs/development/haskell-modules/make-package-set.nix b/pkgs/development/haskell-modules/make-package-set.nix index 2a96c66dced5..c793c0e70860 100644 --- a/pkgs/development/haskell-modules/make-package-set.nix +++ b/pkgs/development/haskell-modules/make-package-set.nix @@ -188,6 +188,52 @@ in package-set { inherit pkgs stdenv callPackage; } self // { }; in withPackages (packages ++ [ hoogle ]); + # Returns a derivation whose environment contains a GHC with only + # the dependencies of packages listed in `packages`, not the + # packages themselves. Using nix-shell on this derivation will + # give you an environment suitable for developing the listed + # packages with an incremental tool like cabal-install. + # + # # default.nix + # with import {}; + # haskellPackages.extend (haskell.lib.packageSourceOverrides { + # frontend = ./frontend; + # backend = ./backend; + # common = ./common; + # }) + # + # # shell.nix + # (import ./.).shellFor { + # packages = p: [p.frontend p.backend p.common]; + # withHoogle = true; + # } + # + # -- cabal.project + # packages: + # frontend/ + # backend/ + # common/ + # + # bash$ nix-shell --run "cabal new-build all" + shellFor = { packages, withHoogle ? false, ... } @ args: + let + selected = packages self; + packageInputs = builtins.map (p: p.override { mkDerivation = haskellLib.extractBuildInputs p.compiler; }) selected; + haskellInputs = + builtins.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; + mkDrvArgs = builtins.removeAttrs args ["packages" "withHoogle"]; + in pkgs.stdenv.mkDerivation (mkDrvArgs // { + name = "ghc-shell-for-packages"; + nativeBuildInputs = [(withPackages (_: haskellInputs))] ++ mkDrvArgs.nativeBuildInputs or []; + buildInputs = systemInputs ++ mkDrvArgs.buildInputs or []; + phases = ["installPhase"]; + installPhase = "echo $nativeBuildInputs $buildInputs > $out"; + }); + ghc = ghc // { withPackages = self.ghcWithPackages; withHoogle = self.ghcWithHoogle; -- cgit 1.4.1