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: {
|
||||
role = "container";
|
||||
location = mainServer;
|
||||
inherit (container) interfaces;
|
||||
}) 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, ... }: {
|
||||
options = {
|
||||
role = mkOption {
|
||||
|
@ -44,6 +63,10 @@ let
|
|||
type = with types; nullOr str;
|
||||
default = null;
|
||||
};
|
||||
interfaces = mkOption {
|
||||
default = {};
|
||||
type = with types; attrsOf (submodule interfaceOpts);
|
||||
};
|
||||
};
|
||||
};
|
||||
in
|
||||
|
|
|
@ -1,19 +1,16 @@
|
|||
{ hostName, self, config, lib, pkgs, ... }:
|
||||
|
||||
let
|
||||
# ctHosts =
|
||||
# lib.filterAttrs (_: { role, model, location, ... }:
|
||||
# role == "container" &&
|
||||
# model == "lxc" &&
|
||||
# location == hostName
|
||||
# ) config.site.hosts;
|
||||
|
||||
pillar = self.lib.saltPillarFor hostName;
|
||||
containers =
|
||||
# TODO: remove 1 line
|
||||
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 != {};
|
||||
|
||||
netConfig = ctName: interfaces:
|
||||
|
@ -60,8 +57,7 @@ let
|
|||
)
|
||||
else throw "Invalid data in lxc net config: ${lib.generators.toPretty {} x}";
|
||||
in
|
||||
builtins.trace "config: ${lib.generators.toPretty {} config}" (
|
||||
serialize "lxc.net" config);
|
||||
serialize "lxc.net" config;
|
||||
in
|
||||
{
|
||||
virtualisation.lxc = lib.mkIf enabled {
|
||||
|
@ -86,7 +82,7 @@ in
|
|||
source =
|
||||
let
|
||||
inherit (containers.${ctName}) interfaces;
|
||||
in builtins.trace ctName builtins.toFile "${ctName}.conf" ''
|
||||
in builtins.toFile "${ctName}.conf" ''
|
||||
# For lxcfs and sane defaults
|
||||
lxc.include = /etc/lxc/common.conf
|
||||
|
||||
|
|
Loading…
Reference in New Issue