mirror of
https://github.com/oddlama/nix-config.git
synced 2025-10-10 23:00:39 +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
|
}: let
|
||||||
inherit
|
inherit
|
||||||
(lib)
|
(lib)
|
||||||
|
any
|
||||||
|
attrValues
|
||||||
concatLists
|
concatLists
|
||||||
flip
|
flip
|
||||||
|
mapAttrsToList
|
||||||
mkDefault
|
mkDefault
|
||||||
mkIf
|
mkIf
|
||||||
mkMerge
|
mkMerge
|
||||||
optional
|
optional
|
||||||
;
|
;
|
||||||
in {
|
in {
|
||||||
#config = mkIf config.systemd.network.enable {
|
config = mkIf config.systemd.network.enable {
|
||||||
# topology.interfaces = mkMerge (
|
topology.self.interfaces = mkMerge (
|
||||||
# # Create interfaces based on systemd.network.netdevs
|
# Create interfaces based on systemd.network.netdevs
|
||||||
# concatLists (
|
concatLists (
|
||||||
# flip mapAttrsToList config.systemd.network.netdevs (
|
flip mapAttrsToList config.systemd.network.netdevs (
|
||||||
# _unit: netdev:
|
_unit: netdev:
|
||||||
# optional (netdev ? netdevConfig.Name) {
|
optional (netdev ? netdevConfig.Name) {
|
||||||
# ${netdev.netdevConfig.Name} = {
|
${netdev.netdevConfig.Name} = {
|
||||||
# physical = mkDefault false;
|
virtual = mkDefault true;
|
||||||
# };
|
};
|
||||||
# }
|
}
|
||||||
# )
|
)
|
||||||
# )
|
)
|
||||||
# # Add interface configuration based on systemd.network.networks
|
# Add interface configuration based on systemd.network.networks
|
||||||
# #++ concatLists (
|
++ concatLists (
|
||||||
# # flip mapAttrsToList config.systemd.network.networks (
|
flip mapAttrsToList config.systemd.network.networks (
|
||||||
# # _unit: network:
|
_unit: network: let
|
||||||
# # optional (network ? matchConfig.Name) {
|
# FIXME: TODO renameInterfacesByMac is not a standard option!
|
||||||
# # ${network.networkConfig.Name} = {
|
nameFromMac =
|
||||||
# # };
|
optional (network ? matchConfig.MACAddress && config.networking.renameInterfacesByMac ? ${network.matchConfig.MACAddress})
|
||||||
# # }
|
config.networking.renameInterfacesByMac.${network.matchConfig.MACAddress};
|
||||||
# # )
|
|
||||||
# #)
|
|
||||||
# );
|
|
||||||
|
|
||||||
# #self.interfaces = {
|
nameFromNetdev =
|
||||||
# #};
|
optional (
|
||||||
# #networks.somenet = {
|
(network ? matchConfig.Name)
|
||||||
# # connections = [];
|
&& 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 = {
|
config.topology = {
|
||||||
# Ensure a node exists for this host
|
# Ensure a node exists for this host
|
||||||
nodes.${config.topology.id} = {};
|
nodes.${config.topology.id}.type = "nixos";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ in
|
||||||
virtual = mkOption {
|
virtual = mkOption {
|
||||||
description = "Whether this is a virtual interface.";
|
description = "Whether this is a virtual interface.";
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
mac = mkOption {
|
mac = mkOption {
|
||||||
|
@ -39,16 +40,17 @@ in
|
||||||
type = types.nullOr types.str;
|
type = types.nullOr types.str;
|
||||||
};
|
};
|
||||||
|
|
||||||
#addresses = mkOption {
|
addresses = mkOption {
|
||||||
# description = "The configured address(es), or a descriptive string (like DHCP).";
|
description = "The configured address(es), or a descriptive string (like DHCP).";
|
||||||
# type = types.listOf types.str;
|
default = [];
|
||||||
#};
|
type = types.listOf types.str;
|
||||||
|
};
|
||||||
|
|
||||||
#gateway = mkOption {
|
gateways = mkOption {
|
||||||
# description = "The configured gateway, if any";
|
description = "The configured gateways, if any.";
|
||||||
# type = types.nullOr types.str;
|
default = [];
|
||||||
# default = null;
|
type = types.listOf types.str;
|
||||||
#};
|
};
|
||||||
|
|
||||||
network = mkOption {
|
network = mkOption {
|
||||||
description = "The id of the network to which this interface belongs, if any.";
|
description = "The id of the network to which this interface belongs, if any.";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue