@@ -161,19 +161,27 @@ packages2nix args pkgs =
161
161
return (fromString pkg, fromString pkg $= mkPath False nix)
162
162
(DVCS (Git url rev) _ subdirs) ->
163
163
do hits <- forM subdirs $ \ subdir -> liftIO $ cacheHits (argCacheFile args) url rev subdir
164
+ let generateBindings =
165
+ fetch (cabalFromPath url rev subdirs)
166
+ (Source url rev UnknownHash ) >>= \ case
167
+ (Just (DerivationSource {.. }, genBindings)) -> genBindings derivHash
168
+ _ -> return []
164
169
if any null hits
165
170
then
166
171
-- If any of the subdirs were missing we need to fetch the files and
167
172
-- generate the bindings.
168
- fetch (cabalFromPath url rev subdirs)
169
- (Source url rev UnknownHash ) >>= \ case
170
- (Just (DerivationSource {.. }, genBindings)) -> genBindings derivHash
171
- _ -> return []
172
- else
173
- -- If the subdirs are all in the cache then the bindings should already be
174
- -- generated too.
175
- forM (concat hits) $ \ ( pkg, nix ) ->
176
- return (fromString pkg, fromString pkg $= mkPath False nix)
173
+ generateBindings
174
+ else do
175
+ let allHits = concat hits
176
+ (and <$> forM allHits (\ ( _, nix ) -> doesFileExist (argOutputDir args </> nix))) >>= \ case
177
+ False ->
178
+ -- One or more of the generated binding files are missing
179
+ generateBindings
180
+ True ->
181
+ -- If the subdirs are all in the cache then the bindings should already be
182
+ -- generated too.
183
+ forM allHits $ \ ( pkg, nix ) ->
184
+ return (fromString pkg, fromString pkg $= mkPath False nix)
177
185
_ -> return []
178
186
where relPath = shortRelativePath (argOutputDir args) (dropFileName (argStackYaml args))
179
187
cabalFromPath
@@ -205,7 +213,10 @@ packages2nix args pkgs =
205
213
createDirectoryIfMissing True (takeDirectory nixFile)
206
214
writeDoc nixFile =<<
207
215
prettyNix <$> cabal2nix True (argDetailLevel args) src cabalFile
208
- appendCache (argCacheFile args) url rev subdir sha256 pkg nix
216
+ -- Only update the cache if there is not already a record
217
+ cacheHits (argCacheFile args) url rev subdir >>= \ case
218
+ [hit] | hit == (pkg, nix) -> return ()
219
+ _ -> appendCache (argCacheFile args) url rev subdir sha256 pkg nix
209
220
return (fromString pkg, fromString pkg $= mkPath False nix)
210
221
211
222
defaultNixContents :: String
0 commit comments