summary refs log tree commit diff
path: root/pkgs/development/idris-modules/build-idris-package.nix
blob: 7168eb2c956f4c08b3d19c83bbaacdff045fb759 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Build an idris package
{ stdenv, lib, idrisPackages, gmp }:
  { idrisDeps ? []
  , noPrelude ? false
  , noBase ? false
  , name
  , version
  , extraBuildInputs ? []
  , ...
  }@attrs:
let
  allIdrisDeps = idrisDeps
    ++ lib.optional (!noPrelude) idrisPackages.prelude
    ++ lib.optional (!noBase) idrisPackages.base;
  idris-with-packages = idrisPackages.with-packages allIdrisDeps;
  newAttrs = builtins.removeAttrs attrs [ "idrisDeps" "extraBuildInputs" "name" "version" ] // {
    meta = attrs.meta // {
      platforms = attrs.meta.platforms or idrisPackages.idris.meta.platforms;
    };
  };
in
stdenv.mkDerivation ({
  name = "${name}-${version}";

  buildInputs = [ idris-with-packages gmp ] ++ extraBuildInputs;
  propagatedBuildInputs = allIdrisDeps;

  # Some packages use the style
  # opts = -i ../../path/to/package
  # rather than the declarative pkgs attribute so we have to rewrite the path.
  postPatch = ''
    sed -i *.ipkg -e "/^opts/ s|-i \\.\\./|-i ${idris-with-packages}/libs/|g"
  '';

  buildPhase = ''
    idris --build *.ipkg
  '';

  checkPhase = ''
    if grep -q test *.ipkg; then
      idris --testpkg *.ipkg
    fi
  '';

  installPhase = ''
    idris --install *.ipkg --ibcsubdir $out/libs
    IDRIS_DOC_PATH=$out/doc idris --installdoc *.ipkg || true
  '';

} // newAttrs)