summary refs log tree commit diff
path: root/pkgs/development/idris-modules/build-idris-package.nix
blob: 2ae1d55258b83ed5539c197e0c3adb17f6ed6c00 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Build an idris package
{ stdenv, lib, idrisPackages, gmp }:
  { idrisDeps ? []
  , noPrelude ? false
  , noBase ? false
  , name
  , version
  , ipkgName ? name
  , extraBuildInputs ? []
  , idrisBuildOptions ? []
  , idrisTestOptions ? []
  , idrisInstallOptions ? []
  , idrisDocOptions ? []
  , ...
  }@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" "noPrelude" "noBase"
    "name" "version" "ipkgName" "extraBuildInputs"
  ] // {
    meta = attrs.meta // {
      platforms = attrs.meta.platforms or idrisPackages.idris.meta.platforms;
    };
  };
in
stdenv.mkDerivation ({
  name = "idris-${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 = ''
    runHook prePatch
    sed -i ${ipkgName}.ipkg -e "/^opts/ s|-i \\.\\./|-i ${idris-with-packages}/libs/|g"
  '';

  buildPhase = ''
    runHook preBuild
    idris --build ${ipkgName}.ipkg ${lib.escapeShellArgs idrisBuildOptions}
    runHook postBuild
  '';

  checkPhase = ''
    runHook preCheck
    if grep -q tests ${ipkgName}.ipkg; then
      idris --testpkg ${ipkgName}.ipkg ${lib.escapeShellArgs idrisTestOptions}
    fi
    runHook postCheck
  '';

  installPhase = ''
    runHook preInstall

    idris --install ${ipkgName}.ipkg --ibcsubdir $out/libs ${lib.escapeShellArgs idrisInstallOptions}

    IDRIS_DOC_PATH=$out/doc idris --installdoc ${ipkgName}.ipkg ${lib.escapeShellArgs idrisDocOptions} || true

    # If the ipkg file defines an executable, install that
    executable=$(grep -Po '^executable = \K.*' ${ipkgName}.ipkg || true)
    # $executable intentionally not quoted because it must be quoted correctly
    # in the ipkg file already
    if [ ! -z "$executable" ] && [ -f $executable ]; then
      mkdir -p $out/bin
      mv $executable $out/bin/$executable
    fi

    runHook postInstall
  '';

} // newAttrs)