-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathflake.nix
More file actions
102 lines (95 loc) · 4.27 KB
/
Copy pathflake.nix
File metadata and controls
102 lines (95 loc) · 4.27 KB
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
{
description = "flake-explorer — interactive visualizer for Nix flakes (outputs/modules/options/files)";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
# Rust builds: buildDepsOnly compiles the dep tree once per Cargo.lock
# (only the crate itself rebuilds on source changes) and provides the
# cargoClippy/cargoLlvmCov check drivers. Lib-only flake, no inputs of
# its own; uses nixpkgs' stable rustc.
crane.url = "github:ipetkov/crane";
};
outputs =
inputs@{ flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
imports = [ inputs.treefmt-nix.flakeModule ];
systems = [
"aarch64-darwin"
"aarch64-linux"
"x86_64-linux"
];
perSystem =
{ pkgs, config, ... }:
{
packages = {
flake-explorer = pkgs.callPackage ./package.nix {
craneLib = inputs.crane.mkLib pkgs;
};
default = config.packages.flake-explorer;
};
checks = {
# cargo test/clippy/llvm-cov, all dev-profile: the suite runs in
# about two seconds and none of them has any use for optimised
# code (see package.nix for the layering that falls out of it).
# Coverage is a check (not just a CI step) so `nix flake check`
# exercises the instrumented build everywhere; CI additionally
# runs the out-of-sandbox variant (real nix, integration tests
# included) and reads its lcov for the octocov report.
test = config.packages.flake-explorer.passthru.checks.test;
clippy = config.packages.flake-explorer.passthru.checks.clippy;
coverage = config.packages.flake-explorer.passthru.checks.coverage;
# Offline `bun test` of the SPA against the vendored node_modules.
app-test = config.packages.flake-explorer.passthru.checks.app-test;
};
# `nix fmt` + checks.treefmt come from the flakeModule; Biome keeps
# owning TS/Svelte via its own biome.json, so treefmt covers Nix
# and Rust.
treefmt.programs.nixfmt.enable = true;
treefmt.programs.rustfmt.enable = true;
# nix itself is deliberately NOT in the shell or wrapper: the CLI
# must use the host's nix so store paths and the flake registry
# match the user's system (src/run_nix.rs checks for it at startup).
devShells.default = pkgs.mkShell {
# cargo-llvm-cov looks for rustup's llvm-tools-preview; point it
# at the LLVM that built this rustc instead (same pinning as the
# coverage check). CI's out-of-sandbox coverage run — the one
# that includes the real-nix integration tests — relies on these.
env = {
LLVM_COV = "${pkgs.rustc.llvmPackages.llvm}/bin/llvm-cov";
LLVM_PROFDATA = "${pkgs.rustc.llvmPackages.llvm}/bin/llvm-profdata";
};
packages =
builtins.attrValues {
inherit (pkgs)
bun
git
cargo
rustc
clippy
rustfmt
rust-analyzer
cargo-llvm-cov
;
}
++ [
config.treefmt.build.wrapper
# Live-source `flake-explorer`: builds and runs the enclosing
# checkout's crate (a flake only sees a store copy of itself,
# so the working tree must be resolved at call time).
(pkgs.writeShellScriptBin "flake-explorer" ''
root=$(git rev-parse --show-toplevel 2>/dev/null)
if [ ! -f "$root/Cargo.toml" ]; then
echo "flake-explorer(dev shim): no Cargo.toml at the git toplevel ('$root') — run inside the flake-explorer checkout" >&2
exit 1
fi
FLAKE_EXPLORER_PROG=flake-explorer exec cargo run --quiet --manifest-path "$root/Cargo.toml" -- "$@"
'')
];
};
};
};
}