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