-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathflake.nix
More file actions
138 lines (130 loc) · 4.2 KB
/
Copy pathflake.nix
File metadata and controls
138 lines (130 loc) · 4.2 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
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
{
description = "Bob the Builder — fast incremental builds on top of Nix";
inputs = {
nixpkgs.url = "https://channels.nixos.org/nixpkgs-unstable/nixexprs.tar.xz";
devshell = {
url = "github:numtide/devshell";
inputs.nixpkgs.follows = "nixpkgs";
};
cargo-nix-plugin = {
url = "github:Mic92/cargo-nix-plugin";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
devshell,
cargo-nix-plugin,
}:
let
systems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
forAllSystems =
f:
nixpkgs.lib.genAttrs systems (
system: f (nixpkgs.legacyPackages.${system}.extend devshell.overlays.default)
);
# nix-instantiate with `builtins.resolveCargoWorkspace` available, for
# `BOB_NIX_INSTANTIATE`. The plugin ABI is tied to the exact Nix it was
# built against, so pair the 2.34 plugin with 2.34 nix from the same
# nixpkgs rather than whatever the host has. Only exposed where
# cargo-nix-plugin actually ships a build (no x86_64-darwin).
bobNixInstantiate =
pkgs:
let
system = pkgs.stdenv.hostPlatform.system;
in
nixpkgs.lib.optionalAttrs (cargo-nix-plugin.packages ? ${system}) {
bob-nix-instantiate = pkgs.writeShellScriptBin "nix-instantiate" ''
exec ${pkgs.nixVersions.nix_2_34}/bin/nix-instantiate \
--option plugin-files ${
cargo-nix-plugin.packages.${system}.cargo-nix-plugin-nix_2_34
}/lib/nix/plugins \
"$@"
'';
};
in
{
packages = forAllSystems (
pkgs:
{
inherit (import ./default.nix { inherit pkgs; }) bob default;
}
// bobNixInstantiate pkgs
);
devShells = forAllSystems (pkgs: {
default = pkgs.devshell.mkShell {
# devshell installs bin/<name> -> entrypoint, which would shadow
# the actual `bob` binary on PATH. Use a distinct name.
name = "bob-dev";
packages = with pkgs; [
cargo
rustc
rustfmt
clippy
rust-analyzer
];
env = [
{
name = "RUST_SRC_PATH";
value = "${pkgs.rustPlatform.rustLibSrc}";
}
]
++ nixpkgs.lib.mapAttrsToList (_: drv: {
name = "BOB_NIX_INSTANTIATE";
value = "${drv}/bin/nix-instantiate";
}) (bobNixInstantiate pkgs);
commands = [
{
name = "fmt";
help = "format nix + rust";
command = ''
${pkgs.lib.getExe pkgs.nixfmt-tree} "$PRJ_ROOT"
cargo fmt --manifest-path "$PRJ_ROOT/Cargo.toml"
'';
}
{
name = "lint";
help = "cargo clippy";
command = ''cargo clippy --manifest-path "$PRJ_ROOT/Cargo.toml" -- -D warnings'';
}
];
};
});
checks = forAllSystems (pkgs: {
inherit (self.packages.${pkgs.stdenv.hostPlatform.system}) bob;
fmt =
pkgs.runCommand "cargo-fmt-check"
{
nativeBuildInputs = [
pkgs.cargo
pkgs.rustfmt
];
}
''
cd ${./.}
cargo fmt --check
touch $out
'';
# bob-core must stay language-agnostic. Fail if any Rust-backend
# identifier appears outside of doc comments.
core-leakage = pkgs.runCommand "bob-core-leakage" { nativeBuildInputs = [ pkgs.ripgrep ]; } ''
cd ${./crates/core/src}
if rg --no-heading --line-number --pcre2 \
'^(?!\s*//).*\b(crateName|crateType|crateLinks|crateVersion|libName|rustc|rlib|EXTRA_RUSTC_FLAGS|__rustc-wrap|buildRustCrate|Cargo\.(toml|lock))\b' \
. ; then
echo "error: Rust-backend identifiers found in bob-core (see above)" >&2
exit 1
fi
touch $out
'';
});
formatter = forAllSystems (pkgs: pkgs.nixfmt-tree);
};
}