Skip to content

Shell for plus #130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions builder/make-config-files.nix
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
{ stdenv, lib, haskellLib, ghc, nonReinstallablePkgs, runCommand }:

with builtins; with lib;
let
flagsAndConfig = field: xs: lib.optionalString (xs != []) ''
echo ${lib.concatStringsSep " " (map (x: "--${field}=${x}") xs)} >> $out/configure-flags
echo "${field}: ${lib.concatStringsSep " " xs}" >> $out/cabal.config
'';

flatDepends = component:
## packageHasLib :: Package -> Bool
packageHasLib = p: hasAttr "library" p.components;
## flatLibDepends :: Component -> [Package]
flatLibDepends =
component:
let
makePairs = map (p: rec { key="${val}"; val=(p.components.library or p); });
makePairs = map (p: rec { key="${val.name}"; val=p.components.library; });
closure = builtins.genericClosure {
startSet = makePairs component.depends;
startSet = makePairs (filter packageHasLib component.depends);
operator = {val,...}: makePairs val.config.depends;
};
in map ({val,...}: val) closure;
Expand Down Expand Up @@ -58,7 +63,7 @@ in { identifier, component, fullName, flags ? {} }:

${lib.concatMapStringsSep "\n" (p: ''
target-pkg --package-db ${p}/package.conf.d dump | target-pkg --force --package-db $out/package.conf.d register -
'') (flatDepends component)}
'') (flatLibDepends component)}

# Note: we pass `clear` first to ensure that we never consult the implicit global package db.
${flagsAndConfig "package-db" ["clear" "$out/package.conf.d"]}
Expand All @@ -69,15 +74,17 @@ in { identifier, component, fullName, flags ? {} }:
cat > $out/ghc-environment <<EOF
package-db $out/package.conf.d
EOF
${lib.concatMapStringsSep "\n" (p: envDep "--package-db ${p.components.library or p}/package.conf.d" p.identifier.name) component.depends}
${lib.concatMapStringsSep "\n" (p: envDep "--package-db ${p.components.library}/package.conf.d" p.identifier.name)
(filter packageHasLib component.depends)}
${lib.concatMapStringsSep "\n" (envDep "") (lib.remove "ghc" nonReinstallablePkgs)}

'' + lib.optionalString component.doExactConfig ''
echo "--exact-configuration" >> $out/configure-flags
echo "allow-newer: ${identifier.name}:*" >> $out/cabal.config
echo "allow-older: ${identifier.name}:*" >> $out/cabal.config

${lib.concatMapStringsSep "\n" (p: exactDep "--package-db ${p.components.library}/package.conf.d" p.identifier.name) component.depends}
${lib.concatMapStringsSep "\n" (p: exactDep "--package-db ${p.components.library}/package.conf.d" p.identifier.name)
(filter packageHasLib component.depends)}
${lib.concatMapStringsSep "\n" (exactDep "") nonReinstallablePkgs}

''
Expand Down
4 changes: 2 additions & 2 deletions builder/shell-for.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ buildPackages, lib, stdenv, ghcForComponent, makeConfigFiles, hsPkgs }:

{ packages, withHoogle ? true } @ args:
{ packages, buildInputs ? [], withHoogle ? true } @ args:

let
selected = packages hsPkgs;
Expand Down Expand Up @@ -29,7 +29,7 @@ in
stdenv.mkDerivation (mkDrvArgs // {
name = mkDrvArgs.name or name;

buildInputs = systemInputs ++ mkDrvArgs.buildInputs or [];
buildInputs = buildInputs ++ systemInputs ++ mkDrvArgs.buildInputs or [];
nativeBuildInputs = [ ghcEnv ] ++ nativeBuildInputs ++ mkDrvArgs.nativeBuildInputs or [];
phases = ["installPhase"];
installPhase = "echo $nativeBuildInputs $buildInputs > $out";
Expand Down