Created
May 2, 2021 21:18
-
-
Save risicle/4aaad898902c821f535a98901d599615 to your computer and use it in GitHub Desktop.
jq expression to turn netplan yaml configs into nixos network configurations, supporting bonding and vlans
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
systemd: { | |
network: { | |
netdevs: ( | |
.network.ethernets | with_entries(.value |= { | |
netdevConfig: {Name: ."set-name"}, | |
matchConfig: {MACAddress: .match.macaddress} | |
}) | |
) | |
} | |
}, | |
networking: { | |
bonds: ( | |
.network.bonds | with_entries(.value |= { | |
interfaces: .interfaces, | |
driverOptions: { | |
mode: .parameters.mode | tostring, | |
downdelay: .parameters."down-delay" | tostring, | |
lacp_rate: .parameters."lacp-rate" | tostring, | |
miimon: .parameters."mii-monitor-interval" | tostring, | |
xmit_hash_policy: .parameters."transmit-hash-policy" | tostring, | |
updelay: .parameters."up-delay" | tostring | |
} | |
}) | |
), | |
vlans: ( | |
.network.vlans | with_entries(.value |= {id: .id, interface: .link}) | |
), | |
interfaces: ( | |
(.network.ethernets + .network.bonds + .network.vlans) | ( | |
with_entries(select(.value.addresses) | .value |= { | |
ipv4: { | |
addresses: [ | |
.addresses[] | split("/") | { | |
address: .[0], | |
prefixLength: .[1] | tonumber | |
} | |
] | |
} | |
}) | |
) * ( | |
with_entries(select(.value.gateway4) | .value |= { | |
ipv4: { | |
routes: [{address: "0.0.0.0", prefixLength: 0, via: .gateway4}] | |
} | |
}) | |
) * ( | |
with_entries(select(.value.mtu) | .value |= {mtu: .mtu}) | |
) * ( | |
with_entries(select(.value.macaddress) | .value |= {macAddress: .macaddress}) | |
) | |
), | |
nameservers: .network[] | objects | .[] | select(.nameservers.addresses) | .nameservers.addresses | flatten | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No not the same error when piping json but an error nevertheless.
So it looks like this is customized for your personal use cases, got it!