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