1
1
{ stdenv , lib , haskellLib , ghc , nonReinstallablePkgs , runCommand } :
2
2
3
+ with builtins ; with lib ;
3
4
let
4
5
flagsAndConfig = field : xs : lib . optionalString ( xs != [ ] ) ''
5
6
echo ${ lib . concatStringsSep " " ( map ( x : "--${ field } =${ x } " ) xs ) } >> $out/configure-flags
6
7
echo "${ field } : ${ lib . concatStringsSep " " xs } " >> $out/cabal.config
7
8
'' ;
8
9
9
- flatDepends = component :
10
+ ## packageHasLib :: Package -> Bool
11
+ packageHasLib = p : hasAttr "library" p . components ;
12
+ ## flatLibDepends :: Component -> [Package]
13
+ flatLibDepends =
14
+ component :
10
15
let
11
- makePairs = map ( p : rec { key = "${ val } " ; val = ( p . components . library or p ) ; } ) ;
16
+ makePairs = map ( p : rec { key = "${ val . name } " ; val = p . components . library ; } ) ;
12
17
closure = builtins . genericClosure {
13
- startSet = makePairs component . depends ;
18
+ startSet = makePairs ( filter packageHasLib component . depends ) ;
14
19
operator = { val , ...} : makePairs val . config . depends ;
15
20
} ;
16
21
in map ( { val , ...} : val ) closure ;
@@ -58,7 +63,7 @@ in { identifier, component, fullName, flags ? {} }:
58
63
59
64
${ lib . concatMapStringsSep "\n " ( p : ''
60
65
target-pkg --package-db ${ p } /package.conf.d dump | target-pkg --force --package-db $out/package.conf.d register -
61
- '' ) ( flatDepends component ) }
66
+ '' ) ( flatLibDepends component ) }
62
67
63
68
# Note: we pass `clear` first to ensure that we never consult the implicit global package db.
64
69
${ flagsAndConfig "package-db" [ "clear" "$out/package.conf.d" ] }
@@ -69,15 +74,17 @@ in { identifier, component, fullName, flags ? {} }:
69
74
cat > $out/ghc-environment <<EOF
70
75
package-db $out/package.conf.d
71
76
EOF
72
- ${ lib . concatMapStringsSep "\n " ( p : envDep "--package-db ${ p . components . library or p } /package.conf.d" p . identifier . name ) component . depends }
77
+ ${ lib . concatMapStringsSep "\n " ( p : envDep "--package-db ${ p . components . library } /package.conf.d" p . identifier . name )
78
+ ( filter packageHasLib component . depends ) }
73
79
${ lib . concatMapStringsSep "\n " ( envDep "" ) ( lib . remove "ghc" nonReinstallablePkgs ) }
74
80
75
81
'' + lib . optionalString component . doExactConfig ''
76
82
echo "--exact-configuration" >> $out/configure-flags
77
83
echo "allow-newer: ${ identifier . name } :*" >> $out/cabal.config
78
84
echo "allow-older: ${ identifier . name } :*" >> $out/cabal.config
79
85
80
- ${ lib . concatMapStringsSep "\n " ( p : exactDep "--package-db ${ p . components . library } /package.conf.d" p . identifier . name ) component . depends }
86
+ ${ lib . concatMapStringsSep "\n " ( p : exactDep "--package-db ${ p . components . library } /package.conf.d" p . identifier . name )
87
+ ( filter packageHasLib component . depends ) }
81
88
${ lib . concatMapStringsSep "\n " ( exactDep "" ) nonReinstallablePkgs }
82
89
83
90
''
0 commit comments