3
0
Fork 0
forked from mirrors/nixpkgs

Merge pull request #36393 from ElvishJerricco/haskell-shell-for

Haskell: Added haskellPackages.shellFor
This commit is contained in:
Peter Simons 2018-03-07 12:45:06 +01:00 committed by GitHub
commit df6e6d91a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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 <nixpkgs> {};
# 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;