blob: 7701ee589df5fbef39e6f561f2d14735dc358141 (
plain) (
blame)
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
|
{ config, lib, ... }: with lib; {
options.srv = {
static = mkOption {
type = types.nullOr (types.submodule {
options = {
ip = mkOption {
type = types.str;
example = "10.0.0.0";
};
prefixLength = mkOption {
type = types.ints.between 0 32;
default = 24;
example = 32;
};
interface = mkOption {
type = types.str;
example = "ens3";
};
};
});
default = null;
};
tld = mkOption {
type = types.nullOr types.str;
default = null;
example = "local";
};
slds = mkOption {
type = types.listOf types.str;
default = [];
};
};
config = let
netinterfaces = config:
{
${config.srv.static.interface}.ipv4.addresses = [{
address = config.srv.static.ip;
prefixLength = config.srv.static.prefixLength;
}];
};
in {
networking.interfaces = mkIf
(config.srv.static != null)
(netinterfaces config);
virtualisation.vmVariant.networking.interfaces = mkIf
(config.srv.static != null)
(lib.mkVMOverride
(netinterfaces
(lib.recursiveUpdate
config
{ srv.static.interface = "eth0"; })));
services.dnsmasq.settings.address = mkIf
(config.srv.static != null && config.srv.tld != null)
(builtins.map
(sld: "/${sld}.${config.srv.tld}/${config.srv.static.ip}")
config.srv.slds);
};
}
|