mirror of
https://github.com/NixOS/nixpkgs.git
synced 2026-07-06 17:13:24 -05:00
As reported on FreeBSD forums, updating lean4 to 4.30.0 fails to a leantar related issue. We follow the patch mentioned on the FreeBSD forums and depend on digama0/leangz (that comes with leantar). However, there doesn't seem to be a reason to disable installing leantar, so we don't set INSTALL_LEANTAR=OFF like the patch. References: - https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=295656 - https://cgit.freebsd.org/ports/commit/?id=516f8a5764de5c7bdd0e9f7810601a5057bbc650 - https://lean-lang.org/doc/reference/latest/releases/v4.30.0/#release-v4___30___0 - leanprover/lean4#12822
145 lines
3.8 KiB
Nix
145 lines
3.8 KiB
Nix
# Lean 4 toolchain for the leanPackages set (independent of pkgs.lean4).
|
||
{
|
||
lib,
|
||
stdenv,
|
||
symlinkJoin,
|
||
cmake,
|
||
fetchFromGitHub,
|
||
git,
|
||
gmp,
|
||
cadical,
|
||
leangz,
|
||
pkg-config,
|
||
libuv,
|
||
perl,
|
||
testers,
|
||
}:
|
||
let
|
||
cadical' = cadical.override { version = "2.1.3"; };
|
||
|
||
lean4 = stdenv.mkDerivation (finalAttrs: {
|
||
pname = "lean4";
|
||
version = "4.30.0";
|
||
|
||
mimalloc-src = fetchFromGitHub {
|
||
owner = "microsoft";
|
||
repo = "mimalloc";
|
||
tag = "v2.2.3";
|
||
hash = "sha256-B0gngv16WFLBtrtG5NqA2m5e95bYVcQraeITcOX9A74=";
|
||
};
|
||
|
||
src = fetchFromGitHub {
|
||
owner = "leanprover";
|
||
repo = "lean4";
|
||
tag = "v${finalAttrs.version}";
|
||
hash = "sha256-YTsfIppd6km7wOjAxRH5KMPsW++ztFDCJT2up72J86Q=";
|
||
};
|
||
|
||
# Vendor mimalloc. Upstream has since partially adopted FetchContent:
|
||
# https://github.com/leanprover/lean4/commit/a145b9c11a0fe38fd4c921024a7376c99cc34bd2
|
||
#
|
||
# Dynamically adjust the source tree to maintain a healthy boundary
|
||
# with Nix and avoid overstepping on its jurisdiction over cache coherence.
|
||
postPatch =
|
||
let
|
||
pattern = "\${LEAN_BINARY_DIR}/../mimalloc/src/mimalloc";
|
||
in
|
||
''
|
||
substituteInPlace src/CMakeLists.txt \
|
||
--replace-fail 'set(GIT_SHA1 "")' 'set(GIT_SHA1 "${finalAttrs.src.tag}")'
|
||
|
||
rm -rf src/lake/examples/git/
|
||
|
||
substituteInPlace CMakeLists.txt \
|
||
--replace-fail 'GIT_REPOSITORY https://github.com/microsoft/mimalloc' \
|
||
'SOURCE_DIR "${finalAttrs.mimalloc-src}"' \
|
||
--replace-fail 'GIT_TAG ${finalAttrs.mimalloc-src.tag}' ""
|
||
for file in stage0/src/CMakeLists.txt stage0/src/runtime/CMakeLists.txt src/CMakeLists.txt src/runtime/CMakeLists.txt; do
|
||
substituteInPlace "$file" \
|
||
--replace-fail '${pattern}' '${finalAttrs.mimalloc-src}'
|
||
done
|
||
|
||
substituteInPlace src/lake/Lake/Load/Lean/Elab.lean \
|
||
--replace-fail \
|
||
'let upToDate := (← olean.pathExists) ∧' \
|
||
'let upToDate := cfg.pkgDir.toString.startsWith "/nix/store/" ∨ (← olean.pathExists) ∧'
|
||
'';
|
||
|
||
preConfigure = ''
|
||
patchShebangs stage0/src/bin/ src/bin/
|
||
'';
|
||
|
||
nativeBuildInputs = [
|
||
cmake
|
||
pkg-config
|
||
leangz # Provides leantar
|
||
];
|
||
|
||
buildInputs = [
|
||
gmp
|
||
libuv
|
||
cadical'
|
||
];
|
||
|
||
nativeCheckInputs = [
|
||
git
|
||
perl
|
||
];
|
||
|
||
cmakeFlags = [
|
||
"-DUSE_GITHASH=OFF"
|
||
"-DINSTALL_LICENSE=OFF"
|
||
"-DINSTALL_CADICAL=OFF"
|
||
"-DUSE_MIMALLOC=ON"
|
||
];
|
||
|
||
passthru.tests = {
|
||
version = testers.testVersion {
|
||
package = finalAttrs.finalPackage;
|
||
version = "v${finalAttrs.version}";
|
||
};
|
||
};
|
||
|
||
meta = {
|
||
description = "Automatic and interactive theorem prover";
|
||
homepage = "https://leanprover.github.io/";
|
||
changelog = "https://github.com/leanprover/lean4/blob/${finalAttrs.src.tag}/RELEASES.md";
|
||
license = lib.licenses.asl20;
|
||
platforms = lib.platforms.all;
|
||
maintainers = with lib.maintainers; [
|
||
nadja-y
|
||
niklashh
|
||
];
|
||
mainProgram = "lean";
|
||
};
|
||
});
|
||
|
||
oldStorePath = builtins.substring 0 43 (toString lean4);
|
||
in
|
||
# Binary-patched for correct runtime discovery in wrapped environments.
|
||
symlinkJoin {
|
||
inherit (lean4) name pname;
|
||
paths = [ lean4 ];
|
||
nativeBuildInputs = [ perl ];
|
||
postBuild = ''
|
||
newStorePath=$(echo "$out" | head -c 43)
|
||
|
||
# Copy (not symlink) — IO.appPath resolves through symlinks.
|
||
rm $out/bin/lean $out/bin/lake
|
||
cp ${lean4}/bin/lean $out/bin/lean
|
||
cp ${lean4}/bin/lake $out/bin/lake
|
||
|
||
for bin in $out/bin/lean $out/bin/lake; do
|
||
cat "$bin" \
|
||
| perl -pe "s|\Q${oldStorePath}\E|$newStorePath|g" \
|
||
> "$bin.tmp"
|
||
chmod +x "$bin.tmp"
|
||
mv "$bin.tmp" "$bin"
|
||
done
|
||
'';
|
||
|
||
inherit (lean4) version src meta;
|
||
passthru = {
|
||
inherit (lean4) version src;
|
||
};
|
||
}
|