NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.42k stars 13.63k forks source link

neworking.defaultGateway6 is not stateful across reboots #138838

Open Wulfsta opened 2 years ago

Wulfsta commented 2 years ago

Describe the bug

Adding

...
networking.defaultGateway6 = {
  address = "<address>";
  interface = "<interface>";
  metric = "<metric>";
};
...

to the NixOS config and running nixos-rebuild switch results in a netstat -6 -rn -f inet6 entry,

...
::/0                           <address>           UG   <metric> 5      0 <interface>
...

that does not persist after a reboot. In my case in particular this causes IPv6 to stop working on my machine.

Expected behavior

netstat entry remains and IPv6 continues to work across boots.

Wulfsta commented 2 years ago

@grahamc Not sure who to ping about networking stuff, but I want to at least alert someone.

Artturin commented 2 years ago

the network-setup.service should set it on boot https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/tasks/network-interfaces-scripted.nix#L91

does the entry get made if you restart the service manually sudo systemctl restart network-setup.service

and check the status of the service before and after systemctl status network-setup.service

Wulfsta commented 2 years ago

I agree, it should set it on boot, but something is happening such that it is not. Looking at the status after boot, it appears the script has been run without detected failures (the script has sensible commands in it as well), but the entry is not in the table. Restarting the service as you suggested does properly add the entry to the routing table. I wonder if the targets are somehow wrong, and another networking component is removing the entry?

Artturin commented 2 years ago
            after = [ "network-pre.target" "systemd-udevd.service" "systemd-sysctl.service" ];
            before = [ "network.target" "shutdown.target" ];
            wants = [ "network.target" ];
            # exclude bridges from the partOf relationship to fix container networking bug #47210
            partOf = map (i: "network-addresses-${i.name}.service") (filter (i: !(hasAttr i.name cfg.bridges)) interfaces);
            conflicts = [ "shutdown.target" ];
            wantedBy = [ "multi-user.target" ] ++ optional hasDefaultGatewaySet "network-online.target";

the ++ optional hasDefault... was added in b1799084147b

if you would like to work on this then clone nixpkgs and follow the instructions here to use the edited module in your config https://nixos.wiki/wiki/Nixpkgs/Reviewing_changes#Modules

Wulfsta commented 2 years ago

Yes, I already looked at that, and am aware of how to work in this repo.

stale[bot] commented 2 years ago

I marked this as stale due to inactivity. → More info

Sean1708 commented 7 months ago

I'm not sure whether it's the same cause or not (I think it's likely to be related at the very least) but I've also noticed that if you disable IPv6 with networking.enableIPv6 = false; (at least on an RPi4, haven't tested anything else) and reboot then it'll be enabled again. The only way I've found to redisable it is to rebuild with IPv6 enabled and then rebuild again with it disabled (there's probably a systemd unit I could run but I haven't had been able to figure out which one).