Files
haskell.nix/builder/setup-builder.nix
Hamish Mackenzie 6c7f9d0042 Use cabal 3.8 (#1641)
A bug was fixed in cabal 3.8 (https://github.com/haskell/cabal/issues/6771) that haskell.nix relied on for `pkg-config` in support.  To work around this we added a dummy `pkg-config` that `cabal configure` now uses when haskell.nix runs it `cabal configure` internally.  That returns version information for all the `pkg-config` packages in `lib/pkgconfig-nixpkgs-map.nix`.  This mapping has also been expanded based on the results of searching nixpkgs for `*.pc` files.

This update also includes workarounds for:

https://github.com/haskell/cabal/issues/8352
https://github.com/haskell/cabal/issues/8370
https://github.com/haskell/cabal/issues/8455
2022-09-13 12:00:04 +12:00

105 lines
3.6 KiB
Nix

{ pkgs, stdenv, lib, buildPackages, haskellLib, ghc, nonReinstallablePkgs, hsPkgs, makeSetupConfigFiles }@defaults:
let self =
{ component, package, name, src, enableDWARF ? false, flags ? {}, revision ? null, patches ? [], defaultSetupSrc
, preUnpack ? component.preUnpack, postUnpack ? component.postUnpack
, prePatch ? null, postPatch ? null
, preBuild ? component.preBuild , postBuild ? component.postBuild
, preInstall ? component.preInstall , postInstall ? component.postInstall
, cleanSrc ? haskellLib.cleanCabalComponent package component "setup" src
, nonReinstallablePkgs ? defaults.nonReinstallablePkgs
, smallAddressSpace ? false
}@drvArgs:
let
ghc = (if enableDWARF then (x: x.dwarf) else (x: x)) (
(if smallAddressSpace then (x: x.smallAddressSpace) else (x: x)) defaults.ghc);
cleanSrc' = haskellLib.rootAndSubDir cleanSrc;
fullName = "${name}-setup";
includeGhcPackage = lib.any (p: p.identifier.name == "ghc") component.depends;
configFiles = makeSetupConfigFiles {
inherit (package) identifier;
inherit fullName flags component enableDWARF nonReinstallablePkgs;
};
hooks = haskellLib.optionalHooks {
inherit
preUnpack postUnpack
prePatch postPatch
preBuild postBuild
preInstall postInstall
;
};
executableToolDepends =
(lib.concatMap (c: if c.isHaskell or false
then builtins.attrValues (c.components.exes or {})
else [c]) component.build-tools) ++
lib.optional (component.pkgconfig != []) buildPackages.cabalPkgConfigWrapper;
drv =
stdenv.mkDerivation ({
name = "${ghc.targetPrefix}${fullName}";
src = cleanSrc'.root;
buildInputs = component.libs
++ component.frameworks
++ builtins.concatLists component.pkgconfig;
nativeBuildInputs = [ghc] ++ executableToolDepends;
passthru = {
inherit (package) identifier;
config = component;
srcSubDir = cleanSrc'.subDir;
srcSubDirPath = cleanSrc'.root + cleanSrc'.subDir;
cleanSrc = cleanSrc';
inherit configFiles;
dwarf = self (drvArgs // { enableDWARF = true; });
smallAddressSpace = self (drvArgs // { smallAddressSpace = true; });
};
meta = {
homepage = package.homepage or "";
description = package.synopsis or "";
license = haskellLib.cabalToNixpkgsLicense package.license;
platforms = if component.platforms == null then lib.platforms.all else component.platforms;
};
phases = ["unpackPhase" "patchPhase" "buildPhase" "installPhase"];
buildPhase = ''
runHook preBuild
if [[ ! -f ./Setup.hs && ! -f ./Setup.lhs ]]; then
cat ${defaultSetupSrc} > Setup.hs
fi
for f in Setup.hs Setup.lhs; do
if [ -f $f ]; then
echo Compiling package $f
ghc $f -threaded ${if includeGhcPackage then "-package ghc " else ""
}-package-db ${configFiles}/${configFiles.packageCfgDir} --make -o ./Setup
fi
done
[ -f ./Setup ] || (echo Failed to build Setup && exit 1)
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out/bin
install ./Setup $out/bin/Setup
runHook postInstall
'';
}
// (lib.optionalAttrs (cleanSrc'.subDir != "") {
prePatch =
# If the package is in a sub directory `cd` there first
''
cd ${lib.removePrefix "/" cleanSrc'.subDir}
'';
})
// (lib.optionalAttrs (patches != []) { patches = map (p: if builtins.isFunction p then p { inherit (package.identifier) version; inherit revision; } else p) patches; })
// hooks
);
in drv; in self