on 19052d8 help sign in
haskell.nix/builder/setup-builder.nix
99 lines 3.4 kB history raw
1{ pkgs, stdenv, lib, buildPackages, haskellLib, ghc, nonReinstallablePkgs, hsPkgs, makeSetupConfigFiles, pkgconfig }:
3let self =
4{ component, package, name, src, enableDWARF ? false, flags ? {}, revision ? null, patches ? [], defaultSetupSrc
5, preUnpack ? component.preUnpack, postUnpack ? component.postUnpack
6, prePatch ? null, postPatch ? null
7, preBuild ? component.preBuild , postBuild ? component.postBuild
8, preInstall ? component.preInstall , postInstall ? component.postInstall
9, cleanSrc ? haskellLib.cleanCabalComponent package component "setup" src
10}@drvArgs:
12let
13 cleanSrc' = haskellLib.rootAndSubDir cleanSrc;
15 fullName = "${name}-setup";
17 includeGhcPackage = lib.any (p: p.identifier.name == "ghc") component.depends;
19 configFiles = makeSetupConfigFiles {
20 inherit (package) identifier;
21 inherit fullName flags component enableDWARF;
22 };
23 hooks = haskellLib.optionalHooks {
24 inherit
25 preUnpack postUnpack
26 prePatch postPatch
27 preBuild postBuild
28 preInstall postInstall
29 ;
30 };
32 executableToolDepends =
33 (lib.concatMap (c: if c.isHaskell or false
34 then builtins.attrValues (c.components.exes or {})
35 else [c]) component.build-tools) ++
36 lib.optional (component.pkgconfig != []) pkgconfig;
38 drv =
39 stdenv.mkDerivation ({
40 name = "${ghc.targetPrefix}${fullName}";
41 src = cleanSrc'.root;
42 buildInputs = component.libs
43 ++ component.frameworks
44 ++ builtins.concatLists component.pkgconfig;
45 nativeBuildInputs = [ghc] ++ executableToolDepends;
47 passthru = {
48 inherit (package) identifier;
49 config = component;
50 srcSubDir = cleanSrc'.subDir;
51 srcSubDirPath = cleanSrc'.root + cleanSrc'.subDir;
52 cleanSrc = cleanSrc';
53 inherit configFiles;
54 dwarf = self (drvArgs // { enableDWARF = true; });
55 };
57 meta = {
58 homepage = package.homepage or "";
59 description = package.synopsis or "";
60 license = haskellLib.cabalToNixpkgsLicense package.license;
61 platforms = if component.platforms == null then lib.platforms.all else component.platforms;
62 };
64 phases = ["unpackPhase" "patchPhase" "buildPhase" "installPhase"];
65 buildPhase = ''
66 runHook preBuild
67 if [[ ! -f ./Setup.hs && ! -f ./Setup.lhs ]]; then
68 cat ${defaultSetupSrc} > Setup.hs
69 fi
70 for f in Setup.hs Setup.lhs; do
71 if [ -f $f ]; then
72 echo Compiling package $f
73 ghc $f -threaded '' + (if includeGhcPackage then "-package ghc " else "")
74 + ''-package-db ${configFiles}/${configFiles.packageCfgDir} --make -o ./Setup
75 setup=$(pwd)/Setup
76 fi
77 done
78 [ -f ./Setup ] || (echo Failed to build Setup && exit 1)
79 runHook preBuild
80 '';
82 installPhase = ''
83 runHook preInstall
84 mkdir -p $out/bin
85 install ./Setup $out/bin/Setup
86 runHook postInstall
87 '';
88 }
89 // (lib.optionalAttrs (cleanSrc'.subDir != "") {
90 prePatch =
91 # If the package is in a sub directory `cd` there first
92 ''
93 cd ${lib.removePrefix "/" cleanSrc'.subDir}
94 '';
95 })
96 // (lib.optionalAttrs (patches != []) { patches = map (p: if builtins.isFunction p then p { inherit (package.identifier) version; inherit revision; } else p) patches; })
97 // hooks
98 );
99in drv; in self