forked from arnarg/nixidy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
183 lines (166 loc) · 5.64 KB
/
Copy pathflake.nix
File metadata and controls
183 lines (166 loc) · 5.64 KB
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
{
description = "ArgoCD application and Kubernetes manifest generator in Nix.";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
nix-kube-generators.url = "github:farcaller/nix-kube-generators";
};
outputs =
{
self,
nixpkgs,
flake-utils,
nix-kube-generators,
}:
{
lib = import ./make-env.nix {
kubelib = nix-kube-generators;
};
}
// (flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
};
mlib = import ./lib {
inherit pkgs;
kubelib = nix-kube-generators;
};
in
{
packages = {
inherit (mlib.helm) mkChartAttrs;
default = self.packages.${system}.cli;
cli = pkgs.callPackage ./cli { };
generators = import ./pkgs/generators {
inherit pkgs;
kubelib = nix-kube-generators;
};
};
libTests = import ./lib/tests.nix {
inherit pkgs;
kubelib = nix-kube-generators;
};
moduleTests =
(self.lib.mkEnv {
inherit pkgs;
modules = [
./modules/testing
./tests
];
}).config.testing;
apps = {
# Generates all generators and copies into place
generate =
let
generated = pkgs.linkFarm "generated-modules" [
{
name = "argocd.nix";
path = self.packages.${system}.generators.argocd;
}
{
name = "k8s";
path = self.packages.${system}.generators.k8s;
}
];
in
{
type = "app";
program =
(pkgs.writeShellScript "generate-modules" ''
set -eo pipefail
dest=./modules/generated
echo "generating modules..."
${pkgs.rsync}/bin/rsync \
--chmod=Du=rwx,Dg=rx,Do=rx,Fu=rw,Fg=r,Fo=r \
--copy-links --recursive --delete \
"${generated}/" "$dest"
echo "done!"
'').outPath;
};
# Runs statix for linting the nix code
staticCheck = {
type = "app";
program =
(pkgs.writeShellScript "static-lint-check" ''
set -eo pipefail
# Use a fancy jq filter to turn the JSON output
# into workflow commands for github actions.
# See: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-a-warning-message
if [ "$GITHUB_ACTIONS" = "true" ]; then
${pkgs.statix}/bin/statix check -o json . | \
${pkgs.jq}/bin/jq -r '.file as $file |
.report | map(
.severity as $severity |
.note as $note |
.diagnostics | map(
. + {
"file": $file,
"note": $note,
"severity": (
if $severity == "Error"
then "error"
else "warning"
end
)
}
)
) |
flatten | .[] |
"::\(.severity) file=\(.file),line=\(.at.from.line),col=\(.at.from.column),endLine=\(.at.to.line),endColumn=\(.at.to.column),title=\(.note)::\(.message)"
'
else
${pkgs.statix}/bin/statix check .
fi
'').outPath;
};
# Runs lib unit tests
libTests = {
type = "app";
program =
(pkgs.writeShellScript "lib-unit-tests" ''
set -eo pipefail
SYSTEM=$(nix eval --expr builtins.currentSystem --raw --impure)
${pkgs.nix-unit}/bin/nix-unit \
--extra-experimental-features flakes \
--flake "${self}#libTests.''${SYSTEM}"
'').outPath;
};
# Run module unit tests
moduleTests = {
type = "app";
program = self.moduleTests.${system}.reportScript.outPath;
};
# Run shellcheck on nixidy cli
cliTest = {
type = "app";
program =
(pkgs.writeShellScript "cli-shellcheck-test" ''
${pkgs.shellcheck}/bin/shellcheck ${self.packages.${system}.default}/bin/nixidy
'').outPath;
};
# Run tests for crd2jsonschema
crd2jsonschemaTest = {
type = "app";
program =
let
pythonWithYaml = pkgs.python3.withPackages (ps: [ ps.pyyaml ]);
in
(pkgs.writeShellScript "crd2jsonschema-test" ''
${pythonWithYaml}/bin/python ${self}/pkgs/generators/test_crd2jsonschema.py
'').outPath;
};
# Serve docs
docsServe = {
type = "app";
program =
(pkgs.writeShellScript "serve-docs" ''
${pkgs.python3}/bin/python -m http.server -d ${(import ./docs { inherit pkgs; }).html} 8080
'').outPath;
};
};
formatter = pkgs.nixfmt-tree;
}
));
}