nixpkgs/pkgs/development/idris-modules/build-idris-package.nix

78 lines
2.2 KiB
Nix
Raw Normal View History

2015-11-27 18:17:17 +00:00
# Build an idris package
{ stdenv, lib, gmp, prelude, base, with-packages, idris }:
{ idrisDeps ? []
, noPrelude ? false
, noBase ? false
, name
, version
2018-09-18 08:38:59 +00:00
, ipkgName ? name
, extraBuildInputs ? []
, idrisBuildOptions ? []
, idrisTestOptions ? []
, idrisInstallOptions ? []
, idrisDocOptions ? []
2018-07-02 03:18:08 +00:00
, ...
}@attrs:
let
allIdrisDeps = idrisDeps
++ lib.optional (!noPrelude) prelude
++ lib.optional (!noBase) base;
idris-with-packages = with-packages allIdrisDeps;
2018-09-18 08:38:59 +00:00
newAttrs = builtins.removeAttrs attrs [
"idrisDeps" "noPrelude" "noBase"
"name" "version" "ipkgName" "extraBuildInputs"
] // {
2018-07-02 03:18:08 +00:00
meta = attrs.meta // {
platforms = attrs.meta.platforms or idris.meta.platforms;
2018-07-02 03:18:08 +00:00
};
};
in
stdenv.mkDerivation ({
name = "idris-${name}-${version}";
2018-07-02 03:18:08 +00:00
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 = ''
2018-09-18 08:38:59 +00:00
runHook prePatch
sed -i ${ipkgName}.ipkg -e "/^opts/ s|-i \\.\\./|-i ${idris-with-packages}/libs/|g"
'';
buildPhase = ''
2018-09-18 08:38:59 +00:00
runHook preBuild
idris --build ${ipkgName}.ipkg ${lib.escapeShellArgs idrisBuildOptions}
2018-09-18 08:38:59 +00:00
runHook postBuild
'';
checkPhase = ''
2018-09-18 08:38:59 +00:00
runHook preCheck
if grep -q tests ${ipkgName}.ipkg; then
idris --testpkg ${ipkgName}.ipkg ${lib.escapeShellArgs idrisTestOptions}
fi
2018-09-18 08:38:59 +00:00
runHook postCheck
'';
installPhase = ''
2018-09-18 08:38:59 +00:00
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
2018-09-18 08:38:59 +00:00
runHook postInstall
'';
2015-11-27 16:03:04 +00:00
2018-07-02 03:18:08 +00:00
} // newAttrs)