I’m trying to configure docker macvlan - basically replicating my blog post: Docker and macvlan networking (IPv4) – Roo's View - except on Nix.
From the docker macvlan setup - I think I’m good to go. That’s just a docker persistent state / network setup.
However, there is a boot time script I used to run using cron @reboot function to massage the network into routing magic
Here is the script
# run as root - once, on boot
ip link add myNewNet-shim link enp3s0 type macvlan mode bridge
ip addr add 192.168.1.67/32 dev myNewNet-shim
ip link set myNewNet-shim up
ip route add 192.168.1.64/30 dev myNewNet-shim
I think there are two ways to make this happen on NixOS.
Path 1 - networking magic. That will perform the same function - to cause the routes to exist. This is well beyond me honestly, but I’m open to advice if someone knows how.
Path 2 - a mechanism to run the script at boot time, once. I think I can use systemd to do this, but I’m hitting path/binary visibility issues.
I’ve added this to my /etc/nixos/configuration.nix file
systemd.services.macvlan-host-routing = {
serviceConfig.Type = "oneshot";
wantedBy = [ "docker.service" ];
script = ''
echo $PATH > /tmp/foobar;
echo 'more than one thing' >> /tmp/foobar
'';
};
Which works - upon boot I see the /tmp/foobar file created. Issuing nixos-rebuilds do not appear to cause this to run again (desired state, I only need to fiddle the network once)
However, the ip command I want to run – isn’t in the $PATH. Searching for which package the ip command is in… is eluding me.
I think I want my systemd bit to look like this
systemd.services.macvlan-host-routing = {
serviceConfig.Type = "oneshot";
wantedBy = [ "docker.service" ];
script = ''
ip link add myNewNet-shim link enp3s0 type macvlan mode bridge;
ip addr add 192.168.1.67/32 dev myNewNet-shim;
ip link set myNewNet-shim up;
ip route add 192.168.1.64/30 dev myNewNet-shim;
'';
};
but of course – the `ip’ command cannot be found, and this fails to run.
If there is a 3rd path - I’m open to it as well.