-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
100 lines (89 loc) · 2.62 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
{
description = "A command-line tool for patching shell scripts";
inputs = {
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-compat.follows = "";
inputs.rust-overlay.follows = "";
};
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.rust-analyzer-src.follows = "";
};
flake-parts = {
url = "github:hercules-ci/flake-parts";
inputs.nixpkgs-lib.follows = "nixpkgs";
};
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
};
outputs = inputs@{ crane, flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [
"aarch64-darwin"
"aarch64-linux"
"x86_64-darwin"
"x86_64-linux"
];
perSystem = { inputs', lib, pkgs, self', system, ... }:
let
inherit (lib)
optional
sourceByRegex
;
inherit (crane.lib.${system}.overrideToolchain inputs'.fenix.packages.default.toolchain)
buildDepsOnly
buildPackage
cargoClippy
cargoFmt
cargoNextest
;
inherit (pkgs)
coreutils
libiconv
nixpkgs-fmt
runCommand
stdenv
;
custom = runCommand "custom" { } ''
mkdir -p $out/bin
touch $out/bin/{'foo$','foo"`'}
chmod +x $out/bin/{'foo$','foo"`'}
'';
args = {
src = sourceByRegex ./. [
"(src|tests)(/.*)?"
"Cargo\\.(toml|lock)"
''rustfmt\.toml''
];
buildInputs = optional stdenv.isDarwin libiconv;
checkInputs = [ custom ];
cargoArtifacts = buildDepsOnly args;
doInstallCargoArtifacts = false;
postPatch = ''
for file in tests/fixtures/*-expected.sh; do
substituteInPlace $file \
--subst-var-by cc ${stdenv.cc} \
--subst-var-by coreutils ${coreutils} \
--subst-var-by custom ${custom}
done
'';
};
in
{
checks = {
build = self'.packages.default;
clippy = cargoClippy (args // {
cargoClippyExtraArgs = "-- -D warnings";
});
fmt = cargoFmt args;
test = cargoNextest args;
};
formatter = nixpkgs-fmt;
packages.default = buildPackage (args // {
doCheck = false;
});
};
};
}