@@ -325,31 +325,43 @@ let
325325 ${lib.optionalString (haskellLib.isLibrary componentId) ''
326326 $SETUP_HS register --gen-pkg-config=${name}.conf
327327 ${ghc.targetPrefix}ghc-pkg -v0 init $out/package.conf.d
328− if [ -d "${name}.conf" ]; then
329− for pkg in ${name}.conf/*; do
330− ${ghc.targetPrefix}ghc-pkg -v0 --package-db ${configFiles}/${configFiles.packageCfgDir} -f $out/package.conf.d register "$pkg"
331− done
332− elif [ -e "${name}.conf" ]; then
333− ${ghc.targetPrefix}ghc-pkg -v0 --package-db ${configFiles}/${configFiles.packageCfgDir} -f $out/package.conf.d register ${name}.conf
334− fi
328+ ${ghc.targetPrefix}ghc-pkg -v0 --package-db ${configFiles}/${configFiles.packageCfgDir} -f $out/package.conf.d register ${name}.conf
335329
336330 mkdir -p $out/exactDep
337331 touch $out/exactDep/configure-flags
338332 touch $out/exactDep/cabal.config
339333 touch $out/envDep
340334
341− if id=$(${target-pkg-and-db} field ${package.identifier.name} id --simple-output); then
342− echo "--dependency=${package.identifier.name}=$id" >> $out/exactDep/configure-flags
343− echo "package-id $id" >> $out/envDep
344− elif id=$(${target-pkg-and-db} field "z-${package.identifier.name}-z-*" id --simple-output); then
345− name=$(${target-pkg-and-db} field "z-${package.identifier.name}-z-*" name --simple-output)
346− # so we are dealing with a sublib. As we build sublibs separately, the above
347− # query should be safe.
348− echo "--dependency=''${name#z-${package.identifier.name}-z-}=$id" >> $out/exactDep/configure-flags
349− else
350− echo 'ERROR: ${package.identifier.name} id could not be found with ${target-pkg-and-db}'
351− exit 0
352− fi
335+ ${ # The main library in a package has the same name as the package
336+ if package.identifier.name == componentId.cname
337+ then ''
338+ if id=$(${target-pkg-and-db} field ${package.identifier.name} id --simple-output); then
339+ echo "--dependency=${package.identifier.name}=$id" >> $out/exactDep/configure-flags
340+ echo "package-id $id" >> $out/envDep
341+ else
342+ echo 'ERROR: ${package.identifier.name} id could not be found with ${target-pkg-and-db}'
343+ exit 0
344+ fi
345+ ''
346+ else
347+ # If the component name is not the package name this must be a sublib.
348+ # As we build sublibs separately, the following query should be safe.
349+ (''
350+ if id=$(${target-pkg-and-db} field "z-${package.identifier.name}-z-*" id --simple-output); then
351+ name=$(${target-pkg-and-db} field "z-${package.identifier.name}-z-*" name --simple-output)
352+ echo "--dependency=''${name#z-${package.identifier.name}-z-}=$id" >> $out/exactDep/configure-flags
353+ ''
354+ # Allow `package-name:sublib-name` to work in `build-depends`
355+ # by adding the same `--dependency` again, but with the package
356+ # name added.
357+ + ''
358+ echo "--dependency=${package.identifier.name}:''${name#z-${package.identifier.name}-z-}=$id" >> $out/exactDep/configure-flags
359+ else
360+ echo 'ERROR: ${package.identifier.name} id could not be found with ${target-pkg-and-db}'
361+ exit 0
362+ fi
363+ '')
364+ }
353365 if ver=$(${target-pkg-and-db} field ${package.identifier.name} version --simple-output); then
354366 echo "constraint: ${package.identifier.name} == $ver" >> $out/exactDep/cabal.config
355367 echo "constraint: ${package.identifier.name} installed" >> $out/exactDep/cabal.config
@@ -372,21 +384,23 @@ let
372384 '')
373385 # In case `setup copy` did not create this
374386 + (lib.optionalString enableSeparateDataOutput "mkdir -p $data")
375− + (lib.optionalString (stdenv.hostPlatform.isWindows && (haskellLib.mayHaveExecutable componentId)) ''
387+ + (lib.optionalString (stdenv.hostPlatform.isWindows && (haskellLib.mayHaveExecutable componentId)) (''
376388 echo "Symlink libffi and gmp .dlls ..."
377389 for p in ${lib.concatStringsSep " " [ libffi gmp ]}; do
378390 find "$p" -iname '*.dll' -exec ln -s {} $out/bin \;
379391 done
392+ ''
380393 # symlink all .dlls into the local directory.
381394 # we ask ghc-pkg for *all* dynamic-library-dirs and then iterate over the unique set
382395 # to symlink over dlls as needed.
396+ + ''
383397 echo "Symlink library dependencies..."
384398 for libdir in $(x86_64-pc-mingw32-ghc-pkg --package-db=$packageConfDir field "*" dynamic-library-dirs --simple-output|xargs|sed 's/ /\n/g'|sort -u); do
385399 if [ -d "$libdir" ]; then
386400 find "$libdir" -iname '*.dll' -exec ln -s {} $out/bin \;
387401 fi
388402 done
389− '')
403+ ''))
390404 + (lib.optionalString doCoverage ''
391405 mkdir -p $out/share
392406 cp -r dist/hpc $out/share