forked from c3d2/nix-config
modules/cluster/deployment: fixups
This commit is contained in:
parent
cbf9f7fac5
commit
acdaf7eece
|
@ -10,10 +10,10 @@
|
|||
type = types.int;
|
||||
default = 512;
|
||||
};
|
||||
networks = mkOption {
|
||||
type = with types; listOf str;
|
||||
default = [ "serv" ];
|
||||
};
|
||||
# networks = mkOption {
|
||||
# type = with types; listOf str;
|
||||
# default = [ "serv" ];
|
||||
# };
|
||||
persistedShares = mkOption {
|
||||
type = with types; listOf str;
|
||||
default = [ "/etc" "/home" "/var" ];
|
||||
|
|
|
@ -1,9 +1,25 @@
|
|||
{ config, lib, ... }:
|
||||
{ zentralwerk, config, lib, ... }:
|
||||
|
||||
let
|
||||
defaultGateways = {
|
||||
serv = "serv-gw";
|
||||
c3d2 = "c3d2-gw3";
|
||||
pub = "pub-gw";
|
||||
flpk = "flpk-gw";
|
||||
};
|
||||
|
||||
nets = builtins.attrNames (
|
||||
lib.filterAttrs (net: { hosts4, hosts6, ... }:
|
||||
hosts4 ? ${hostName} ||
|
||||
lib.filterAttrs (ctx: hosts6:
|
||||
hosts6 ? ${hostName}
|
||||
) hosts6 != {}
|
||||
) zentralwerk.lib.config.site.net
|
||||
);
|
||||
|
||||
inherit (config.networking) hostName;
|
||||
inherit (config.system.build.skyflake-deployment) user repo vmName;
|
||||
|
||||
|
||||
generateMacAddress = net:
|
||||
let
|
||||
hash = builtins.hashString "md5" "1-${net}-${hostName}";
|
||||
|
@ -16,10 +32,10 @@ let
|
|||
if s' == s
|
||||
then s
|
||||
else withoutLeadingSlash s';
|
||||
|
||||
|
||||
in
|
||||
{
|
||||
config.microvm = {
|
||||
microvm = {
|
||||
hypervisor = "cloud-hypervisor";
|
||||
vcpu = config.deployment.vcpu;
|
||||
mem = config.deployment.mem;
|
||||
|
@ -50,4 +66,52 @@ in
|
|||
mac = generateMacAddress net;
|
||||
}) config.deployment.networks;
|
||||
};
|
||||
|
||||
networking = {
|
||||
useDHCP = false;
|
||||
dhcpcd.enable = false;
|
||||
useNetworkd = true;
|
||||
};
|
||||
|
||||
systemd.network = {
|
||||
links = builtins.foldl' (links: net: links // {
|
||||
"30-${net}" = {
|
||||
# enable = true;
|
||||
matchConfig.MACAddress = generateMacAddress net;
|
||||
# rename interface to net name
|
||||
linkConfig.Name = net;
|
||||
};
|
||||
}) {} nets;
|
||||
|
||||
networks = builtins.foldl' (networks: net: networks // {
|
||||
"30-${net}" =
|
||||
let
|
||||
zwNet = zentralwerk.lib.config.site.net.${net};
|
||||
addresses =
|
||||
lib.optional (zwNet.hosts4 ? ${hostName}) "${zwNet.hosts4.${hostName}}/${toString zwNet.subnet4Len}"
|
||||
++
|
||||
map (hosts6: "${hosts6.${hostName}}/64") (
|
||||
builtins.filter (hosts6: hosts6 ? ${hostName}) (
|
||||
builtins.attrValues zwNet.hosts6
|
||||
)
|
||||
);
|
||||
in {
|
||||
matchConfig.MACAddress = generateMacAddress net;
|
||||
addresses = map (Address: {
|
||||
addressConfig = { inherit Address; };
|
||||
}) addresses;
|
||||
gateway = lib.mkIf (defaultGateways ? ${net}) (
|
||||
let
|
||||
gw = defaultGateways.${net};
|
||||
in
|
||||
[ zwNet.hosts4.${gw} ]
|
||||
++ map (hosts6: hosts6.${gw}) (
|
||||
builtins.filter (hosts6: hosts6 ? ${gw}) (
|
||||
builtins.attrValues zwNet.hosts6
|
||||
)
|
||||
)
|
||||
);
|
||||
};
|
||||
}) {} nets;
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user