mirror of
https://github.com/oddlama/nix-config.git
synced 2025-10-10 14:50:40 +02:00
feat(topology): add systemd network extractor
This commit is contained in:
parent
65890181e9
commit
887115c96d
3 changed files with 58 additions and 40 deletions
|
@ -5,43 +5,59 @@
|
|||
}: let
|
||||
inherit
|
||||
(lib)
|
||||
any
|
||||
attrValues
|
||||
concatLists
|
||||
flip
|
||||
mapAttrsToList
|
||||
mkDefault
|
||||
mkIf
|
||||
mkMerge
|
||||
optional
|
||||
;
|
||||
in {
|
||||
#config = mkIf config.systemd.network.enable {
|
||||
# topology.interfaces = mkMerge (
|
||||
# # Create interfaces based on systemd.network.netdevs
|
||||
# concatLists (
|
||||
# flip mapAttrsToList config.systemd.network.netdevs (
|
||||
# _unit: netdev:
|
||||
# optional (netdev ? netdevConfig.Name) {
|
||||
# ${netdev.netdevConfig.Name} = {
|
||||
# physical = mkDefault false;
|
||||
# };
|
||||
# }
|
||||
# )
|
||||
# )
|
||||
# # Add interface configuration based on systemd.network.networks
|
||||
# #++ concatLists (
|
||||
# # flip mapAttrsToList config.systemd.network.networks (
|
||||
# # _unit: network:
|
||||
# # optional (network ? matchConfig.Name) {
|
||||
# # ${network.networkConfig.Name} = {
|
||||
# # };
|
||||
# # }
|
||||
# # )
|
||||
# #)
|
||||
# );
|
||||
config = mkIf config.systemd.network.enable {
|
||||
topology.self.interfaces = mkMerge (
|
||||
# Create interfaces based on systemd.network.netdevs
|
||||
concatLists (
|
||||
flip mapAttrsToList config.systemd.network.netdevs (
|
||||
_unit: netdev:
|
||||
optional (netdev ? netdevConfig.Name) {
|
||||
${netdev.netdevConfig.Name} = {
|
||||
virtual = mkDefault true;
|
||||
};
|
||||
}
|
||||
)
|
||||
)
|
||||
# Add interface configuration based on systemd.network.networks
|
||||
++ concatLists (
|
||||
flip mapAttrsToList config.systemd.network.networks (
|
||||
_unit: network: let
|
||||
# FIXME: TODO renameInterfacesByMac is not a standard option!
|
||||
nameFromMac =
|
||||
optional (network ? matchConfig.MACAddress && config.networking.renameInterfacesByMac ? ${network.matchConfig.MACAddress})
|
||||
config.networking.renameInterfacesByMac.${network.matchConfig.MACAddress};
|
||||
|
||||
# #self.interfaces = {
|
||||
# #};
|
||||
# #networks.somenet = {
|
||||
# # connections = [];
|
||||
# #};
|
||||
#};
|
||||
nameFromNetdev =
|
||||
optional (
|
||||
(network ? matchConfig.Name)
|
||||
&& flip any (attrValues config.systemd.network.netdevs) (x:
|
||||
(x ? netdevConfig.Name)
|
||||
&& x.netdevConfig.Name == network.matchConfig.Name)
|
||||
)
|
||||
network.matchConfig.Name;
|
||||
|
||||
interfaceName = builtins.head (nameFromMac ++ nameFromNetdev ++ [null]);
|
||||
in
|
||||
optional (interfaceName != null) {
|
||||
${interfaceName} = {
|
||||
mac = network.matchConfig.MACAddress or null;
|
||||
addresses = network.address ++ (network.networkConfig.Address or []);
|
||||
gateways = network.gateway ++ (network.networkConfig.Gateway or []);
|
||||
};
|
||||
}
|
||||
)
|
||||
)
|
||||
);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -49,6 +49,6 @@ in {
|
|||
|
||||
config.topology = {
|
||||
# Ensure a node exists for this host
|
||||
nodes.${config.topology.id} = {};
|
||||
nodes.${config.topology.id}.type = "nixos";
|
||||
};
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ in
|
|||
virtual = mkOption {
|
||||
description = "Whether this is a virtual interface.";
|
||||
type = types.bool;
|
||||
default = false;
|
||||
};
|
||||
|
||||
mac = mkOption {
|
||||
|
@ -39,16 +40,17 @@ in
|
|||
type = types.nullOr types.str;
|
||||
};
|
||||
|
||||
#addresses = mkOption {
|
||||
# description = "The configured address(es), or a descriptive string (like DHCP).";
|
||||
# type = types.listOf types.str;
|
||||
#};
|
||||
addresses = mkOption {
|
||||
description = "The configured address(es), or a descriptive string (like DHCP).";
|
||||
default = [];
|
||||
type = types.listOf types.str;
|
||||
};
|
||||
|
||||
#gateway = mkOption {
|
||||
# description = "The configured gateway, if any";
|
||||
# type = types.nullOr types.str;
|
||||
# default = null;
|
||||
#};
|
||||
gateways = mkOption {
|
||||
description = "The configured gateways, if any.";
|
||||
default = [];
|
||||
type = types.listOf types.str;
|
||||
};
|
||||
|
||||
network = mkOption {
|
||||
description = "The id of the network to which this interface belongs, if any.";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue