-
Notifications
You must be signed in to change notification settings - Fork 0
/
devenv.nix
137 lines (122 loc) · 4.39 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
{ 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.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;
languages.python.venv.enable = true;
languages.python.venv.requirements = ./requirements.txt;
devcontainer.enable = true;
devcontainer.settings.customizations.vscode.extensions = [ "jnoortheen.nix-ide" ];
difftastic.enable = true;
dotenv.enable = true;
processes.docs.exec = "mkdocs serve";
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-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 --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
if $(uname) == "Linux"
then
nix build --impure --accept-flake-config --show-trace .#container-processes
fi
popd
rm -rf "$tmp"
'';
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;
#clippy.enable = true;
rustfmt.enable = true;
#markdownlint.enable = true;
};
pre-commit.settings.markdownlint.config = {
MD013 = {
line_length = 120;
};
MD033 = false;
MD034 = false;
};
}