forked from cachix/devenv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
devenv.nix
163 lines (147 loc) · 5 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
{ inputs, pkgs, lib, config, ... }:
{
packages = [
(import ./src/devenv.nix { inherit pkgs; nix = inputs.nix; })
pkgs.cairo
pkgs.xorg.libxcb
pkgs.yaml2json
];
languages.nix.enable = true;
languages.python.enable = true;
languages.python.venv.enable = true;
languages.python.poetry.enable = true;
devcontainer.enable = true;
devcontainer.settings.customizations.vscode.extensions = [ "bbenoist.Nix" ];
difftastic.enable = true;
dotenv.enable = true;
processes.docs.exec = "mkdocs serve";
processes.build.exec = "${pkgs.watchexec}/bin/watchexec -e nix nix build";
scripts.devenv-bump-version.exec = ''
# TODO: ask for the new version
# TODO: update the version in the mkdocs.yml
echo assuming you bumped the version in mkdocs.yml, populating src/modules/latest-version
cat mkdocs.yml | yaml2json | jq -r '.extra.devenv.version' > src/modules/latest-version
'';
scripts.devenv-run-tests.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 ci
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 --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 --impure --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
nix build --impure .#container-processes
popd
rm -rf "$tmp"
# TODO: test DIRENV_ACTIVE
'';
scripts.devenv-test-all-examples.exec = ''
for dir in $(ls examples); do
devenv-test-example $dir
done
'';
scripts.devenv-test-example.exec = ''
# execute all trap_ function on exit
trap 'eval $(declare -F | grep -o "trap_[^ ]*" | tr "\n" ";")' EXIT
set -e
example="$PWD/examples/$1"
pushd $example
mv devenv.yaml devenv.yaml.orig
awk '
{ print }
/^inputs:$/ {
print " devenv:";
print " url: path:../../src/modules";
}
' devenv.yaml.orig > devenv.yaml
trap_restore_yaml() {
mv "$example/devenv.yaml.orig" "$example/devenv.yaml"
}
devenv ci
if [ -f .test.sh ]; then
trap_restore_local() {
rm "$example/devenv.local.nix"
rm -rf "$example/.devenv"
}
# coreutils-full provides timeout on darwin
echo "{ pkgs, ... }: { packages = [ pkgs.coreutils-full ]; }" > devenv.local.nix
devenv shell ./.test.sh
else
devenv shell ls
fi
popd
'';
scripts."devenv-generate-doc-options".exec = ''
set -e
options=$(nix build --impure --extra-experimental-features 'flakes nix-command' --show-trace --print-out-paths --no-link '.#devenv-docs-options')
echo "# devenv.nix options" > docs/reference/options.md
echo >> docs/reference/options.md
cat $options >> docs/reference/options.md
'';
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;
#markdownlint.enable = true;
};
pre-commit.settings.markdownlint.config = {
MD013 = {
line_length = 120;
};
MD033 = false;
MD034 = false;
};
}