Every NixOS rebuild creates a new Tailscale machine

I’m using Tailscale automated in Systemd with this configuration.nix setup. Every time I do a rebuild of NixOS, Tailscale interprets that as a new machine and adds a new entry to its machine list with a number appended, and disconnects the prior version. I end up with a machine list like this:

100.60.1.37     z11pa-d8-1           tagged-devices linux   offline
100.81.16.123   z11pa-d8-2           tagged-devices linux   offline
100.73.19.128   z11pa-d8-3           tagged-devices linux   offline
100.79.176.117  z11pa-d8-4           tagged-devices linux   offline
100.105.25.29   z11pa-d8-5           tagged-devices linux   offline
100.71.180.121  z11pa-d8-6           tagged-devices linux   offline
100.90.122.127  z11pa-d8-7           tagged-devices linux   -
100.90.123.127  z11pa-d8             tagged-devices linux   offline

This obviously breaks any script that references the original machine name, ‘z11pa-d8’. Anyone know how to make the current machine persist through rebuilds?

I have /etc/machine-id persisted in my ‘Erase Your Darlings’ setup, so it remains constant across rebuilds.

It might be worth checking carefully if there is an ordering issue between tailscale starting, and this file getting put back in place. Especially if you’re doing anything with tailscale in stage 1, but I don’t think you are.

1 Like

I don’t know the Tailscale internals but are you persisting its state directory /var/lib/tailscale/? If you’re wiping that on every boot, that’d obviously make it create a new identity on every boot; requiring you to login aswell.

1 Like