Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ lib, stdenv, writeScript, fetchFromGitHub, z3, ocamlPackages, makeWrapper, installShellFiles, removeReferencesTo }:
2
3stdenv.mkDerivation rec {
4 pname = "fstar";
5 version = "2023.02.01";
6
7 src = fetchFromGitHub {
8 owner = "FStarLang";
9 repo = "FStar";
10 rev = "v${version}";
11 hash = "sha256-sLhbIGF7j1tH8zKsPq1qOSwHvYDrVCyfln9UbE3IYv0=";
12 };
13
14 strictDeps = true;
15
16 nativeBuildInputs = [
17 z3
18 makeWrapper
19 installShellFiles
20 removeReferencesTo
21 ] ++ (with ocamlPackages; [
22 ocaml
23 findlib
24 ocamlbuild
25 menhir
26 ]);
27
28 buildInputs = with ocamlPackages; [
29 batteries
30 zarith
31 stdint
32 yojson
33 fileutils
34 menhirLib
35 pprint
36 sedlex
37 ppxlib
38 ppx_deriving
39 ppx_deriving_yojson
40 process
41 ];
42
43 makeFlags = [ "PREFIX=$(out)" ];
44
45 enableParallelBuilding = true;
46
47 postPatch = ''
48 patchShebangs ulib/gen_mllib.sh
49 substituteInPlace src/ocaml-output/Makefile --replace '$(COMMIT)' 'v${version}'
50 '';
51
52 preInstall = ''
53 mkdir -p $out/lib/ocaml/${ocamlPackages.ocaml.version}/site-lib/fstarlib
54 '';
55 postInstall = ''
56 # Remove build artifacts
57 find $out -name _build -type d | xargs -I{} rm -rf "{}"
58 remove-references-to -t '${ocamlPackages.ocaml}' $out/bin/fstar.exe
59
60 wrapProgram $out/bin/fstar.exe --prefix PATH ":" "${z3}/bin"
61 installShellCompletion --bash .completion/bash/fstar.exe.bash
62 installShellCompletion --fish .completion/fish/fstar.exe.fish
63 installShellCompletion --zsh --name _fstar.exe .completion/zsh/__fstar.exe
64 '';
65
66 passthru.updateScript = writeScript "update-fstar" ''
67 #!/usr/bin/env nix-shell
68 #!nix-shell -i bash -p git gnugrep common-updater-scripts
69 set -eu -o pipefail
70
71 version="$(git ls-remote --tags git@github.com:FStarLang/FStar.git | grep -Po 'v\K\d{4}\.\d{2}\.\d{2}' | sort | tail -n1)"
72 update-source-version fstar "$version"
73 '';
74
75 meta = with lib; {
76 description = "ML-like functional programming language aimed at program verification";
77 homepage = "https://www.fstar-lang.org";
78 changelog = "https://github.com/FStarLang/FStar/raw/v${version}/CHANGES.md";
79 license = licenses.asl20;
80 maintainers = with maintainers; [ gebner pnmadelaine ];
81 mainProgram = "fstar.exe";
82 platforms = with platforms; darwin ++ linux;
83 };
84}