-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfmt.nix
More file actions
123 lines (109 loc) · 2.99 KB
/
fmt.nix
File metadata and controls
123 lines (109 loc) · 2.99 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
{ pkgs }:
let
name = "fmt";
version = "0.0.1";
description = "Format code using various tools";
in
pkgs.stdenvNoCC.mkDerivation {
pname = name;
inherit version;
src = ./.;
dontBuild = true;
nativeBuildInputs = with pkgs; [
makeWrapper
];
buildInputs = with pkgs; [
nixfmt-rfc-style
nodePackages.prettier
nodePackages.eslint
shfmt
go
gotools # contains goimports
golangci-lint
python3Packages.black
python3Packages.isort
python3Packages.autopep8
rustfmt
zig
jq
yq-go
yamllint
sql-formatter
# PostgreSQL SQL syntax beautifier that can work as a console
# program or as a CGI
pgformatter
sqlfluff
taplo # TOML formatter
];
installPhase = ''
mkdir -p $out/bin
mkdir -p $out/share/fmt/config
# Copy the main script
cp scripts/${name} $out/bin/${name}
chmod +x $out/bin/${name}
# Copy shared configuration files (including hidden files)
if [ -d shared ]; then
find shared -maxdepth 1 -type f -exec cp {} $out/share/fmt/config/ \;
fi
# Create nixfmt-tree wrapper for directory formatting
cat > $out/bin/nixfmt-tree <<'EOF'
#!/usr/bin/env bash
set -euo pipefail
# Wrapper for nixfmt that recursively formats Nix files in directories
# This avoids the deprecated behavior of passing directories to nixfmt directly
ARGS=()
DIRS=()
for arg in "$@"; do
if [[ -d "$arg" ]]; then
DIRS+=("$arg")
else
ARGS+=("$arg")
fi
done
if [[ ''${#DIRS[@]} -gt 0 ]]; then
for dir in "''${DIRS[@]}"; do
find "$dir" -name "*.nix" -type f -exec nixfmt "''${ARGS[@]}" {} +
done
else
nixfmt "''${ARGS[@]}"
fi
EOF
chmod +x $out/bin/nixfmt-tree
# Wrap nixfmt-tree to ensure nixfmt is in PATH
wrapProgram $out/bin/nixfmt-tree \
--prefix PATH : ${pkgs.lib.makeBinPath [ pkgs.nixfmt-rfc-style ]}
# Wrap the script to ensure all dependencies are in PATH and set config path
wrapProgram $out/bin/${name} \
--prefix PATH : ${
pkgs.lib.makeBinPath [
pkgs.nixfmt-rfc-style
pkgs.nodePackages.prettier
pkgs.nodePackages.eslint
pkgs.shfmt
pkgs.go
pkgs.gotools
pkgs.golangci-lint
pkgs.python3Packages.black
pkgs.python3Packages.isort
pkgs.python3Packages.autopep8
pkgs.rustfmt
pkgs.zig
pkgs.jq
pkgs.yq-go
pkgs.yamllint
pkgs.sql-formatter
pkgs.pgformatter
pkgs.sqlfluff
pkgs.taplo
]
}:$out/bin \
--set FMT_CONFIG_DIR "$out/share/fmt/config"
runHook postInstall
'';
meta = with pkgs.lib; {
inherit description;
platforms = platforms.unix;
maintainers = [ ];
license = licenses.mit;
};
}