-
Notifications
You must be signed in to change notification settings - Fork 6
/
formatter.nix
65 lines (57 loc) · 1.18 KB
/
formatter.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
{
pname,
pkgs,
flake,
}:
let
formatter = pkgs.writeShellApplication {
name = pname;
runtimeInputs = [
pkgs.deadnix
pkgs.nixfmt-rfc-style
];
text = ''
set -euo pipefail
set -x
deadnix --no-lambda-pattern-names --edit "$@"
nixfmt "$@"
'';
meta = {
description = "format your project";
};
};
check =
pkgs.runCommand "format-check"
{
nativeBuildInputs = [
formatter
pkgs.git
];
# only check on Linux
meta.platforms = pkgs.lib.platforms.linux;
}
''
export HOME=$NIX_BUILD_TOP/home
# keep timestamps so that treefmt is able to detect mtime changes
cp --no-preserve=mode --preserve=timestamps -r ${flake} source
cd source
git init --quiet
git add .
shopt -s globstar
${pname} **/*.nix
if ! git diff --exit-code; then
echo "-------------------------------"
echo "aborting due to above changes ^"
exit 1
fi
touch $out
'';
in
formatter
// {
passthru = formatter.passthru // {
tests = {
check = check;
};
};
}