-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
177 lines (159 loc) · 5.99 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
{
description = "Telperion with Silver Fruit";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
dns = {
url = "github:nix-community/dns.nix";
inputs.nixpkgs.follows = "nixpkgs"; # (optionally)
};
laurelin = {
url = "git+file:/home/jfredett/code/minas-tarwon/laurelin";
inputs.nixpkgs.follows = "nixpkgs";
};
narya = {
url = "git+file:/home/jfredett/code/minas-tarwon/narya";
inputs.nixpkgs.follows = "nixpkgs";
};
nur.url = "github:nix-community/NUR";
home-manager = {
url = "github:nix-community/home-manager/master";
inputs.nixpkgs.follows = "nixpkgs";
};
glamdring = {
url = "git+file:/home/jfredett/code/minas-tarwon/glamdring";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = inputs @ { self, nixpkgs, dns, laurelin, narya, glamdring, home-manager, nur, ... }: rec {
# FIXME: This sucks, too messy.
genDNS = with nixpkgs.lib; let
mkZoneString = zone: config: toString (dns.lib.evalZone zone config);
# TODO: Extract this.
ecConf = let
root = import ./emerald.city/dns.nix { inherit dns; };
configs = map (c: c.config.laurelin.infra.dns) (attrValues self.nixosConfigTree."emerald.city");
in mkZoneString "emerald.city" (mkMerge (configs ++ [root]));
canonConf = let
root = import ./cadaster { inherit dns; };
configs = map (c: c.config.laurelin.infra.dns) (attrValues self.nixosConfigTree.canon);
#in mkZoneString "canon" (mkMerge (configs ++ root));
in mkZoneString "canon" (mkMerge (configs ++ root));
in {
zones = {
canon = canonConf;
"emerald.city" = ecConf;
};
};
# This needs to be flat, but I want to store it in a more structured way, time to add another
# layer.
nixosConfigurations = with builtins; let
mkFlat = domain: acc: el: acc // { "${el}.${domain}" = self.nixosConfigTree."${domain}"."${el}"; };
flatten = domain: branch: foldl' (mkFlat domain) {} (attrNames branch."${domain}");
canon = flatten "canon" self.nixosConfigTree;
emerald-city = flatten "emerald.city" self.nixosConfigTree;
in canon // emerald-city;
nixosConfigTree = let
vmConfigFor = path: nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
{ system.stateVersion = "24.11"; }
narya.nixosModules.default
laurelin.nixosModules.default
# FIXME: I don't think these two things should be here, they should be behind
# laurelin/narya at least, ideally behind glamdring.
home-manager.nixosModules.home-manager
{ home-manager.backupFileExtension = "backup"; }
nur.modules.nixos.default
path
];
specialArgs = { root = self; inherit glamdring laurelin narya dns; };
};
configFor = name: nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
{ system.stateVersion = "24.11"; }
narya.nixosModules.default
laurelin.nixosModules.default
# FIXME: I don't think these two things should be here, they should be behind
# laurelin/narya at least, ideally behind glamdring.
home-manager.nixosModules.home-manager
nur.modules.nixos.default
./cadaster/${name}
];
specialArgs = { root = self; inherit glamdring laurelin narya dns; };
};
in {
# TODO: It might be better to do:
#
# archimedes = {
# canon = configFor "archimedes";
# "emerald.city" = configFor "archimedes" { additional-options };
# };
#
# as this would allow punning of the form `.#archimedes.canon` and
# `.#archimedes."emerald.city"`.
canon = {
archimedes = configFor "archimedes";
maiasaura = configFor "maiasaura";
dragon-of-perdition = configFor "dragon-of-perdition";
babylon-the-great = configFor "babylon-the-great";
toto = configFor "toto";
};
"emerald.city" = {
barge = vmConfigFor ./emerald.city/roles/barge.nix;
pinky = vmConfigFor ./emerald.city/roles/pinky.nix;
randy = vmConfigFor ./emerald.city/roles/randy.nix;
daktylos = vmConfigFor ./emerald.city/roles/daktylos.nix;
bill = vmConfigFor ./emerald.city/roles/bill.nix;
};
};
# TODO: I don't like this name, maybe this is like, vmConfigs? libvirtConfigs? Eventually it
# should have a more rich structure anyway...
domains = {
"emerald.city" = {
domains = {
barge = ./emerald.city/domains/barge.xml;
pinky = ./emerald.city/domains/pinky.xml;
randy = ./emerald.city/domains/randy.xml;
daktylos = ./emerald.city/domains/daktylos.xml;
bill = ./emerald.city/domains/bill.xml;
};
networks = {
ec-net = ./emerald.city/networks/ec-net.xml;
};
};
};
scrapeTargets = with builtins; let
isEnabled = exporter: c: c.config.laurelin.services.prometheus.exporters.${exporter}.enable;
scrapeClientsFor = exporter: (filter (isEnabled exporter) (attrValues self.nixosConfigurations));
mkScrapeConfigsFor = exporter: map (mkScrapeConfigFor exporter) (scrapeClientsFor exporter);
mkScrapeConfigFor = exporter: conf: let
hostName = conf.config.networking.hostName;
domain = conf.config.laurelin.services.prometheus.exporters.node.domain;
port = conf.config.laurelin.services.prometheus.exporters.node.port;
in {
job_name = "${hostName}-${exporter}";
static_configs = [
{
labels = {
hostname = hostName;
};
targets = [
"${hostName}.${domain}:${toString port}"
];
}
];
};
exporters = [
# "domain"
# "idrac"
"ipmi"
"nginx"
"node"
# "script"
"systemd"
# "zfs"
];
in concatMap mkScrapeConfigsFor exporters;
};
}