-
Notifications
You must be signed in to change notification settings - Fork 9
/
flake.nix
131 lines (120 loc) · 4.11 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
{
description = "ngrok agent library in Java";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
# Note: fenix packages are cached via cachix:
# cachix use nix-community
fenix-flake = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-utils = {
url = "github:numtide/flake-utils";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, fenix-flake, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
fenix-flake.overlays.default
];
};
rust-toolchain = pkgs.fenix.complete.withComponents [
"cargo"
"clippy"
"rust-src"
"rustc"
"rustfmt"
"rust-analyzer"
];
java-toolchain = with pkgs; [
openjdk17_headless
openjdk11_headless
maven
];
fix-n-fmt = pkgs.writeShellScriptBin "fix-n-fmt" ''
set -euf -o pipefail
${rust-toolchain}/bin/cargo clippy --fix --allow-staged --allow-dirty --all-targets --all-features
${rust-toolchain}/bin/cargo fmt
'';
pre-commit = pkgs.writeShellScript "pre-commit" ''
cargo clippy --workspace --all-targets --all-features -- -D warnings
result=$?
if [[ ''${result} -ne 0 ]] ; then
cat <<\EOF
There are some linting issues, try `fix-n-fmt` to fix.
EOF
exit 1
fi
# Use a dedicated sub-target-dir for udeps. For some reason, it fights with clippy over the cache.
CARGO_TARGET_DIR=$(git rev-parse --show-toplevel)/target/udeps cargo udeps --workspace --all-targets --all-features
result=$?
if [[ ''${result} -ne 0 ]] ; then
cat <<\EOF
There are some unused dependencies.
EOF
exit 1
fi
diff=$(cargo fmt -- --check)
result=$?
if [[ ''${result} -ne 0 ]] ; then
cat <<\EOF
There are some code style issues, run `fix-n-fmt` first.
EOF
exit 1
fi
exit 0
'';
setup-hooks = pkgs.writeShellScriptBin "setup-hooks" ''
repo_root=$(git rev-parse --git-dir)
${toString (map (h: ''
ln -sf ${h} ''${repo_root}/hooks/${h.name}
'') [
pre-commit
])}
'';
# Make sure that cargo semver-checks uses the stable toolchain rather
# than the nightly one that we normally develop with.
semver-checks = with pkgs; symlinkJoin {
name = "cargo-semver-checks";
paths = [ cargo-semver-checks ];
buildInputs = [ makeWrapper ];
postBuild = ''
wrapProgram $out/bin/cargo-semver-checks \
--prefix PATH : ${rustc}/bin \
--prefix PATH : ${cargo}/bin
'';
};
extract-version = with pkgs; writeShellScriptBin "extract-crate-version" ''
${cargo}/bin/cargo metadata --format-version 1 --no-deps | \
${jq}/bin/jq -r ".packages[] | select(.name == \"$1\") | .version"
'';
in
{
devShell = pkgs.mkShell {
CHALK_OVERFLOW_DEPTH = 3000;
CHALK_SOLVER_MAX_SIZE = 1500;
OPENSSL_LIB_DIR = "${pkgs.openssl.out}/lib";
OPENSSL_INCLUDE_DIR = "${pkgs.openssl.dev}/include";
RUSTC_WRAPPER="${pkgs.sccache}/bin/sccache";
JAVA_11_HOME = "${pkgs.openjdk11_headless}";
JAVA_17_HOME = "${pkgs.openjdk17_headless}";
buildInputs = with pkgs; [
rust-toolchain
java-toolchain
fix-n-fmt
setup-hooks
cargo-udeps
semver-checks
extract-version
] ++ lib.optionals stdenv.isDarwin [
# nix darwin stdenv has broken libiconv: https://github.com/NixOS/nixpkgs/issues/158331
libiconv
pkgs.darwin.apple_sdk.frameworks.Security
];
};
});
}