networkd: allow to supply own unit files

Networkd units can contain secrets. In future also wireguard vpn will be supported by
networkd. To avoid leakage of private keys, those could be then also put outside
of the /nix/store

Having a writeable /etc/systemd/network also allows to quick fix network issues,
when upgrading `nixos-rebuild switch` would require network on its own (due
updates).
This commit is contained in:
Jörg Thalheim 2016-11-16 21:47:11 +00:00
parent 45c1c50ddd
commit d49e0d5fa5

@ -606,6 +606,10 @@ let
'';
};
unitFiles = map (name: {
target = "systemd/network/${name}";
source = "${cfg.units.${name}.unit}/${name}";
}) (attrNames cfg.units);
in
{
@ -657,17 +661,15 @@ in
systemd.additionalUpstreamSystemUnits =
[ "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}.link" (linkToUnit n v)) cfg.links
// mapAttrs' (n: v: nameValuePair "${n}.netdev" (netdevToUnit n v)) cfg.netdevs
// mapAttrs' (n: v: nameValuePair "${n}.network" (networkToUnit n v)) cfg.networks;
environment.etc."systemd/network".source =
generateUnits "network" cfg.units [] [];
environment.etc = unitFiles;
systemd.services.systemd-networkd = {
wantedBy = [ "multi-user.target" ];
restartTriggers = [ config.environment.etc."systemd/network".source ];
restartTriggers = map (f: f.source) (unitFiles);
};
systemd.services.systemd-networkd-wait-online = {