-
Notifications
You must be signed in to change notification settings - Fork 339
/
devenv.nix
254 lines (226 loc) · 8.34 KB
/
devenv.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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
{ inputs, pkgs, lib, config, ... }: {
env.DEVENV_NIX = inputs.nix.packages.${pkgs.stdenv.system}.nix;
# ignore annoying browserlists warning that breaks pre-commit hooks
env.BROWSERSLIST_IGNORE_OLD_DATA = "1";
env.RUST_LOG = "devenv=debug";
env.RUST_LOG_SPAN_EVENTS = "full";
env.DATABASE_URL = "sqlite:.devenv/nix-eval-cache.db";
packages = [
pkgs.cairo
pkgs.git
pkgs.xorg.libxcb
pkgs.yaml2json
pkgs.tesh
pkgs.watchexec
pkgs.openssl
pkgs.sqlx-cli
] ++ lib.optionals pkgs.stdenv.isDarwin (with pkgs.darwin.apple_sdk; [
frameworks.SystemConfiguration
]);
languages.nix.enable = true;
# for cli
languages.rust.enable = true;
# for docs
languages.python.enable = true;
# it breaks glibc
languages.python.manylinux.enable = false;
# speed it up
languages.python.uv.enable = true;
languages.python.venv.enable = true;
languages.python.venv.requirements = ./requirements.txt;
languages.javascript.enable = true;
languages.javascript.npm.enable = true;
languages.javascript.npm.install.enable = true;
devcontainer.enable = true;
devcontainer.settings.customizations.vscode.extensions = [ "jnoortheen.nix-ide" ];
difftastic.enable = true;
processes = {
docs.exec = "mkdocs serve";
tailwind.exec = "watchexec -e html,css,js devenv-generate-doc-css";
};
scripts.devenv-test-cli = {
description = "Test devenv CLI.";
exec = ''
set -xe
set -o pipefail
pushd examples/simple
# this should fail since files already exist
devenv init && exit 1
popd
tmp="$(mktemp -d)"
devenv init "$tmp"
pushd "$tmp"
devenv version
devenv --override-input devenv path:${config.devenv.root}?dir=src/modules test
popd
rm -rf "$tmp"
# Test devenv integrated into bare Nix flake
tmp="$(mktemp -d)"
pushd "$tmp"
nix flake init --template ''${DEVENV_ROOT}#simple
nix flake update \
--override-input devenv ''${DEVENV_ROOT}
nix develop --accept-flake-config --no-pure-eval --command echo nix-develop started succesfully |& tee ./console
grep -F 'nix-develop started succesfully' <./console
grep -F "$(${lib.getExe pkgs.hello})" <./console
# Assert that nix-develop fails in pure mode.
if nix develop --command echo nix-develop started in pure mode |& tee ./console
then
echo "nix-develop was able to start in pure mode. This is explicitly not supported at the moment."
exit 1
fi
grep -F 'devenv was not able to determine the current directory.' <./console
popd
rm -rf "$tmp"
# Test devenv integrated into flake-parts Nix flake
tmp="$(mktemp -d)"
pushd "$tmp"
nix flake init --template ''${DEVENV_ROOT}#flake-parts
nix flake update \
--override-input devenv ''${DEVENV_ROOT}
nix develop --accept-flake-config --override-input devenv-root "file+file://"<(printf %s "$PWD") --command echo nix-develop started succesfully |& tee ./console
grep -F 'nix-develop started succesfully' <./console
grep -F "$(${lib.getExe pkgs.hello})" <./console
# Test that a container can be built
if $(uname) == "Linux"
then
nix build --override-input devenv-root "file+file://"<(printf %s "$PWD") --accept-flake-config --show-trace .#container-processes
fi
popd
rm -rf "$tmp"
'';
};
scripts."devenv-generate-doc-css" = {
description = "Generate CSS for the docs.";
exec = "${lib.getExe pkgs.tailwindcss} build -i docs/assets/extra.css -o docs/assets/output.css";
};
scripts."devenv-generate-doc-options" = {
description = "Generate option docs.";
exec = ''
set -e
output_file=docs/reference/options.md
options=$(nix build --accept-flake-config --no-pure-eval --extra-experimental-features 'flakes nix-command' --show-trace --print-out-paths --no-link '.#devenv-docs-options')
echo "[comment]: # (DO NOT MODIFY. This file was generated by devenv-generate-doc-options.)" > $output_file
echo "# devenv.nix" >> $output_file
echo >> $output_file
cat $options >> $output_file
# https://github.com/NixOS/nixpkgs/issues/224661
sed -i 's/\\\././g' $output_file
'';
};
scripts."devenv-generate-languages-example" = {
description = "Generate an example enabling every supported language.";
exec = ''
cat > examples/supported-languages/devenv.nix <<EOF
# DO NOT MODIFY.
# This file was generated bu devenv-generate-languages-example.
{ pkgs, ... }: {
# Enable all languages tooling!
${lib.concatStringsSep "\n " (map (lang: "languages.${lang}.enable = true;") (builtins.attrNames config.languages))}
# If you're missing a language, please contribute it by following examples of other languages <3
}
EOF
'';
};
scripts."devenv-generate-docs" = {
description = "Generate lists of all languages and services.";
exec = ''
cat > docs/services-all.md <<EOF
\`\`\`nix
${lib.concatStringsSep "\n " (map (lang: "services.${lang}.enable = true;") (builtins.attrNames config.services))}
\`\`\`
EOF
cat > docs/languages-all.md <<EOF
\`\`\`nix
${lib.concatStringsSep "\n " (map (lang: "languages.${lang}.enable = true;") (builtins.attrNames config.languages))}
\`\`\`
EOF
'';
};
scripts."devenv-generate-individual-docs" = {
description = "Generate individual docs of all devenv modules";
exec = ''
mkdir -p docs/{supported-languages,supported-services,supported-process-managers}
nix build --no-pure-eval --extra-experimental-features 'flakes nix-command' --show-trace --print-out-paths '.#devenv-generate-individual-docs'
cp -r --no-preserve=all result/docs/individual-docs/* docs/
'';
};
scripts."devenv-verify-individual-docs" = {
description = "Generate missing template markdown files";
exec = ''
process_directory() {
local nix_dir=$1
local md_dir=$2
local category=$3
nixFiles=($(ls $nix_dir/*.nix))
mdFiles=($(ls $md_dir/*.md))
declare -a nixList
declare -a mdList
# Remove extensions and populate lists
for file in "''${nixFiles[@]}"; do
baseName=$(basename "$file" .nix)
nixList+=("$baseName")
done
for file in "''${mdFiles[@]}"; do
baseName=$(basename "$file" .md)
mdList+=("$baseName")
done
IFS=$'\n' sorted_nix=($(sort <<<"''${nixList[*]}"))
IFS=$'\n' sorted_md=($(sort <<<"''${mdList[*]}"))
# Compare and create missing files
missing_files=()
for item in "''${sorted_nix[@]}"; do
if [[ ! " ''${sorted_md[@]} " =~ " $item " ]]; then
missing_files+=("$item")
cat << EOF > "$md_dir/$item.md"
[comment]: # (Please add your documentation on top of this line)
@AUTOGEN_OPTIONS@
EOF
echo "Created missing file: $md_dir/$item.md"
fi
done
if [ ''${#missing_files[@]} -eq 0 ]; then
echo "All $category docs markdown files are present."
fi
}
process_directory "src/modules/languages" "docs/individual-docs/languages" "language"
process_directory "src/modules/services" "docs/individual-docs/services" "service"
process_directory "src/modules/process-managers" "docs/individual-docs/process-managers" "process manager"
'';
};
tasks = {
"devenv:compile-requirements" = {
exec = "uv pip compile requirements.in -o requirements.txt";
before = [ "devenv:python:virtualenv" ];
status = ''
get_last_modified() {
stat -c %Y $1 2>/dev/null || stat -f %m $1 2>/dev/null || echo 0
}
input=$(get_last_modified "requirements.in")
output=$(get_last_modified "requirements.txt")
if [[ $output -eq 0 || $input -gt $output ]]; then
exit 1
fi
'';
};
};
pre-commit.hooks = {
nixpkgs-fmt.enable = true;
#shellcheck.enable = true;
#clippy.enable = true;
rustfmt.enable = true;
#markdownlint.enable = true;
markdownlint.settings.configuration = {
MD013 = {
line_length = 120;
};
MD033 = false;
MD034 = false;
};
generate-doc-css = {
enable = true;
name = "generate-doc-css";
entry = config.scripts."devenv-generate-doc-css".exec;
};
};
}