on fd39d56 help sign in
haskell.nix/builder/default.nix
69 lines 1.7 kB history raw
1{ pkgs, stdenv, lib, haskellLib, ghc, fetchurl, writeText, runCommand, pkgconfig }:
3{ flags
4, package
5, components
7, name
8, sha256
9, src
10, revision
11, revisionSha256
13, ...
14}@config:
16let
17 cabalFile = if revision == null || revision == 0 then null else
18 fetchurl {
19 url = "https://hackage.haskell.org/package/${name}/revision/${toString revision}.cabal";
20 sha256 = revisionSha256;
21 };
22 defaultSetupSrc = builtins.toFile "Setup.hs" ''
23 import Distribution.Simple
24 main = defaultMain
25 '';
26 defaultSetup = runCommand "default-Setup" { nativeBuildInputs = [ghc]; } ''
27 cat ${defaultSetupSrc} > Setup.hs
28 ghc Setup.hs --make -o $out
29 '';
31 setup = stdenv.mkDerivation {
32 name = "${name}-setup";
33 nativeBuildInputs = [ghc];
34 inherit src;
35 phases = ["unpackPhase" "buildPhase" "installPhase"];
36 buildPhase = ''
37 setup=${defaultSetup}
38 for f in Setup.hs Setup.lhs; do
39 if [ -f $f ]; then
40 if ! (diff $f ${defaultSetupSrc} > /dev/null); then
41 echo Compiling package $f
42 ghc $f --make -o ./Setup
43 setup=$(pwd)/Setup
44 else
45 echo Using default Setup
46 fi
47 break
48 fi
49 done
50 '';
52 installPhase = ''
53 mkdir -p $out/bin
54 install $setup $out/bin/Setup
55 '';
56 };
58 comp-builder = haskellLib.weakCallPackage pkgs ./comp-builder.nix { inherit ghc haskellLib; };
60 buildComp = componentId: component: comp-builder {
61 inherit componentId component package name src flags setup cabalFile;
62 };
64in {
65 components = haskellLib.applyComponents buildComp config;
66 inherit (package) identifier;
67 inherit setup cabalFile;
68 isHaskell = true;