@@ -340,11 +340,24 @@ let
340340 fi
341341 cp -r ${maybeCleanedSource}/* .
342342 chmod +w -R .
343− # warning: this may not generate the proper cabal file.
344− # hpack allows globbing, and turns that into module lists
345− # without the source available (we cleaneSourceWith'd it),
346− # this may not produce the right result.
347− find . -name package.yaml -exec hpack "{}" \;
343+ # Decide what to do for each `package.yaml` file.
344+ for hpackFile in $(find . -name package.yaml); do (
345+ # Look to see if a `.cabal` file exists
346+ shopt -u nullglob
347+ for cabalFile in $(dirname $hpackFile)/*.cabal; do
348+ if [ -e "$cabalFile" ]; then
349+ echo Ignoring $hpackFile as $cabalFile exists
350+ else
351+ # warning: this may not generate the proper cabal file.
352+ # hpack allows globbing, and turns that into module lists
353+ # without the source available (we cleaneSourceWith'd it),
354+ # this may not produce the right result.
355+ echo No .cabal file found, running hpack on $hpackFile
356+ hpack $hpackFile
357+ fi
358+ done
359+ )
360+ done
348361 ${pkgs.lib.optionalString (subDir != "") "cd ${subDir}"}
349362 ${fixedProject.makeFixedProjectFile}
350363 ${pkgs.lib.optionalString (cabalProjectFreeze != null) ''