forked from zentralwerk/network
nix: put interfaces in options
This commit is contained in:
parent
465a316192
commit
020e8c3af2
|
@ -36,6 +36,7 @@ in
|
||||||
(builtins.mapAttrs (_: container: {
|
(builtins.mapAttrs (_: container: {
|
||||||
role = "container";
|
role = "container";
|
||||||
location = mainServer;
|
location = mainServer;
|
||||||
|
inherit (container) interfaces;
|
||||||
}) pillar.containers)
|
}) pillar.containers)
|
||||||
] ++
|
] ++
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,25 @@ let
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
interfaceOpts = { name, ... }: {
|
||||||
|
options = {
|
||||||
|
hwaddr = mkOption {
|
||||||
|
type = with types; nullOr str;
|
||||||
|
default = null;
|
||||||
|
};
|
||||||
|
type = mkOption {
|
||||||
|
type = types.enum [ "veth" "phys" ];
|
||||||
|
};
|
||||||
|
gw = mkOption {
|
||||||
|
type = with types; nullOr str;
|
||||||
|
default = null;
|
||||||
|
};
|
||||||
|
gw6 = mkOption {
|
||||||
|
type = with types; nullOr str;
|
||||||
|
default = null;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
hostOpts = { name, ... }: {
|
hostOpts = { name, ... }: {
|
||||||
options = {
|
options = {
|
||||||
role = mkOption {
|
role = mkOption {
|
||||||
|
@ -44,6 +63,10 @@ let
|
||||||
type = with types; nullOr str;
|
type = with types; nullOr str;
|
||||||
default = null;
|
default = null;
|
||||||
};
|
};
|
||||||
|
interfaces = mkOption {
|
||||||
|
default = {};
|
||||||
|
type = with types; attrsOf (submodule interfaceOpts);
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
|
|
|
@ -1,19 +1,16 @@
|
||||||
{ hostName, self, config, lib, pkgs, ... }:
|
{ hostName, self, config, lib, pkgs, ... }:
|
||||||
|
|
||||||
let
|
let
|
||||||
# ctHosts =
|
|
||||||
# lib.filterAttrs (_: { role, model, location, ... }:
|
|
||||||
# role == "container" &&
|
|
||||||
# model == "lxc" &&
|
|
||||||
# location == hostName
|
|
||||||
# ) config.site.hosts;
|
|
||||||
|
|
||||||
pillar = self.lib.saltPillarFor hostName;
|
|
||||||
containers =
|
containers =
|
||||||
# TODO: remove 1 line
|
# TODO: remove 1 line
|
||||||
lib.filterAttrs (ctName: _: ctName == "upstream1") (
|
lib.filterAttrs (ctName: _: ctName == "upstream1") (
|
||||||
if pillar ? containers then pillar.containers else {}
|
lib.filterAttrs (_: { role, model, location, ... }:
|
||||||
|
role == "container" &&
|
||||||
|
model == "lxc" &&
|
||||||
|
location == hostName
|
||||||
|
) config.site.hosts
|
||||||
);
|
);
|
||||||
|
|
||||||
enabled = containers != {};
|
enabled = containers != {};
|
||||||
|
|
||||||
netConfig = ctName: interfaces:
|
netConfig = ctName: interfaces:
|
||||||
|
@ -60,8 +57,7 @@ let
|
||||||
)
|
)
|
||||||
else throw "Invalid data in lxc net config: ${lib.generators.toPretty {} x}";
|
else throw "Invalid data in lxc net config: ${lib.generators.toPretty {} x}";
|
||||||
in
|
in
|
||||||
builtins.trace "config: ${lib.generators.toPretty {} config}" (
|
serialize "lxc.net" config;
|
||||||
serialize "lxc.net" config);
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
virtualisation.lxc = lib.mkIf enabled {
|
virtualisation.lxc = lib.mkIf enabled {
|
||||||
|
@ -86,7 +82,7 @@ in
|
||||||
source =
|
source =
|
||||||
let
|
let
|
||||||
inherit (containers.${ctName}) interfaces;
|
inherit (containers.${ctName}) interfaces;
|
||||||
in builtins.trace ctName builtins.toFile "${ctName}.conf" ''
|
in builtins.toFile "${ctName}.conf" ''
|
||||||
# For lxcfs and sane defaults
|
# For lxcfs and sane defaults
|
||||||
lxc.include = /etc/lxc/common.conf
|
lxc.include = /etc/lxc/common.conf
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue