Repository navigation
Expand file tree
/
Copy pathflake.nix
More file actions
188 lines (188 loc) · 7.55 KB
/
Copy pathflake.nix
File metadata and controls
188 lines (188 loc) · 7.55 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
{
description = "NixOS Homelab Networking Workloads";
inputs = {
systems.url = "github:nix-systems/default-linux";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-26.05";
nixpkgs-mongodb-pin.url = "github:NixOS/nixpkgs/9b696460ac78b5ccfc17c854d8c976f20456e943";
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-monitoring";
};
homelab-monitoring = {
url = "github:nixos-homelab/monitoring";
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.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; });
toPorts = import ./nix/lib/to-ports.nix;
};
nixosModules = {
cilium = importApply ./nix/modules/cilium { inherit self inputs; };
cilium-crds = importApply ./nix/modules/cilium/crds.nix { inherit self inputs; };
client-vpn = importApply ./nix/modules/client-vpn { inherit self inputs; };
external-dns = importApply ./nix/modules/external-dns { inherit self inputs; };
homepage = importApply ./nix/modules/homepage { inherit self inputs; };
netutils = importApply ./nix/modules/netutils { inherit self inputs; };
privacy-vpn = importApply ./nix/modules/privacy-vpn { inherit self inputs; };
routed-ippool = importApply ./nix/modules/routed-ippool { inherit self inputs; };
unifi = importApply ./nix/modules/unifi { inherit self inputs; };
};
};
perSystem =
{
config,
pkgs,
lib,
...
}:
{
# 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
'';
# Addresses from the documentation ranges, keys all zero
checks.manifests = inputs.homelab-shared.lib.checks.manifests {
inherit pkgs;
modules = lib.attrValues self.nixosModules ++ [
./nix/tests/config.nix
{
# Evaluates the metrics parts of the modules, off with Alloy
homelab.alloy.enable = true;
nixpkgs.config.allowUnfreePredicate =
pkg:
builtins.elem (lib.getName pkg) [
"unifi-controller"
"mongodb"
];
}
];
};
# The PromQL of this flake's alert rules through promtool, with Grafana on to have them
checks.promql = inputs.homelab-monitoring.lib.alerts.check {
inherit pkgs;
config =
(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; }
./nix/tests/config.nix
{
homelab.alloy.enable = true;
homelab.grafana.enable = true;
}
];
}).config;
};
# The parsers of this flake's workloads on their examples, through the pinned Alloy and Loki
checks.logs = inputs.homelab-monitoring.lib.logs.check {
inherit pkgs;
modules = lib.attrValues self.nixosModules ++ [
./nix/tests/config.nix
{
nixpkgs.config.allowUnfreePredicate =
pkg:
builtins.elem (lib.getName pkg) [
"unifi-controller"
"mongodb"
];
}
];
};
# 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
# The cluster on one node, with a LAN host beside it
legacyPackages.nixosTests.cluster = import ./nix/tests/cluster.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/networking/blob/main";
prefixGroups = {
cilium = [ "homelab.cilium" ];
client-vpn = [ "homelab.client-vpn" ];
external-dns = [ "homelab.external-dns" ];
netutils = [ "homelab.netutils" ];
privacy-vpn = [ "homelab.privacy-vpn" ];
routed-ippool = [ "homelab.routed-ippool" ];
unifi = [
"homelab.unifi"
"homelab.homepage.integrations.unifi"
];
homepage = [ "homelab.homepage.sections" ];
};
};
manual-docs = inputs.docs.lib.mkdocs.manual {
inherit pkgs;
rootDoc = ./README.md;
pathMap = {
cilium = ./nix/modules/cilium/README.md;
};
};
};
};
}
);
}