forked from hacspec/hax
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
202 lines (197 loc) · 7.13 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
crane = {
url = "github:ipetkov/crane";
inputs = {
nixpkgs.follows = "nixpkgs";
};
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
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-book = pkgs.callPackage ./book {};
hax-engine = pkgs.callPackage ./engine {
hax-rust-frontend = packages.hax-rust-frontend.unwrapped;
# `hax-engine-names-extract` extracts Rust names but also
# some informations about `impl`s when names are `impl`
# blocks. That includes some span information, which
# includes full paths to Rust sources. Sometimes those
# Rust sources happens to be in the Nix store. That
# creates useless dependencies, this wrapper below takes
# care of removing those extra depenedencies.
hax-engine-names-extract = pkgs.writeScriptBin "hax-engine-names-extract" ''
#!${pkgs.stdenv.shell}
${packages.hax-rust-frontend.hax-engine-names-extract}/bin/hax-engine-names-extract | sed 's|/nix/store/\(.\{6\}\)|/nix_store/\1-|g'
'';
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;
# The commit that corresponds to our nightly pin, helpful when updating rusrc.
toolchain_commit = pkgs.runCommand "hax-toolchain-commit" { } ''
# This is sad but I don't know a better way.
cat ${rustc}/share/doc/rust/html/version_info.html \
| grep 'github.com' \
| sed 's#.*"https://github.com/rust-lang/rust/commit/\([^"]*\)".*#\1#' \
> $out
'';
};
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 "$@"
''}";
};
serve-book = {
type = "app";
program = "${pkgs.writeScript "serve-book" ''
cd ${packages.hax-book}
${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
utils = pkgs.stdenv.mkDerivation {
name = "hax-dev-scripts";
phases = ["installPhase"];
installPhase = ''
mkdir -p $out/bin
cp ${./.utils/rebuild.sh} $out/bin/rebuild
cp ${./.utils/list-names.sh} $out/bin/list-names
cp ${./.utils/expand.sh} $out/bin/expand-hax-macros
'';
};
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
utils
];
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;
shellHook = ''echo "Commands available: $(ls ${utils}/bin | tr '\n' ' ')"'';
};
};
}
);
}