1# Build an idris package
2{
3 stdenv,
4 lib,
5 gmp,
6 prelude,
7 base,
8 with-packages,
9 idris,
10}:
11{
12 idrisDeps ? [ ],
13 noPrelude ? false,
14 noBase ? false,
15 pname,
16 version,
17 ipkgName ? pname,
18 extraBuildInputs ? [ ],
19 idrisBuildOptions ? [ ],
20 idrisTestOptions ? [ ],
21 idrisInstallOptions ? [ ],
22 idrisDocOptions ? [ ],
23 ...
24}@attrs:
25let
26 allIdrisDeps = idrisDeps ++ lib.optional (!noPrelude) prelude ++ lib.optional (!noBase) base;
27 idris-with-packages = with-packages allIdrisDeps;
28 newAttrs =
29 builtins.removeAttrs attrs [
30 "idrisDeps"
31 "noPrelude"
32 "noBase"
33 "pname"
34 "version"
35 "ipkgName"
36 "extraBuildInputs"
37 ]
38 // {
39 meta = attrs.meta // {
40 platforms = attrs.meta.platforms or idris.meta.platforms;
41 };
42 };
43in
44stdenv.mkDerivation (
45 {
46 pname = "idris-${pname}";
47 inherit version;
48
49 buildInputs = [
50 idris-with-packages
51 gmp
52 ]
53 ++ extraBuildInputs;
54 propagatedBuildInputs = allIdrisDeps;
55
56 # Some packages use the style
57 # opts = -i ../../path/to/package
58 # rather than the declarative pkgs attribute so we have to rewrite the path.
59 patchPhase = ''
60 runHook prePatch
61 sed -i ${ipkgName}.ipkg -e "/^opts/ s|-i \\.\\./|-i ${idris-with-packages}/libs/|g"
62 runHook postPatch
63 '';
64
65 buildPhase = ''
66 runHook preBuild
67 idris --build ${ipkgName}.ipkg ${lib.escapeShellArgs idrisBuildOptions}
68 runHook postBuild
69 '';
70
71 checkPhase = ''
72 runHook preCheck
73 if grep -q tests ${ipkgName}.ipkg; then
74 idris --testpkg ${ipkgName}.ipkg ${lib.escapeShellArgs idrisTestOptions}
75 fi
76 runHook postCheck
77 '';
78
79 installPhase = ''
80 runHook preInstall
81
82 idris --install ${ipkgName}.ipkg --ibcsubdir $out/libs ${lib.escapeShellArgs idrisInstallOptions}
83
84 IDRIS_DOC_PATH=$out/doc idris --installdoc ${ipkgName}.ipkg ${lib.escapeShellArgs idrisDocOptions} || true
85
86 # If the ipkg file defines an executable, install that
87 executable=$(grep -Po '^executable = \K.*' ${ipkgName}.ipkg || true)
88 # $executable intentionally not quoted because it must be quoted correctly
89 # in the ipkg file already
90 if [ ! -z "$executable" ] && [ -f $executable ]; then
91 mkdir -p $out/bin
92 mv $executable $out/bin/$executable
93 fi
94
95 runHook postInstall
96 '';
97
98 }
99 // newAttrs
100)