cascade-functions/_enrich-machine-attrs.nix

24 lines
426 B
Nix
Raw Permalink Normal View History

2022-10-16 22:46:24 +00:00
with builtins;
machine:
let addressParts = match "([0-9.]*)/([0-9]*)" machine.address;
in
if addressParts == null then throw "could not split address into IP and subnet" else
let prefix = fromJSON (elemAt addressParts 1);
ip = head addressParts;
in
machine // {
inherit ip prefix;
interface = {
ipv4.addresses = [{
address = ip;
prefixLength = prefix;
}];
macAddress = machine.mac;
};
}