-
Notifications
You must be signed in to change notification settings - Fork 4
/
flake.nix
202 lines (185 loc) · 6.46 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
{
description = "a minimal WASM interpreter";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05";
nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
typst-packages = {
url = "github:typst/packages";
flake = false;
};
typix = {
url = "github:loqusion/typix";
inputs.nixpkgs.follows = "nixpkgs-unstable";
};
utils.url = "git+https://github.com/numtide/flake-utils.git";
devshell.url = "github:numtide/devshell";
fenix = {
url = "git+https://github.com/nix-community/fenix.git?ref=main";
inputs.nixpkgs.follows = "nixpkgs";
};
naersk = {
url = "git+https://github.com/nix-community/naersk.git";
inputs.nixpkgs.follows = "nixpkgs";
};
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, utils, naersk, devshell, treefmt-nix, ... }@inputs:
utils.lib.eachSystem [ "x86_64-linux" "i686-linux" "aarch64-linux" ] (system:
let
lib = nixpkgs.lib;
pkgs = import nixpkgs {
inherit system;
overlays = [
devshell.overlays.default
# We unfortunately need the most up-to-date typst
(final: prev: {
typst = inputs.nixpkgs-unstable.legacyPackages.${pkgs.hostPlatform.system}.typst;
})
];
};
# universal formatter
treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;
# rust target name of the `system`
rust-target = pkgs.pkgsStatic.targetPlatform.rust.rustcTarget;
# Rust distribution for our hostSystem
fenix = inputs.fenix.packages.${system};
rust-toolchain = with fenix; combine [
latest.rustc
latest.cargo
latest.clippy
latest.rustfmt
targets.${rust-target}.latest.rust-std
targets.thumbv6m-none-eabi.latest.rust-std # for no_std test
targets.wasm32-unknown-unknown.latest.rust-std
];
# overrides a naersk-lib which uses the stable toolchain expressed above
naersk-lib = (naersk.lib.${system}.override {
cargo = rust-toolchain;
rustc = rust-toolchain;
});
typstPackagesCache = pkgs.stdenv.mkDerivation {
name = "typst-packages-cache";
src = inputs.typst-packages;
dontBuild = true;
installPhase = ''
mkdir -p "$out/typst/packages"
cp --dereference --no-preserve=mode --recursive --reflink=auto \
--target-directory="$out/typst/packages" -- "$src"/packages/*
'';
};
in
{
# packages
packages.wasm-interpreter = pkgs.callPackage pkgs/wasm-interpreter.nix { };
packages.whitepaper = inputs.typix.lib.${system}.buildTypstProject {
name = "whitepaper.pdf";
src = ./whitepaper;
XDG_CACHE_HOME = typstPackagesCache;
};
packages.report = pkgs.callPackage pkgs/report.nix {
inherit (self.packages.${system}) wasm-interpreter whitepaper;
};
# a devshell with all the necessary bells and whistles
devShells.default = (pkgs.devshell.mkShell {
imports = [ "${devshell}/extra/git/hooks.nix" ];
name = "wasm-interpreter";
packages = with pkgs; [
stdenv.cc
coreutils
rust-toolchain
rust-analyzer
cargo-audit
cargo-expand
cargo-llvm-cov
cargo-outdated
cargo-udeps
cargo-watch
nodePackages.prettier
strictdoc
wabt
# utilities
nixpkgs-fmt
nodePackages.prettier
treefmtEval.config.build.wrapper
typst # for the whitepaper
];
env = [
{
name = "LLVM_COV";
value = self.packages.${system}.wasm-interpreter.LLVM_COV;
}
{
name = "LLVM_PROFDATA";
value = self.packages.${system}.wasm-interpreter.LLVM_PROFDATA;
}
];
git.hooks = {
enable = true;
pre-commit.text = "nix flake check";
};
commands = [
{
name = "requirements-export-excel";
command = ''
strictdoc export --output-dir "$PRJ_ROOT/requirements/export" \
--formats=excel \
"$PRJ_ROOT/requirements"
'';
help = "export the requirements to requirements/export";
}
{
name = "requirements-export-html";
command = ''
strictdoc export --output-dir "$PRJ_ROOT/requirements/export" \
--formats=html \
"$PRJ_ROOT/requirements"
'';
help = "export the requirements to requirements/export";
}
{
name = "requirements-web-server";
command = ''
strictdoc server "$PRJ_ROOT/requirements"
'';
help = "start the requirements editor web-ui";
}
{
name = "cargo-watch-doc";
command = ''
cargo watch --shell 'cargo doc --document-private-items'
'';
help = "start cargo watch loop for documentation";
}
{
name = "whitepaper-watch";
command = ''
typst watch --root "$PRJ_ROOT/whitepaper" "$PRJ_ROOT/whitepaper/main.typ"
'';
help = "start typst watch loop for the whitepaper";
}
];
});
# for `nix fmt`
formatter = treefmtEval.config.build.wrapper;
# always check these
checks = {
formatting = treefmtEval.config.build.check self;
# TODO remove once https://github.com/numtide/treefmt/issues/153 is closed
format-bug-fix = pkgs.runCommand "yaml-fmt"
{
nativeBuildInputs = [ pkgs.nodePackages.prettier ];
} "cd ${./.} && prettier --check .github; touch $out";
requirements = pkgs.runCommand "check-requirement"
{
nativeBuildInputs = [ pkgs.strictdoc ];
} ''
shopt -s globstar
strictdoc passthrough ${./.}/requirements/**.sdoc
touch $out
'';
};
});
}