Merge pull request #82941 from flokli/systemd-network-link-no-networkd-without-lib-pushdown

nixos/systemd: apply .link even when networkd is disabled (without the lib refactor this time)
This commit is contained in:
Graham Christensen 2020-03-19 09:53:38 -04:00 committed by GitHub
commit 7f0a2998ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 89 additions and 42 deletions

View File

@ -768,6 +768,14 @@ auth required pam_succeed_if.so uid >= 1000 quiet
</itemizedlist> </itemizedlist>
</para> </para>
</listitem> </listitem>
<listitem>
<para>
The <link linkend="opt-systemd.network.links">systemd.network.links</link> option is now respected
even when <link linkend="opt-systemd.network.enable">systemd-networkd</command> is disabled.
This mirrors the behaviour of systemd - It's udev that parses <literal>.link</literal> files,
not <command>systemd-networkd</command>.
</para>
</listitem>
</itemizedlist> </itemizedlist>
</section> </section>
</section> </section>

View File

@ -69,13 +69,14 @@ in
environment.systemPackages = [ cfg.package ]; environment.systemPackages = [ cfg.package ];
# Prevent systemd from potentially changing the MAC address # Prevent systemd from potentially changing the MAC address
environment.etc."systemd/network/50-zerotier.link".text = '' systemd.network.links."50-zerotier" = {
[Match] matchConfig = {
OriginalName=zt* OriginalName = "zt*";
};
[Link] linkConfig = {
AutoNegotiation=false AutoNegotiation = false;
MACAddressPolicy=none MACAddressPolicy = "none";
''; };
};
}; };
} }

View File

@ -355,6 +355,14 @@ let
}; };
linkOptions = commonNetworkOptions // { linkOptions = commonNetworkOptions // {
# overwrite enable option from above
enable = mkOption {
default = true;
type = types.bool;
description = ''
Whether to enable this .link unit. It's handled by udev no matter if <command>systemd-networkd</command> is enabled or not
'';
};
linkConfig = mkOption { linkConfig = mkOption {
default = {}; default = {};
@ -1045,7 +1053,14 @@ in
}; };
config = mkIf config.systemd.network.enable { config = mkMerge [
# .link units are honored by udev, no matter if systemd-networkd is enabled or not.
{
systemd.network.units = mapAttrs' (n: v: nameValuePair "${n}.link" (linkToUnit n v)) cfg.links;
environment.etc = unitFiles;
}
(mkIf config.systemd.network.enable {
users.users.systemd-network.group = "systemd-network"; users.users.systemd-network.group = "systemd-network";
@ -1053,12 +1068,9 @@ in
"systemd-networkd.service" "systemd-networkd-wait-online.service" "systemd-networkd.service" "systemd-networkd-wait-online.service"
]; ];
systemd.network.units = mapAttrs' (n: v: nameValuePair "${n}.link" (linkToUnit n v)) cfg.links systemd.network.units = mapAttrs' (n: v: nameValuePair "${n}.netdev" (netdevToUnit n v)) cfg.netdevs
// mapAttrs' (n: v: nameValuePair "${n}.netdev" (netdevToUnit n v)) cfg.netdevs
// mapAttrs' (n: v: nameValuePair "${n}.network" (networkToUnit n v)) cfg.networks; // mapAttrs' (n: v: nameValuePair "${n}.network" (networkToUnit n v)) cfg.networks;
environment.etc = unitFiles;
systemd.services.systemd-networkd = { systemd.services.systemd-networkd = {
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
restartTriggers = attrNames unitFiles; restartTriggers = attrNames unitFiles;
@ -1084,5 +1096,6 @@ in
}; };
services.resolved.enable = mkDefault true; services.resolved.enable = mkDefault true;
}; })
];
} }

View File

@ -655,6 +655,31 @@ let
), "The IPv6 routing table has not been properly cleaned:\n{}".format(ipv6Residue) ), "The IPv6 routing table has not been properly cleaned:\n{}".format(ipv6Residue)
''; '';
}; };
# even with disabled networkd, systemd.network.links should work
# (as it's handled by udev, not networkd)
link = {
name = "Link";
nodes.client = { pkgs, ... }: {
virtualisation.vlans = [ 1 ];
networking = {
useNetworkd = networkd;
useDHCP = false;
};
systemd.network.links."50-foo" = {
matchConfig = {
Name = "foo";
Driver = "dummy";
};
linkConfig.MTUBytes = "1442";
};
};
testScript = ''
print(client.succeed("ip l add name foo type dummy"))
print(client.succeed("stat /etc/systemd/network/50-foo.link"))
client.succeed("udevadm settle")
assert "mtu 1442" in client.succeed("ip l show dummy0")
'';
};
}; };
in mapAttrs (const (attrs: makeTest (attrs // { in mapAttrs (const (attrs: makeTest (attrs // {