on e94de40 help sign in
haskell.nix/builder/setup-builder.nix
89 lines 3.1 kB history raw
1{ stdenv, lib, buildPackages, haskellLib, ghc, nonReinstallablePkgs, hsPkgs, makeSetupConfigFiles, pkgconfig }:
3{ component, package, name, src, flags ? {}, revision ? null, patches ? [], defaultSetupSrc
4, preUnpack ? component.preUnpack, postUnpack ? component.postUnpack
5, prePatch ? null, postPatch ? null
6, preBuild ? component.preBuild , postBuild ? component.postBuild
7, preInstall ? component.preInstall , postInstall ? component.postInstall
8, cleanSrc ? haskellLib.cleanCabalComponent package component src
9}:
11let
12 fullName = "${name}-setup";
14 includeGhcPackage = lib.any (p: p.identifier.name == "ghc") component.depends;
16 configFiles = makeSetupConfigFiles {
17 inherit (package) identifier;
18 inherit fullName flags component;
19 };
20 hooks = haskellLib.optionalHooks {
21 inherit
22 preUnpack postUnpack
23 prePatch postPatch
24 preBuild postBuild
25 preInstall postInstall
26 ;
27 };
29 executableToolDepends =
30 (lib.concatMap (c: if c.isHaskell or false
31 then builtins.attrValues (c.components.exes or {})
32 else [c]) component.build-tools) ++
33 lib.optional (component.pkgconfig != []) pkgconfig;
35 drv =
36 stdenv.mkDerivation ({
37 name = "${ghc.targetPrefix}${fullName}";
38 src = cleanSrc;
39 buildInputs = component.libs
40 ++ component.frameworks
41 ++ builtins.concatLists component.pkgconfig;
42 nativeBuildInputs = [ghc] ++ executableToolDepends;
44 passthru = {
45 inherit (package) identifier;
46 config = component;
47 inherit configFiles cleanSrc;
48 };
50 meta = {
51 homepage = package.homepage or "";
52 description = package.synopsis or "";
53 license =
54 let
55 license-map = import ../lib/cabal-licenses.nix lib;
56 in license-map.${package.license} or
57 (builtins.trace "WARNING: license \"${package.license}\" not found" license-map.LicenseRef-OtherLicense);
58 platforms = if component.platforms == null then stdenv.lib.platforms.all else component.platforms;
59 };
61 phases = ["unpackPhase" "patchPhase" "buildPhase" "installPhase"];
62 buildPhase = ''
63 runHook preBuild
64 if [[ ! -f ./Setup.hs && ! -f ./Setup.lhs ]]; then
65 cat ${defaultSetupSrc} > Setup.hs
66 fi
67 for f in Setup.hs Setup.lhs; do
68 if [ -f $f ]; then
69 echo Compiling package $f
70 ghc $f -threaded '' + (if includeGhcPackage then "-package ghc " else "")
71 + ''-package-db ${configFiles}/${configFiles.packageCfgDir} --make -o ./Setup
72 setup=$(pwd)/Setup
73 fi
74 done
75 [ -f ./Setup ] || (echo Failed to build Setup && exit 1)
76 runHook preBuild
77 '';
79 installPhase = ''
80 runHook preInstall
81 mkdir -p $out/bin
82 install ./Setup $out/bin/Setup
83 runHook postInstall
84 '';
85 }
86 // (lib.optionalAttrs (patches != []) { patches = map (p: if builtins.isFunction p then p { inherit (package.identifier) version; inherit revision; } else p) patches; })
87 // hooks
88 );
89in drv