10
10
ghc = if enableDWARF then defaults . ghc . dwarf else defaults . ghc ;
11
11
12
12
flagsAndConfig = field : xs : lib . optionalString ( xs != [ ] ) ''
13
- echo ${ lib . concatStringsSep " " ( map ( x : "--${ field } =${ x } " ) xs ) } >> $out /configure-flags
14
- echo "${ field } : ${ lib . concatStringsSep " " xs } " >> $out /cabal.config
13
+ echo ${ lib . concatStringsSep " " ( map ( x : "--${ field } =${ x } " ) xs ) } >> $configFiles /configure-flags
14
+ echo "${ field } : ${ lib . concatStringsSep " " xs } " >> $configFiles /cabal.config
15
15
'' ;
16
16
17
17
target-pkg = "${ ghc . targetPrefix } ghc-pkg" ;
64
64
libDeps ;
65
65
in lib . concatStringsSep "\" \" " xs ;
66
66
libs = lib . concatMapStringsSep "\" \" " ( p : "${ p } " ) libDeps ;
67
- drv = runCommand "${ ghc . targetPrefix } ${ fullName } -config" {
68
- nativeBuildInputs = [ ghc ] ;
69
- passthru = {
70
- inherit ( ghc ) targetPrefix ;
71
- inherit ghcCommand ghcCommandCaps libDir packageCfgDir component ;
72
- # Use ''${pkgroot} relative paths so that we can relocate the package database
73
- # along with referenced packages and still have it work on systems with
74
- # or without nix installed.
75
- relocatableConfigFiles = runCommand "${ ghc . targetPrefix } ${ fullName } -relocatable-config" ''
76
- cp -r ${ drv } $out
77
- chmod -R +w $out
78
- sed -i 's|/nix/store/|'' ${pkgroot}/../../../|' $out/${ packageCfgDir } /*.conf
79
- ${ target-pkg } -v0 --package-db $out/${ packageCfgDir } recache
80
- '' ;
81
- } ;
82
- } ( ''
83
- mkdir -p $out
84
-
85
- ${ target-pkg } init $out/${ packageCfgDir }
67
+ script = ''
68
+ ${ target-pkg } init $configFiles/${ packageCfgDir }
86
69
87
70
${ lib . concatStringsSep "\n " ( lib . mapAttrsToList flagsAndConfig {
88
71
"extra-lib-dirs" = map ( p : "${ lib . getLib p } /lib" ) ( lib . flatten component . libs )
99
82
${ # Copy over the nonReinstallablePkgs from the global package db.
100
83
''
101
84
for p in ${ lib . concatStringsSep " " nonReinstallablePkgs' } ; do
102
- find $ghc/lib/${ ghc . name } /package.conf.d -name $p'*.conf' -exec cp -f {} $out /${ packageCfgDir } \;
85
+ find $ghc/lib/${ ghc . name } /package.conf.d -name $p'*.conf' -exec cp -f {} $configFiles /${ packageCfgDir } \;
103
86
done
104
87
'' }
105
88
106
89
for l in "${ cfgFiles } "; do
107
90
if [ -n "$l" ]; then
108
91
files=("$l/${ packageCfgDir } /"*.conf)
109
92
if (( '' ${#files[@]} )); then
110
- cp -f "'' ${files[@]}" $out /${ packageCfgDir }
93
+ cp -f "'' ${files[@]}" $configFiles /${ packageCfgDir }
111
94
else
112
95
echo "$l/${ packageCfgDir } didn't contain any *.conf files!"
113
96
exit 1
118
101
if [ -n "$l" ]; then
119
102
files=("$l/package.conf.d/"*.conf)
120
103
if (( '' ${#files[@]} )); then
121
- cp -f "'' ${files[@]}" $out /${ packageCfgDir }
104
+ cp -f "'' ${files[@]}" $configFiles /${ packageCfgDir }
122
105
else
123
106
echo "$l/package.conf.d didn't contain any *.conf files!"
124
107
exit 1
@@ -127,46 +110,46 @@ let
127
110
done
128
111
129
112
${ # Note: we pass `clear` first to ensure that we never consult the implicit global package db.
130
- flagsAndConfig "package-db" [ "clear" "$out /${ packageCfgDir } " ]
113
+ flagsAndConfig "package-db" [ "clear" "$configFiles /${ packageCfgDir } " ]
131
114
}
132
115
133
- echo ${ lib . concatStringsSep " " ( lib . mapAttrsToList ( fname : val : "--flags=${ lib . optionalString ( ! val ) "-" + fname } " ) flags ) } >> $out /configure-flags
116
+ echo ${ lib . concatStringsSep " " ( lib . mapAttrsToList ( fname : val : "--flags=${ lib . optionalString ( ! val ) "-" + fname } " ) flags ) } >> $configFiles /configure-flags
134
117
135
118
${ # Provide a cabal config without remote package repositories
136
119
''
137
- echo "write-ghc-environment-files: never" >> $out /cabal.config
120
+ echo "write-ghc-environment-files: never" >> $configFiles /cabal.config
138
121
'' }
139
122
140
123
${ # Provide a GHC environment file
141
124
''
142
- cat > $out /ghc-environment <<EOF
143
- package-db $out /${ packageCfgDir }
125
+ cat > $configFiles /ghc-environment <<EOF
126
+ package-db $configFiles /${ packageCfgDir }
144
127
EOF
145
128
'' }
146
129
147
130
${ lib . optionalString component . doExactConfig ''
148
- echo "--exact-configuration" >> $out /configure-flags
149
- echo "allow-newer: ${ identifier . name } :*" >> $out /cabal.config
150
- echo "allow-older: ${ identifier . name } :*" >> $out /cabal.config
131
+ echo "--exact-configuration" >> $configFiles /configure-flags
132
+ echo "allow-newer: ${ identifier . name } :*" >> $configFiles /cabal.config
133
+ echo "allow-older: ${ identifier . name } :*" >> $configFiles /cabal.config
151
134
'' }
152
135
153
136
for p in ${ lib . concatStringsSep " " libDeps } ; do
154
- cat $p/envDep >> $out /ghc-environment
137
+ cat $p/envDep >> $configFiles /ghc-environment
155
138
${ lib . optionalString component . doExactConfig ''
156
- cat $p/exactDep/configure-flags >> $out /configure-flags
157
- cat $p/exactDep/cabal.config >> $out /cabal.config
139
+ cat $p/exactDep/configure-flags >> $configFiles /configure-flags
140
+ cat $p/exactDep/cabal.config >> $configFiles /cabal.config
158
141
'' }
159
142
done
160
143
for p in ${ lib . concatStringsSep " " ( lib . remove "ghc" nonReinstallablePkgs' ) } ; do
161
144
if [ -e $ghc/envDeps/$p ]; then
162
- cat $ghc/envDeps/$p >> $out /ghc-environment
145
+ cat $ghc/envDeps/$p >> $configFiles /ghc-environment
163
146
fi
164
147
done
165
148
'' + lib . optionalString component . doExactConfig ''
166
149
for p in ${ lib . concatStringsSep " " nonReinstallablePkgs' } ; do
167
150
if [ -e $ghc/exactDeps/$p ]; then
168
- cat $ghc/exactDeps/$p/configure-flags >> $out /configure-flags
169
- cat $ghc/exactDeps/$p/cabal.config >> $out /cabal.config
151
+ cat $ghc/exactDeps/$p/configure-flags >> $configFiles /configure-flags
152
+ cat $ghc/exactDeps/$p/cabal.config >> $configFiles /cabal.config
170
153
fi
171
154
done
172
155
''
@@ -199,24 +182,43 @@ let
199
182
# Create a local directory with symlinks of the *.dylib (macOS shared
200
183
# libraries) from all the dependencies.
201
184
+ lib . optionalString stdenv . isDarwin ''
202
- local dynamicLinksDir="$out /lib/links"
185
+ local dynamicLinksDir="$configFiles /lib/links"
203
186
mkdir -p $dynamicLinksDir
204
187
# Enumerate dynamic-library-dirs with '' ${pkgroot} expanded.
205
188
local dirsToLink=$(
206
- for f in "$out /${ packageCfgDir } /"*.conf; do
189
+ for f in "$configFiles /${ packageCfgDir } /"*.conf; do
207
190
(cat $f; echo) | sed -En '/^ ./{H;$!d} ; x ; /^dynamic-library-dirs:/ {s/^dynamic-library-dirs:// ; s/ /\n/g ; s/\n\n*/\n/g; s/^\n//; p}'
208
191
done | sed 's|'' ${pkgroot}/../../../|/nix/store/|' | sort -u
209
192
)
210
193
for d in $dirsToLink; do
211
194
ln -f -s "$d/"*.{a,dylib,so} $dynamicLinksDir
212
195
done
213
196
# Edit the local package DB to reference the links directory.
214
- for f in "$out /${ packageCfgDir } /"*.conf; do
197
+ for f in "$configFiles /${ packageCfgDir } /"*.conf; do
215
198
chmod +w $f
216
199
echo >> $f
217
200
sed -i -E "/^ ./{H;$!d} ; x ; s,^dynamic-library-dirs:.*,dynamic-library-dirs: $dynamicLinksDir," $f
218
201
done
219
202
'' + ''
220
- ${ target-pkg } -v0 --package-db $out/${ packageCfgDir } recache
203
+ ${ target-pkg } -v0 --package-db $configFiles/${ packageCfgDir } recache
204
+ '' ;
205
+ drv = runCommand "${ ghc . targetPrefix } ${ fullName } -config" {
206
+ nativeBuildInputs = [ ghc ] ;
207
+ } ( ''
208
+ mkdir -p $out
209
+ configFiles=$out
210
+ ${ script }
221
211
'' ) ;
222
- in drv
212
+ in {
213
+ inherit ( ghc ) targetPrefix ;
214
+ inherit script drv ghcCommand ghcCommandCaps libDir packageCfgDir component ;
215
+ # Use ''${pkgroot} relative paths so that we can relocate the package database
216
+ # along with referenced packages and still have it work on systems with
217
+ # or without nix installed.
218
+ relocatableConfigFiles = runCommand "${ ghc . targetPrefix } ${ fullName } -relocatable-config" ''
219
+ cp -r ${ drv } $configFiles
220
+ chmod -R +w $configFiles
221
+ sed -i 's|/nix/store/|'' ${pkgroot}/../../../|' $configFiles/${ packageCfgDir } /*.conf
222
+ ${ target-pkg } -v0 --package-db $configFiles/${ packageCfgDir } recache
223
+ '' ;
224
+ }
0 commit comments