Repository navigation
Expand file tree
/
Copy pathflake.nix
More file actions
227 lines (227 loc) · 9.83 KB
/
Copy pathflake.nix
File metadata and controls
227 lines (227 loc) · 9.83 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
{
description = "NixOS Homelab Monitoring Workloads";
inputs = {
systems.url = "github:nix-systems/default-linux";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-26.05";
flake-parts.url = "github:hercules-ci/flake-parts";
kube-generators.url = "github:farcaller/nix-kube-generators";
setup-secrets = {
url = "github:andsens/nixos-setup-secrets";
inputs.systems.follows = "systems";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-parts.follows = "flake-parts";
};
homelab-shared = {
url = "github:nixos-homelab/shared";
inputs.systems.follows = "systems";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-parts.follows = "flake-parts";
inputs.setup-secrets.follows = "setup-secrets";
inputs.kube-generators.follows = "kube-generators";
inputs.homelab-monitoring.follows = "";
};
homelab-storage = {
url = "github:nixos-homelab/storage";
inputs.systems.follows = "systems";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-parts.follows = "flake-parts";
inputs.setup-secrets.follows = "setup-secrets";
inputs.kube-generators.follows = "kube-generators";
inputs.homelab-shared.follows = "homelab-shared";
inputs.homelab-monitoring.follows = "";
inputs.docs.follows = "docs";
};
docs = {
url = "github:andsens/nix-docs";
inputs.systems.follows = "systems";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-parts.follows = "flake-parts";
};
};
outputs =
{
systems,
flake-parts,
nixpkgs,
...
}@inputs:
flake-parts.lib.mkFlake { inherit inputs; } (
{
flake-parts-lib,
self,
inputs,
lib,
...
}:
let
inherit (flake-parts-lib) importApply;
in
{
systems = import systems;
flake = {
lib = {
importsApply = map (path: importApply path { inherit self inputs; });
# The log pipeline of a configuration on its examples
logs = import ./nix/lib/logs { inherit self inputs lib; };
# Dashboard builders for homelab.grafana.dashboards
grafana = import ./nix/lib/grafana.nix { inherit lib; };
# The PromQL of the alert rules through promtool
alerts = import ./nix/lib/alerts.nix { inherit self lib; };
# Screenshots of dashboards on generated samples, for working on their layout
screenshots = import ./nix/lib/screenshots { inherit self inputs lib; };
};
nixosModules = {
alloy = importApply ./nix/modules/alloy { inherit self inputs; };
grafana = importApply ./nix/modules/grafana { inherit self inputs; };
homepage = importApply ./nix/modules/homepage { inherit self inputs; };
kube-state-metrics = importApply ./nix/modules/kube-state-metrics { inherit self inputs; };
node-exporter = importApply ./nix/modules/node-exporter { inherit self inputs; };
loki = importApply ./nix/modules/loki { inherit self inputs; };
mimir = importApply ./nix/modules/mimir { inherit self inputs; };
smartctl-exporter = importApply ./nix/modules/smartctl-exporter { inherit self inputs; };
systemd-exporter = importApply ./nix/modules/systemd-exporter { inherit self inputs; };
zfs-exporter = importApply ./nix/modules/zfs-exporter { inherit self inputs; };
};
};
perSystem =
{
config,
pkgs,
lib,
...
}:
let
# Every module of this flake on, with the check dashboard as the home dashboard
everything = {
homelab = {
alloy.enable = true;
grafana.enable = true;
loki.enable = true;
mimir.enable = true;
node-exporter.enable = true;
smartctl-exporter.enable = true;
systemd-exporter.enable = true;
zfs-exporter.enable = true;
homepage.enable = true;
kube-state-metrics.enable = true;
# A board through every builder, as the home dashboard
grafana.homeDashboard = "check";
grafana.dashboards.check.dashboard = import ./nix/checks/dashboard.nix {
inherit (self.lib) grafana;
};
# Rules through the builder for both datasources and a contact point notified of critical alerts;
# the check drops the last rule and expects the prune to delete it
grafana.alerting = import ./nix/checks/alerting.nix { inherit (self.lib) grafana; };
};
};
manifests = inputs.homelab-shared.lib.checks.manifests {
inherit pkgs;
modules = lib.attrValues self.nixosModules ++ [ everything ];
};
# The same machine, for its dashboards
machine = inputs.nixpkgs.lib.nixosSystem {
modules =
lib.attrValues inputs.homelab-shared.nixosModules
++ lib.attrValues self.nixosModules
++ [
inputs.homelab-shared.lib.checks.fixture
{ nixpkgs.hostPlatform = pkgs.stdenv.hostPlatform.system; }
everything
];
};
in
{
# One lock node per homelab repo
checks.flake-lock = inputs.homelab-shared.lib.checks.flakeLock {
inherit pkgs;
lockFile = ./flake.lock;
};
# Dead Nix code. Pattern names stay: modules take { config, lib, pkgs, ... } whether they use them or not
checks.deadnix = pkgs.runCommand "deadnix" { nativeBuildInputs = [ pkgs.deadnix ]; } ''
deadnix --fail --no-lambda-pattern-names ${self}
touch $out
'';
checks.manifests = manifests;
# The parsers of this flake's sources on their examples, through the pinned Alloy and Loki
checks.logs = self.lib.logs.check {
inherit pkgs;
inherit (machine) config;
};
# nix build .#screenshots.<dashboard>[.<scenario>]; legacyPackages, as the renders nest
legacyPackages.screenshots = self.lib.screenshots.forDashboards {
inherit pkgs;
inherit (machine.config.homelab.grafana) dashboards;
};
# The pinned Grafana on the payload the manifests check rendered
checks.grafana = import ./nix/checks/grafana.nix {
inherit pkgs;
image =
(inputs.homelab-shared.lib.images.pinned pkgs ./nix/modules/grafana/Dockerfile)."grafana/grafana";
payload = manifests.passthru.manifests;
postgresql = machine.config.homelab.postgresql.image.package;
};
# The alert rules' PromQL through promtool
checks.promql = self.lib.alerts.check {
inherit pkgs;
inherit (machine) config;
};
# Every LogQL query of the dashboards and the alert rules through the pinned Loki
checks.logql = self.lib.logs.queries {
inherit pkgs;
inherit (machine) config;
# The journal stream of shared's k3s tile on the Cluster board, as shared's own logql check has it
streams = [
{
source = "journal";
node = "nas";
unit = "k3s.service";
program = "k3s";
service_name = "k3s";
}
];
};
# The VM tests, under the NixOS test driver (needs KVM): `nix build .#nixosTests.<name>`. They stay out of the
# checks, so a plain `nix flake check` takes minutes; CI runs both
legacyPackages.nixosTests = {
# Grafana with storage's PostgreSQL on one node on k3s' bundled network
grafana = import ./nix/tests/grafana.nix { inherit self inputs pkgs; };
# Alloy shipping the pods' and the journal's logs to Loki on one node on k3s' bundled network
logs = import ./nix/tests/logs.nix { inherit self inputs pkgs; };
};
# That the VM tests evaluate, without building or running them
checks.nixos-tests = pkgs.writeText "nixos-tests" (
lib.concatMapStringsSep "\n" (test: builtins.unsafeDiscardOutputDependency test.drvPath) (
lib.attrValues config.legacyPackages.nixosTests
)
);
packages = {
options-docs = inputs.docs.lib.docs.options {
inherit pkgs;
modules = lib.attrValues self.nixosModules;
repoPath = toString self;
repoLinkPrefix = "https://github.com/nixos-homelab/monitoring/blob/main";
prefixGroups = {
alloy = [ "homelab.alloy" ];
grafana = [
"homelab.grafana"
"homelab.homepage.integrations.grafana"
];
kube-state-metrics = [ "homelab.kube-state-metrics" ];
node-exporter = [ "homelab.node-exporter" ];
loki = [ "homelab.loki" ];
mimir = [ "homelab.mimir" ];
smartctl-exporter = [ "homelab.smartctl-exporter" ];
systemd-exporter = [ "homelab.systemd-exporter" ];
zfs-exporter = [ "homelab.zfs-exporter" ];
homepage = [ "homelab.homepage.sections" ];
};
};
manual-docs = inputs.docs.lib.mkdocs.manual {
inherit pkgs;
rootDoc = ./README.md;
};
};
};
}
);
}