2021-01-20 23:15:24 +03:00
|
|
|
{ stdenv
|
2021-03-15 17:21:50 +03:00
|
|
|
, lib
|
2021-01-20 23:15:24 +03:00
|
|
|
, chez
|
|
|
|
, clang
|
|
|
|
, fetchFromGitHub
|
|
|
|
, makeWrapper
|
2021-03-15 17:21:50 +03:00
|
|
|
, idris2-version
|
2021-01-15 20:20:52 +03:00
|
|
|
}:
|
|
|
|
|
|
|
|
# Uses scheme to bootstrap the build of idris2
|
|
|
|
stdenv.mkDerivation rec {
|
|
|
|
pname = "idris2";
|
2021-03-15 17:21:50 +03:00
|
|
|
version = idris2-version;
|
2021-01-15 20:20:52 +03:00
|
|
|
|
2021-03-15 17:21:50 +03:00
|
|
|
src = ../.;
|
2021-01-15 20:20:52 +03:00
|
|
|
|
|
|
|
strictDeps = true;
|
|
|
|
nativeBuildInputs = [ makeWrapper clang chez ];
|
|
|
|
buildInputs = [ chez ];
|
|
|
|
|
|
|
|
prePatch = ''
|
|
|
|
patchShebangs --build tests
|
|
|
|
'';
|
|
|
|
|
|
|
|
makeFlags = [ "PREFIX=$(out)" ]
|
2021-03-15 17:21:50 +03:00
|
|
|
++ lib.optional stdenv.isDarwin "OS=";
|
2021-01-15 20:20:52 +03:00
|
|
|
|
|
|
|
# The name of the main executable of pkgs.chez is `scheme`
|
2021-01-20 23:15:24 +03:00
|
|
|
buildFlags = [ "bootstrap" "SCHEME=scheme" ];
|
2021-01-15 20:20:52 +03:00
|
|
|
|
2021-01-20 23:15:24 +03:00
|
|
|
checkTarget = "test";
|
2021-01-15 20:20:52 +03:00
|
|
|
|
|
|
|
# TODO: Move this into its own derivation, such that this can be changed
|
|
|
|
# without having to recompile idris2 every time.
|
|
|
|
postInstall = let
|
2021-03-09 21:27:05 +03:00
|
|
|
includedLibs = [ "base" "contrib" "network" "prelude" "test" ];
|
2021-01-15 20:20:52 +03:00
|
|
|
name = "${pname}-${version}";
|
2021-02-28 19:11:03 +03:00
|
|
|
packagePaths = builtins.map (l: "$out/${name}/${l}-${version}") includedLibs;
|
2021-01-15 20:20:52 +03:00
|
|
|
additionalIdris2Paths = builtins.concatStringsSep ":" packagePaths;
|
2021-03-15 17:21:50 +03:00
|
|
|
globalLibraries = [ "\\$HOME/.nix-profile/lib/${name}" "/run/current-system/sw/lib/${name}" ];
|
|
|
|
globalLibrariesPath = builtins.concatStringsSep ":" globalLibraries;
|
2021-01-15 20:20:52 +03:00
|
|
|
in ''
|
|
|
|
# Remove existing idris2 wrapper that sets incorrect LD_LIBRARY_PATH
|
|
|
|
rm $out/bin/idris2
|
|
|
|
# Move actual idris2 binary
|
|
|
|
mv $out/bin/idris2_app/idris2.so $out/bin/idris2
|
|
|
|
# After moving the binary, there is nothing left in idris2_app that isn't
|
|
|
|
# either contained in lib/ or is useless to us.
|
|
|
|
rm $out/bin/idris2_app/*
|
|
|
|
rmdir $out/bin/idris2_app
|
|
|
|
# idris2 needs to find scheme at runtime to compile
|
|
|
|
# idris2 installs packages with --install into the path given by PREFIX.
|
|
|
|
# Since PREFIX is in nix-store, it is immutable so --install does not work.
|
|
|
|
# If the user redefines PREFIX to be able to install packages, idris2 will
|
|
|
|
# not find the libraries and packages since all paths are relative to
|
|
|
|
# PREFIX by default.
|
|
|
|
# We explicitly make all paths to point to nix-store, such that they are
|
|
|
|
# independent of what IDRIS2_PREFIX is. This allows the user to redefine
|
|
|
|
# IDRIS2_PREFIX and use --install as expected.
|
|
|
|
# TODO: Make support libraries their own derivation such that
|
|
|
|
# overriding LD_LIBRARY_PATH is unnecessary
|
|
|
|
# TODO: Maybe set IDRIS2_PREFIX to the users home directory
|
|
|
|
wrapProgram "$out/bin/idris2" \
|
|
|
|
--set-default CHEZ "${chez}/bin/scheme" \
|
|
|
|
--suffix IDRIS2_LIBS ':' "$out/${name}/lib" \
|
|
|
|
--suffix IDRIS2_DATA ':' "$out/${name}/support" \
|
|
|
|
--suffix IDRIS2_PATH ':' "${additionalIdris2Paths}" \
|
2021-03-15 17:21:50 +03:00
|
|
|
--run "export IDRIS2_PACKAGE_PATH=\$IDRIS2_PACKAGE_PATH:${globalLibrariesPath}" \
|
2021-01-15 20:20:52 +03:00
|
|
|
--suffix LD_LIBRARY_PATH ':' "$out/${name}/lib"
|
|
|
|
'';
|
|
|
|
}
|