IfState: Difference between revisions
add dhcpv4 |
m Change link to current site wiki |
||
| (3 intermediate revisions by one other user not shown) | |||
| Line 4: | Line 4: | ||
=== Examples === | === Examples === | ||
You can find several examples on the [https://ifstate.net/2. | You can find several examples on the [https://ifstate.net/2.2/examples/ IfState website]. Some include NixOS configuration instructions, while the more complex examples are covered in detail here. | ||
==== Network Namespaces (netns) ==== | ==== Network Namespaces (netns) ==== | ||
| Line 15: | Line 15: | ||
systemd.services."<name>".serviceConfig.NetworkNamespacePath = "/var/run/netns/<netnsName>"; | systemd.services."<name>".serviceConfig.NetworkNamespacePath = "/var/run/netns/<netnsName>"; | ||
} | } | ||
</syntaxhighlight>When using [ | </syntaxhighlight>When using [[NixOS Containers|nixos-containers]], network namespaces allow you to configure the network outside the container. This separation simplifies management and ensures the container’s network setup is independent of its internal configuration.<syntaxhighlight lang="nixos"> | ||
{ | { | ||
containers."<name>".networkNamespace = "/var/run/netns/<netnsName>"; | containers."<name>".networkNamespace = "/var/run/netns/<netnsName>"; | ||
| Line 167: | Line 167: | ||
<syntaxhighlight lang="nixos"> | <syntaxhighlight lang="nixos"> | ||
{ lib, pkgs, ... }: | { lib, pkgs, ... }: | ||
{ | { | ||
networking.ifstate = { | networking.ifstate = { | ||
| Line 186: | Line 172: | ||
settings = { | settings = { | ||
parameters.hooks.dhcp.script = pkgs.writeScript "ifstate-udhcp-wrapper-script.sh" '' | parameters.hooks.dhcp.script = pkgs.writeScript "ifstate-udhcp-wrapper-script.sh" '' | ||
${lib.getExe' pkgs.busybox "udhcpc"} --quit --now -i $IFS_IFNAME -b --script ${script | ${lib.getExe' pkgs.busybox "udhcpc"} --quit --now -i $IFS_IFNAME -b --script ${pkgs.busybox}/default.script | ||
''; | ''; | ||
interfaces.eth1 = { | interfaces.eth1 = { | ||
addresses = [ ]; | addresses = [ ]; | ||
hooks = [ | hooks = [ | ||
{ | { name = "dhcp"; } | ||
]; | ]; | ||
link = { | link = { | ||