From d49e0d5fa5c245ab4e8675ba7fd286d848484fb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 16 Nov 2016 21:47:11 +0000 Subject: [PATCH] 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). --- nixos/modules/system/boot/networkd.nix | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/nixos/modules/system/boot/networkd.nix b/nixos/modules/system/boot/networkd.nix index e5ec70d8690b..86237ea6ac7c 100644 --- a/nixos/modules/system/boot/networkd.nix +++ b/nixos/modules/system/boot/networkd.nix @@ -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 = {