-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathflake.nix
158 lines (142 loc) · 4.55 KB
/
flake.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
{
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";
kubenix = {
url = "github:hall/kubenix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = {
self,
nixpkgs,
flake-utils,
nix-kube-generators,
kubenix,
}:
{
lib = import ./make-env.nix {
inherit kubenix;
kubelib = nix-kube-generators;
};
}
// (flake-utils.lib.eachDefaultSystem (system: let
pkgs = import nixpkgs {
inherit system;
};
packages = import ./nixidy pkgs;
in {
packages = {
default = packages.nixidy;
generators = import ./pkgs/generators {inherit pkgs;};
};
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 = {
type = "app";
program = with pkgs.lib;
(pkgs.writeShellScript "generate-modules" ''
set -eo pipefail
dest=./modules/generated
${concatStringsSep "\n" (mapAttrsToList (
n: mod: ''
echo "generating ${n}"
cat ${mod} > $dest/${n}.nix
''
) (removeAttrs self.packages.${system}.generators ["fromCRD"]))}
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;
};
# 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;
};
};
}));
}