forked from cachix/devenv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
devenv.nix
150 lines (135 loc) · 4.84 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
{ inputs, pkgs, lib, config, ... }:
{
env.DEVENV_NIX = inputs.nix.packages.${pkgs.stdenv.system}.nix;
packages = [
pkgs.cairo
pkgs.xorg.libxcb
pkgs.yaml2json
pkgs.tesh
pkgs.watchexec
pkgs.openssl
] ++ 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;
dotenv.enable = true;
processes = {
docs.exec = "mkdocs serve";
tailwind.exec = "watchexec -e html,css,js npx tailwindcss build docs/assets/extra.css -o docs/assets/output.css";
};
scripts.devenv-test-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 --impure --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-options".exec = ''
set -e
output_file=docs/reference/options.md
options=$(nix build --impure --extra-experimental-features 'flakes nix-command' --show-trace --print-out-paths --no-link '.#devenv-docs-options')
echo "# devenv.nix options" > $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".exec = ''
cat > examples/supported-languages/devenv.nix <<EOF
{ 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".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
'';
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-css = {
enable = true;
name = "generate-css";
entry = "npx tailwindcss build docs/assets/extra.css -o docs/assets/output.css";
};
};
}