Merge pull request #119126 from fabaff/pycomfoconnect
[NixPkgs.git] / pkgs / development / idris-modules / build-idris-package.nix
blobac0555636be0b104ba72e6edbc7ec33ea3251b40
1 # Build an idris package
2 { stdenv, lib, gmp, prelude, base, with-packages, idris }:
3   { idrisDeps ? []
4   , noPrelude ? false
5   , noBase ? false
6   , name
7   , version
8   , ipkgName ? name
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     "name" "version" "ipkgName" "extraBuildInputs"
24   ] // {
25     meta = attrs.meta // {
26       platforms = attrs.meta.platforms or idris.meta.platforms;
27     };
28   };
30 stdenv.mkDerivation ({
31   name = "idris-${name}-${version}";
33   buildInputs = [ idris-with-packages gmp ] ++ extraBuildInputs;
34   propagatedBuildInputs = allIdrisDeps;
36   # Some packages use the style
37   # opts = -i ../../path/to/package
38   # rather than the declarative pkgs attribute so we have to rewrite the path.
39   postPatch = ''
40     runHook prePatch
41     sed -i ${ipkgName}.ipkg -e "/^opts/ s|-i \\.\\./|-i ${idris-with-packages}/libs/|g"
42   '';
44   buildPhase = ''
45     runHook preBuild
46     idris --build ${ipkgName}.ipkg ${lib.escapeShellArgs idrisBuildOptions}
47     runHook postBuild
48   '';
50   checkPhase = ''
51     runHook preCheck
52     if grep -q tests ${ipkgName}.ipkg; then
53       idris --testpkg ${ipkgName}.ipkg ${lib.escapeShellArgs idrisTestOptions}
54     fi
55     runHook postCheck
56   '';
58   installPhase = ''
59     runHook preInstall
61     idris --install ${ipkgName}.ipkg --ibcsubdir $out/libs ${lib.escapeShellArgs idrisInstallOptions}
63     IDRIS_DOC_PATH=$out/doc idris --installdoc ${ipkgName}.ipkg ${lib.escapeShellArgs idrisDocOptions} || true
65     # If the ipkg file defines an executable, install that
66     executable=$(grep -Po '^executable = \K.*' ${ipkgName}.ipkg || true)
67     # $executable intentionally not quoted because it must be quoted correctly
68     # in the ipkg file already
69     if [ ! -z "$executable" ] && [ -f $executable ]; then
70       mkdir -p $out/bin
71       mv $executable $out/bin/$executable
72     fi
74     runHook postInstall
75   '';
77 } // newAttrs)