blob: 70fc05813b1b19e0c57cdf5f50c1e78ec89d6d64 (
plain)
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
|
{ config, lib, ... }:
with import <stockholm/lib>;
let
cfg = config.krebs;
out = {
imports = [
../../kartei
./acl.nix
./airdcpp.nix
./announce-activation.nix
./apt-cacher-ng.nix
./backup.nix
./bepasty-server.nix
./bindfs.nix
./brockman.nix
./build.nix
./cachecache.nix
./ci
./current.nix
./dns.nix
./ergo.nix
./exim-retiolum.nix
./exim-smarthost.nix
./exim.nix
./fetchWallpaper.nix
./git.nix
./github
./go.nix
./hidden-ssh.nix
./hosts.nix
./htgen.nix
./iana-etc.nix
./iptables.nix
./kapacitor.nix
./konsens.nix
./monit.nix
./nixpkgs.nix
./on-failure.nix
./os-release.nix
./per-user.nix
./permown.nix
./power-action.nix
./reaktor2.nix
./realwallpaper.nix
./repo-sync.nix
./retiolum-bootstrap.nix
./secret.nix
./setuid.nix
./shadow.nix
./ssl.nix
./sync-containers.nix
./systemd.nix
./tinc.nix
./tinc_graphs.nix
./upstream
./urlwatch.nix
./xresources.nix
./zones.nix
];
options.krebs = api;
config = lib.mkIf cfg.enable imp;
};
api = {
enable = mkEnableOption "krebs";
users = mkOption {
type = with types; attrsOf user;
};
sitemap = mkOption {
default = {};
type = types.attrsOf types.sitemap.entry;
};
zone-head-config = mkOption {
type = with types; attrsOf str;
description = ''
The zone configuration head which is being used to create the
zone files. The string for each key is pre-pended to the zone file.
'';
# TODO: configure the default somewhere else,
# maybe use krebs.dns.providers
default = {
# github.io -> 192.30.252.154
"krebsco.de" = ''
$TTL 86400
@ IN SOA dns19.ovh.net. tech.ovh.net. (2015052000 86400 3600 3600000 86400)
IN NS ns19.ovh.net.
IN NS dns19.ovh.net.
IN A 185.199.108.153
IN A 185.199.109.153
IN A 185.199.110.153
IN A 185.199.111.153
'';
};
};
};
imp = lib.mkMerge [
{
krebs.dns.providers = {
"krebsco.de" = "zones";
shack = "hosts";
i = "hosts";
r = "hosts";
w = "hosts";
};
krebs.dns.search-domain = mkDefault "r";
krebs.users = {
krebs = {
home = "/krebs";
mail = "spam@krebsco.de";
};
root = {
home = "/root";
pubkey = config.krebs.build.host.ssh.pubkey;
uid = 0;
};
};
services.openssh.hostKeys =
let inherit (config.krebs.build.host.ssh) privkey; in
mkIf (privkey != null) [privkey];
services.openssh.knownHosts =
filterAttrs
(knownHostName: knownHost:
knownHost.publicKey != null &&
knownHost.hostNames != []
)
(mapAttrs
(hostName: host: {
hostNames =
concatLists
(mapAttrsToList
(netName: net:
let
aliases =
concatLists [
shortAliases
net.aliases
net.addrs
];
shortAliases =
optionals
(cfg.dns.search-domain != null)
(map (removeSuffix ".${cfg.dns.search-domain}")
(filter (hasSuffix ".${cfg.dns.search-domain}")
net.aliases));
addPort = alias:
if net.ssh.port != 22
then "[${alias}]:${toString net.ssh.port}"
else alias;
in
map addPort aliases
)
host.nets);
publicKey = host.ssh.pubkey;
})
(foldl' mergeAttrs {} [
cfg.hosts
{
localhost = {
nets.local = {
addrs = [ "127.0.0.1" "::1" ];
aliases = [ "localhost" ];
ssh.port = 22;
};
ssh.pubkey = config.krebs.build.host.ssh.pubkey;
};
}
]));
programs.ssh.extraConfig = concatMapStrings
(net: ''
Host ${toString (net.aliases ++ net.addrs)}
Port ${toString net.ssh.port}
'')
(filter
(net: net.ssh.port != 22)
(concatMap (host: attrValues host.nets)
(mapAttrsToList
(_: host: recursiveUpdate host
(optionalAttrs (cfg.dns.search-domain != null &&
hasAttr cfg.dns.search-domain host.nets) {
nets."" = host.nets.${cfg.dns.search-domain} // {
aliases = [host.name];
addrs = [];
};
}))
config.krebs.hosts)));
}
];
in out
|