forked from cryspen/hax
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
168 lines (164 loc) · 5.47 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
{
inputs = {
flake-utils.url = "github:numtide/flake-utils";
crane = {
url = "github:ipetkov/crane";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
};
};
rust-overlay.follows = "crane/rust-overlay";
fstar = {
url = "github:FStarLang/FStar/v2024.01.13";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
};
};
hacl-star = {
url = "github:hacl-star/hacl-star";
flake = false;
};
};
outputs = {
flake-utils,
nixpkgs,
rust-overlay,
crane,
hacl-star,
...
} @ inputs:
flake-utils.lib.eachDefaultSystem (
system: let
pkgs = import nixpkgs {
inherit system;
overlays = [rust-overlay.overlays.default];
};
rustc = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
craneLib = (crane.mkLib pkgs).overrideToolchain rustc;
ocamlformat = pkgs.ocamlformat_0_24_1;
rustfmt = pkgs.rustfmt;
fstar = inputs.fstar.packages.${system}.default;
hax-env-file = pkgs.writeText "hax-env-file" ''
HAX_PROOF_LIBS_HOME="${./proof-libs/fstar}"
HAX_LIBS_HOME="${./hax-lib}"/proofs/fstar/extraction
HACL_HOME="${hacl-star}"
'';
hax-env = pkgs.writeScriptBin "hax-env" ''
if [[ "$1" == "no-export" ]]; then
cat "${hax-env-file}"
else
cat "${hax-env-file}" | xargs -I{} echo "export {}"
fi
'';
in rec {
packages = {
inherit rustc ocamlformat rustfmt fstar hax-env;
hax-engine = pkgs.callPackage ./engine {
hax-rust-frontend = packages.hax-rust-frontend.unwrapped;
hax-engine-names-extract = packages.hax-rust-frontend.hax-engine-names-extract;
inherit rustc;
};
hax-rust-frontend = pkgs.callPackage ./cli {
inherit rustc craneLib;
inherit (packages) hax-engine;
};
hax = packages.hax-rust-frontend;
default = packages.hax;
check-toolchain = checks.toolchain;
check-examples = checks.examples;
check-readme-coherency = checks.readme-coherency;
};
checks = {
toolchain = packages.hax.tests;
examples = pkgs.callPackage ./examples {
inherit (packages) hax;
inherit craneLib fstar hacl-star hax-env;
};
readme-coherency = let
src = pkgs.lib.sourceFilesBySuffices ./. [".md"];
in
pkgs.stdenv.mkDerivation {
name = "readme-coherency";
inherit src;
buildPhase = ''
${apps.replace-fstar-versions-md.program}
diff -r . ${src}
'';
installPhase = "touch $out";
};
};
apps = {
replace-fstar-versions-md = {
type = "app";
program = "${pkgs.writeScript "replace-fstar-versions-md" ''
FSTAR_VERSION=$(cat ${./flake.lock} | ${pkgs.jq}/bin/jq '.nodes.fstar.original.ref' -r)
${pkgs.fd}/bin/fd \
-X ${pkgs.sd}/bin/sd '`.*?`(<!---FSTAR_VERSION-->)' '`'"$FSTAR_VERSION"'`$1' **/*.md \
";" --glob '*.md'
''}";
};
serve-rustc-docs = {
type = "app";
program = "${pkgs.writeScript "serve-rustc-docs" ''
cd ${packages.rustc.passthru.availableComponents.rustc-docs}/share/doc/rust/html/rustc
${pkgs.python3}/bin/python -m http.server
''}";
};
};
devShells = let
inputsFrom = [
packages.hax-rust-frontend.unwrapped
# `hax-engine`'s build requires `hax-rust-frontend` and
# `hax-engine-names-extract`, but in a dev environment,
# those two packages are supposed to be built locally,
# thus we kill them here
(packages.hax-engine.override {
hax-rust-frontend = pkgs.hello;
hax-engine-names-extract = pkgs.hello;
})
];
in let
packages = [
ocamlformat
pkgs.ocamlPackages.ocaml-lsp
pkgs.ocamlPackages.ocamlformat-rpc-lib
pkgs.ocamlPackages.ocaml-print-intf
pkgs.ocamlPackages.odoc
pkgs.ocamlPackages.utop
pkgs.cargo-expand
pkgs.cargo-insta
pkgs.openssl.dev
pkgs.pkg-config
pkgs.rust-analyzer
rustfmt
rustc
(pkgs.stdenv.mkDerivation {
name = "rebuild-script";
phases = ["installPhase"];
installPhase = ''
mkdir -p $out/bin
cp ${./.utils/rebuild.sh} $out/bin/rebuild
'';
})
];
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
in {
fstar = pkgs.mkShell {
inherit inputsFrom LIBCLANG_PATH;
HACL_HOME = "${hacl-star}";
shellHook = ''
HAX_ROOT=$(git rev-parse --show-toplevel)
export HAX_PROOF_LIBS_HOME="$HAX_ROOT/proof-libs/fstar"
export HAX_LIBS_HOME="$HAX_ROOT/hax-lib"
'';
packages = packages ++ [fstar];
};
default = pkgs.mkShell {
inherit packages inputsFrom LIBCLANG_PATH;
};
};
}
);
}