2015-11-27 21:17:17 +03:00
|
|
|
# Build an idris package
|
2019-08-02 17:42:21 +03:00
|
|
|
{ stdenv, lib, gmp, prelude, base, with-packages, idris }:
|
2017-11-06 21:18:59 +03:00
|
|
|
{ idrisDeps ? []
|
2018-07-03 22:19:28 +03:00
|
|
|
, noPrelude ? false
|
|
|
|
, noBase ? false
|
2017-11-06 21:18:59 +03:00
|
|
|
, name
|
|
|
|
, version
|
2018-09-18 11:38:59 +03:00
|
|
|
, ipkgName ? name
|
2017-11-06 21:18:59 +03:00
|
|
|
, extraBuildInputs ? []
|
2019-07-31 17:46:47 +03:00
|
|
|
, idrisBuildOptions ? []
|
|
|
|
, idrisTestOptions ? []
|
|
|
|
, idrisInstallOptions ? []
|
|
|
|
, idrisDocOptions ? []
|
2018-07-02 06:18:08 +03:00
|
|
|
, ...
|
|
|
|
}@attrs:
|
2017-11-06 21:18:59 +03:00
|
|
|
let
|
2018-07-03 22:19:28 +03:00
|
|
|
allIdrisDeps = idrisDeps
|
2019-08-02 17:42:21 +03:00
|
|
|
++ lib.optional (!noPrelude) prelude
|
|
|
|
++ lib.optional (!noBase) base;
|
|
|
|
idris-with-packages = with-packages allIdrisDeps;
|
2018-09-18 11:38:59 +03:00
|
|
|
newAttrs = builtins.removeAttrs attrs [
|
|
|
|
"idrisDeps" "noPrelude" "noBase"
|
|
|
|
"name" "version" "ipkgName" "extraBuildInputs"
|
|
|
|
] // {
|
2018-07-02 06:18:08 +03:00
|
|
|
meta = attrs.meta // {
|
2019-08-02 17:42:21 +03:00
|
|
|
platforms = attrs.meta.platforms or idris.meta.platforms;
|
2018-07-02 06:18:08 +03:00
|
|
|
};
|
|
|
|
};
|
2017-11-06 21:18:59 +03:00
|
|
|
in
|
|
|
|
stdenv.mkDerivation ({
|
2018-07-13 23:43:33 +03:00
|
|
|
name = "idris-${name}-${version}";
|
2017-11-06 21:18:59 +03:00
|
|
|
|
2018-07-02 06:18:08 +03:00
|
|
|
buildInputs = [ idris-with-packages gmp ] ++ extraBuildInputs;
|
2018-07-03 22:19:28 +03:00
|
|
|
propagatedBuildInputs = allIdrisDeps;
|
2017-11-06 21:18:59 +03:00
|
|
|
|
|
|
|
# Some packages use the style
|
|
|
|
# opts = -i ../../path/to/package
|
|
|
|
# rather than the declarative pkgs attribute so we have to rewrite the path.
|
|
|
|
postPatch = ''
|
2018-09-18 11:38:59 +03:00
|
|
|
runHook prePatch
|
|
|
|
sed -i ${ipkgName}.ipkg -e "/^opts/ s|-i \\.\\./|-i ${idris-with-packages}/libs/|g"
|
2018-02-03 13:12:43 +03:00
|
|
|
'';
|
|
|
|
|
2015-11-27 17:35:59 +03:00
|
|
|
buildPhase = ''
|
2018-09-18 11:38:59 +03:00
|
|
|
runHook preBuild
|
2019-07-31 17:46:47 +03:00
|
|
|
idris --build ${ipkgName}.ipkg ${lib.escapeShellArgs idrisBuildOptions}
|
2018-09-18 11:38:59 +03:00
|
|
|
runHook postBuild
|
2015-11-27 17:35:59 +03:00
|
|
|
'';
|
|
|
|
|
|
|
|
checkPhase = ''
|
2018-09-18 11:38:59 +03:00
|
|
|
runHook preCheck
|
|
|
|
if grep -q tests ${ipkgName}.ipkg; then
|
2019-07-31 17:46:47 +03:00
|
|
|
idris --testpkg ${ipkgName}.ipkg ${lib.escapeShellArgs idrisTestOptions}
|
2015-11-27 17:35:59 +03:00
|
|
|
fi
|
2018-09-18 11:38:59 +03:00
|
|
|
runHook postCheck
|
2015-11-27 17:35:59 +03:00
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
2018-09-18 11:38:59 +03:00
|
|
|
runHook preInstall
|
2019-04-28 17:54:32 +03:00
|
|
|
|
2019-07-31 17:46:47 +03:00
|
|
|
idris --install ${ipkgName}.ipkg --ibcsubdir $out/libs ${lib.escapeShellArgs idrisInstallOptions}
|
2019-04-28 17:54:32 +03:00
|
|
|
|
2019-07-31 17:46:47 +03:00
|
|
|
IDRIS_DOC_PATH=$out/doc idris --installdoc ${ipkgName}.ipkg ${lib.escapeShellArgs idrisDocOptions} || true
|
2019-04-28 17:54:32 +03:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|
2018-09-18 11:38:59 +03:00
|
|
|
runHook postInstall
|
2015-11-27 17:35:59 +03:00
|
|
|
'';
|
2015-11-27 19:03:04 +03:00
|
|
|
|
2018-07-02 06:18:08 +03:00
|
|
|
} // newAttrs)
|