-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathflake.nix
227 lines (220 loc) · 6.88 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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
crane = {
url = "github:ipetkov/crane";
};
flake-utils = {
url = "github:numtide/flake-utils";
};
advisory-db = {
url = "github:rustsec/advisory-db";
flake = false;
};
flake-compat = {
url = "github:edolstra/flake-compat";
};
};
outputs =
{
self,
flake-utils,
nixpkgs,
rust-overlay,
crane,
advisory-db,
...
}:
flake-utils.lib.eachDefaultSystem (
system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs { inherit system overlays; };
filteredSource =
let
pathsToIgnore = [
".envrc"
".ignore"
".github"
".gitignore"
"rust-toolchain.toml"
"README.md"
"flake.nix"
"flake.lock"
"target"
"LICENCE"
".direnv"
];
ignorePaths =
path: type:
let
inherit (nixpkgs) lib;
# split the nix store path into its components
components = lib.splitString "/" path;
# drop off the `/nix/hash-source` section from the path
relPathComponents = lib.drop 4 components;
# reassemble the path components
relPath = lib.concatStringsSep "/" relPathComponents;
in
lib.all (p: !(lib.hasPrefix p relPath)) pathsToIgnore;
in
builtins.path {
name = "mania-source";
path = toString ./.;
# filter out unnecessary paths
filter = ignorePaths;
};
stdenv = if pkgs.stdenv.isLinux then pkgs.stdenv else pkgs.clangStdenv;
rustToolchain = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
env =
let
inherit (pkgs) lib libclang;
version = lib.getVersion libclang;
majorVersion = lib.versions.major version;
in
{
BINDGEN_EXTRA_CLANG_ARGS = "-isystem ${libclang.lib}/lib/clang/${majorVersion}/include";
LIBCLANG_PATH = lib.makeLibraryPath [ libclang.lib ];
};
commonArgs = {
inherit stdenv env;
inherit (craneLib.crateNameFromCargoToml { cargoToml = ./mania/Cargo.toml; }) pname;
inherit (craneLib.crateNameFromCargoToml { cargoToml = ./Cargo.toml; }) version;
src = filteredSource;
strictDeps = true;
depsBuildBuild = with pkgs; [
protobuf
pkg-config
];
nativeBuildInputs = with pkgs; [
libclang.lib
openssl.dev
];
doCheck = false;
meta = {
mainProgram = "mania";
homepage = "https://github.com/LagrangeDev/mania";
license = pkgs.lib.licenses.gpl3Only;
};
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
typoCheck =
pkgs.runCommandNoCCLocal "check-typo"
{
src = ./.;
nativeBuildInputs = with pkgs; [ typos ];
}
''
mkdir -p $out
cd $src
typos --config ./typos.toml
'';
fmtCheck =
let
restFmtCheck =
pkgs.runCommandNoCCLocal "check-fmt"
{
src = ./.;
nativeBuildInputs = with pkgs; [
taplo
nixfmt-rfc-style
deno
just
shfmt
];
}
''
mkdir -p $out
cd $src
# just
echo '==> just format check'
just --unstable --fmt --check
# markdown
echo '==> markdown format check'
find . -type f -regextype egrep -regex '^.*\.md$' -exec deno fmt --check --ext md {} +
# toml
echo '==> toml format check'
find . -type f -regextype egrep -regex '^.*\.toml$' -exec taplo format --check {} +
# yaml
echo '==> yaml format check'
find . -type f -regextype egrep -regex '^.*\.yml$' -exec deno fmt --check --ext yml {} +
# nix
echo '==> nix format check'
find . -type f -regextype egrep -regex '^.*\.nix$' -exec nixfmt --check {} +
# sh
echo '==> sh format check'
cd ./scripts && find . -type f -executable -exec shfmt -p -s -d -i 2 -ci -sr -kp -fn '{}' +
'';
in
pkgs.symlinkJoin {
name = "fmtCheck";
paths = [
restFmtCheck
(craneLib.cargoFmt commonArgs)
];
};
in
{
packages = {
mania = craneLib.buildPackage (
commonArgs
// {
inherit cargoArtifacts;
cargoExtraArgs = ''
--example mania_multi_login
'';
postInstall = ''
mkdir -p $out/bin
cp ./target/release/examples/mania_multi_login $out/bin/mania
'';
}
);
default = self.packages."${system}".mania;
};
checks = {
inherit (self.packages."${system}") mania;
typo = typoCheck;
audit = craneLib.cargoAudit (commonArgs // { inherit advisory-db; });
clippy = craneLib.cargoClippy (
commonArgs
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
}
);
fmt = fmtCheck;
doc = craneLib.cargoDoc (commonArgs // { inherit cargoArtifacts; });
test = craneLib.cargoTest (commonArgs // { inherit cargoArtifacts; });
};
devShells.default = pkgs.mkShell {
inherit env;
inputsFrom = builtins.attrValues self.checks."${system}";
packages = with pkgs; [
# deps
protobuf
pkg-config
# dev
rust-analyzer
cargo-flamegraph
cargo-tarpaulin
lldb
# fmt
taplo
nixfmt-rfc-style
deno
just
shfmt
];
shellHook = '''';
};
}
)
// {
overlays.default = final: prev: { inherit (self.packages."${final.system}") mania; };
};
}