on e94de40 help sign in
haskell.nix/builder/hspkg-builder.nix
108 lines 3.1 kB history raw
1{ pkgs, buildPackages, stdenv, lib, haskellLib, ghc, fetchurl, runCommand, comp-builder, setup-builder }:
3config:
4{ flags
5, package
6, components
7, cabal-generator
9, name
10, sha256
11, src
12, revision
13, revisionSha256
14, patches
16, shellHook
18, ...
19}@pkg:
21assert (if ghc.isHaskellNixCompiler or false then true
22 else throw ("It is likely you used `haskell.compiler.X` instead of `haskell-nix.compiler.X`"
23 + pkgs.lib.optionalString (name != null) (" for " + name)));
25let
26 cabalFile = if revision == null || revision == 0 then null else
27 fetchurl {
28 name = "${name}-${toString revision}.cabal";
29 url = "https://hackage.haskell.org/package/${name}/revision/${toString revision}.cabal";
30 sha256 = revisionSha256;
31 };
33 defaultSetupSrc = builtins.toFile "Setup.hs" ''
34 import Distribution.Simple
35 main = defaultMain
36 '';
37 defaultSetup = setup-builder {
38 name = "${ghc.targetPrefix}default-Setup";
39 component = {
40 depends = config.setup-depends;
41 libs = [];
42 frameworks = [];
43 doExactConfig = false;
44 includeDirs = [];
45 asmSources = [];
46 cSources = [];
47 cmmSources = [];
48 cxxSources = [];
49 jsSources = [];
50 extraSrcFiles = [ "Setup.hs" "Setup.lhs" ];
51 pkgconfig = [];
52 build-tools = [];
54 platforms = null;
55 preBuild = null; postBuild = null;
56 preInstall = null; postInstall = null;
57 preUnpack = null; postUnpack = null;
58 };
59 package = {
60 identifier = {
61 name = "default-Setup";
62 version = "1.0";
63 };
64 homepage = null;
65 synopsis = null;
66 license = "MIT";
67 };
68 src = null; cleanSrc = buildPackages.runCommand "default-Setup-src" {} ''
69 mkdir $out
70 cat ${defaultSetupSrc} > $out/Setup.hs
71 '';
72 inherit defaultSetupSrc;
73 };
75 # buildPackages.runCommand "default-Setup" { nativeBuildInputs = [(ghc.passthru.buildGHC or ghc)]; } ''
76 # cat ${defaultSetupSrc} > Setup.hs
77 # mkdir -p $out/bin
78 # ${(ghc.passthru.buildGHC or ghc).targetPrefix}ghc Setup.hs --make -o $out/bin/Setup
79 # '';
81 setup = if package.buildType == "Simple"
82 then defaultSetup
83 else setup-builder {
84 component = components.setup // {
85 depends = config.setup-depends ++ components.setup.depends ++ package.setup-depends;
86 extraSrcFiles = components.setup.extraSrcFiles ++ [ "Setup.hs" "Setup.lhs" ];
87 pkgconfig = if components ? library then components.library.pkgconfig or [] else [];
88 };
89 inherit package name src flags revision patches defaultSetupSrc;
90 inherit (pkg) preUnpack postUnpack;
91 };
93 buildComp = componentId: component: comp-builder {
94 inherit componentId component package name src flags setup cabalFile cabal-generator patches revision
95 shellHook
96 ;
97 };
99in rec {
100 components = haskellLib.applyComponents buildComp pkg;
101 checks = pkgs.recurseIntoAttrs (builtins.mapAttrs
102 (_: d: haskellLib.check d)
103 (lib.filterAttrs (_: d: d.config.doCheck) components.tests));
104 inherit (package) identifier detailLevel isLocal;
105 inherit setup cabalFile;
106 isHaskell = true;
107 inherit src;