forked from cryspen/hax
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
151 lines (147 loc) · 4.79 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
{
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;
in rec {
packages = {
inherit rustc ocamlformat rustfmt fstar;
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;
};
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}";
packages = packages ++ [fstar];
};
default = pkgs.mkShell {
inherit packages inputsFrom LIBCLANG_PATH;
};
};
}
);
}