@@ -70,13 +70,19 @@ self: super: {
70
70
{ pkg-def # Base package set. Either from stackage (via stack-to-nix) or from a cabal projects plan file (via plan-to-nix)
71
71
, pkg-def-extras ? [ ] # Additional packages to augment the Base package set `pkg-def` with.
72
72
, modules ? [ ]
73
+ , extra-hackages ? [ ] # Extra Hackage repositories to use besides main one.
73
74
} @args :
74
75
75
- import ../package-set.nix ( args // {
76
+ let
77
+ hackageAll = builtins . foldl' ( base : extra : base // extra ) hackage extra-hackages ;
78
+ in
79
+
80
+ import ../package-set.nix {
81
+ inherit ( args ) pkg-def pkg-def-extras ;
76
82
modules = defaultModules ++ modules ;
77
83
pkgs = self ;
78
- inherit hackage pkg-def ;
79
- } ) ;
84
+ hackage = hackageAll ;
85
+ } ;
80
86
81
87
# Some boot packages (libiserv) are in lts, but not in hackage,
82
88
# so we should not try to get it from hackage based on the stackage
@@ -128,6 +134,7 @@ self: super: {
128
134
{ plan-pkgs # Path to the output of plan-to-nix
129
135
, pkg-def-extras ? [ ]
130
136
, modules ? [ ]
137
+ , extra-hackages ? [ ]
131
138
} @args :
132
139
133
140
let
@@ -146,6 +153,7 @@ self: super: {
146
153
modules = [ { doExactConfig = true ; } patchesModule ]
147
154
++ modules
148
155
++ plan-pkgs . modules or [ ] ;
156
+ inherit extra-hackages ;
149
157
} ;
150
158
151
159
# Package sets for all stackage snapshots.
@@ -169,33 +177,56 @@ self: super: {
169
177
nix-tools = self . buildPackages . haskell-nix . nix-tools-cross-compiled ;
170
178
# TODO perhaps there is a cleaner way to get a suitable nix-tools.
171
179
172
- # Produce a fixed output derivation from a moving target (hackage index tarball)
180
+ # Produce a fixed output derivation from a moving target (hackage index tarball)
181
+ # Takes desired index-state and sha256 and produces a set { name, index }, where
182
+ # index points to "01-index.tar.gz" file downloaded from hackage.haskell.org.
173
183
hackageTarball = { index-state , sha256 , nix-tools ? self . haskell-nix . nix-tools , ... } :
174
184
assert sha256 != null ;
175
- self . fetchurl {
176
- name = "01-index.tar.gz-at-${ builtins . replaceStrings [ ":" ] [ "" ] index-state } " ;
185
+ let at = builtins . replaceStrings [ ":" ] [ "" ] index-state ; in
186
+ { name = "hackage.haskell.org-at-${ at } " ;
187
+ index = self . fetchurl {
188
+ name = "01-index.tar.gz-at-${ at } " ;
177
189
url = "https://hackage.haskell.org/01-index.tar.gz" ;
178
190
downloadToTemp = true ;
179
191
postFetch = "${ nix-tools } /bin/truncate-index -o $out -i $downloadedFile -s ${ index-state } " ;
180
192
181
193
outputHashAlgo = "sha256" ;
182
194
outputHash = sha256 ;
195
+ } ;
183
196
} ;
184
197
185
- mkLocalHackageRepo = import ../mk-local-hackage-repo { inherit hackageTarball ; pkgs = self ; } ;
198
+ # Creates Cabal local repository from { name, index } set.
199
+ mkLocalHackageRepo = import ../mk-local-hackage-repo self ;
186
200
187
- dotCabal = { index-state , sha256 , cabal-install , ... } @args :
201
+ dotCabal = { index-state , sha256 , cabal-install , extra-hackage-tarballs ? [ ] , ... } @args :
202
+ let
203
+ allTarballs = [ ( hackageTarball args ) ] ++ extra-hackage-tarballs ;
204
+ in
188
205
self . runCommand "dot-cabal-at-${ builtins . replaceStrings [ ":" ] [ "" ] index-state } " { nativeBuildInputs = [ cabal-install ] ; } ''
189
206
mkdir -p $out/.cabal
190
207
cat <<EOF > $out/.cabal/config
191
- repository cached
192
- url: file:${ mkLocalHackageRepo args }
193
- secure: True
194
- root-keys:
195
- key-threshold: 0
208
+ ${ self . lib . concatStrings (
209
+ map ( tarball :
210
+ ''
211
+ repository ${ tarball . name }
212
+ url: file:${ mkLocalHackageRepo tarball }
213
+ secure: True
214
+ root-keys:
215
+ key-threshold: 0
216
+
217
+ '' ) allTarballs
218
+ ) }
196
219
EOF
197
- mkdir -p $out/.cabal/packages/cached
198
- HOME=$out cabal new-update cached
220
+
221
+ # All repositories must be mkdir'ed before calling new-update on any repo,
222
+ # otherwise it fails.
223
+ ${ self . lib . concatStrings ( map ( { name , ... } : ''
224
+ mkdir -p $out/.cabal/packages/${ name }
225
+ '' ) allTarballs ) }
226
+
227
+ ${ self . lib . concatStrings ( map ( { name , ... } : ''
228
+ HOME=$out cabal new-update ${ name }
229
+ '' ) allTarballs ) }
199
230
'' ;
200
231
201
232
checkMaterialization = false ; # This is the default. Use an overlay to set it to true and test all the materialized files
@@ -419,6 +450,7 @@ self: super: {
419
450
pkg-def-extras = args . pkg-def-extras or [ ] ;
420
451
modules = ( args . modules or [ ] )
421
452
++ self . lib . optional ( args ? ghc ) { ghc . package = args . ghc ; } ;
453
+ extra-hackages = args . extra-hackages or [ ] ;
422
454
} ;
423
455
in { inherit ( pkg-set . config ) hsPkgs ; plan-nix = plan . nix ; } ;
424
456
0 commit comments