-
Notifications
You must be signed in to change notification settings - Fork 0
/
devenv.nix
147 lines (142 loc) · 4.14 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
{
pkgs,
lib,
config,
...
}: {
packages = with pkgs; [
nix-search-cli
nix-output-monitor
nix-melt
deploy-rs
];
languages.nix = {
enable = true;
lsp.package = pkgs.nil;
};
pre-commit.hooks = {
deadnix.enable = true;
alejandra.enable = true;
shellcheck.enable = true;
gitleaks = {
enable = true;
package = pkgs.gitleaks;
entry = "${pkgs.gitleaks}/bin/gitleaks detect --verbose";
pass_filenames = false;
};
lint = {
enable = true;
package = pkgs.statix;
entry = "nx-lint";
pass_filenames = false;
};
};
scripts = {
nx-inspect = {
exec = ''${pkgs.nix-inspect}/bin/nix-inspect "$@" '';
description = "Inspect the entire configuration, like a json tree";
};
browse-flake-lock = {
exec = ''
${pkgs.nix-melt}/bin/nix-melt
'';
description = "Browse the flake.lock contents";
};
nx-deploy-single = {
exec = ''
sudo ${pkgs.deploy-rs}/bin/deploy --remote-build --skip-checks --fast-connection=true .#$@ -- --extra-experimental-features pipe-operators --fallback
'';
};
nx-deploy = {
exec = ''
sudo -v
echo "$@" | ${pkgs.rush-parallel}/bin/rush -D " " "nx-deploy-single {}"
'';
};
nx-lint = {
exec = ''
${pkgs.coreutils}/bin/rm -rf "$DEVENV_ROOT/result"
${pkgs.statix}/bin/statix check
'';
description = "Lint the configuration";
};
nx-search = {
exec = ''
${pkgs.nix-search-cli}/bin/nix-search "$@"
'';
description = "Search for a package";
};
apply-local = {
exec = ''
nx-build && sudo nixos-rebuild switch --fast --flake .#$(hostname) || exit 1
'';
description = "Rebuild the system";
};
nx-build = {
exec = ''
sudo ${pkgs.nix-output-monitor}/bin/nom build .#nixosConfigurations.$(hostname).config.system.build.toplevel -L --extra-experimental-features pipe-operators
'';
description = "Build the system";
};
edit-secrets = {
exec = ''
sops secrets/secrets.yaml
'';
description = "Edit secrets";
};
nx-update = {
exec = ''
sudo nix-channel --update && nix flake update && git add . && git commit -m "Update flake.lock" && apply-local
'';
description = "Update the system";
};
colmena-apply = {
exec = ''
sudo colmena apply --on "$@" --verbose
'';
description = "Apply the configuration using colmena to the specified hosts (e.g. 'opi*,rzr,surface')";
};
colmena-apply-k8s = {
exec = ''
colmena-apply "opi1,opi2,opi3,opi4,rzr,smol,a21"
'';
description = "Apply the configuration using colmena to all Kubernetes nodes.";
};
build-on-apply-on = {
exec = ''
sudo nixos-rebuild --flake ".#$2" --target-host "$2" --verbose --build-host "$1" switch
'';
description = "Builds configuration on $/1 and applies it on $/2";
};
nx-diff = {
exec = ''
echo -e "---------- Building... ----------\n" && nx-build && echo -e "---------- Build finished. Computing diff... ---------- \n\n\n" && nvd diff /run/current-system result
'';
description = "Diff the current system with current configuration files";
};
help = {
exec = ''
echo
echo 🦾 Useful project scripts:
echo 🦾
${pkgs.gnused}/bin/sed -e 's| |••|g' -e 's|=| |' <<EOF | ${pkgs.util-linuxMinimal}/bin/column -t | ${pkgs.gnused}/bin/sed -e 's|^|🦾 |' -e 's|••| |g'
${lib.generators.toKeyValue {} (lib.mapAttrs (_: value: value.description) config.scripts)}
EOF
echo
'';
description = "Show this help message";
};
};
enterTest = ''
nix flake check
'';
enterShell = ''
echo
echo 🦾 Useful project scripts:
echo 🦾
${pkgs.gnused}/bin/sed -e 's| |••|g' -e 's|=| |' <<EOF | ${pkgs.util-linuxMinimal}/bin/column -t | ${pkgs.gnused}/bin/sed -e 's|^|🦾 |' -e 's|••| |g'
${lib.generators.toKeyValue {} (lib.mapAttrs (_: value: value.description) config.scripts)}
EOF
echo
'';
}