Add basic config for networkd.

This commit is contained in:
Kevin Baensch 2021-10-28 15:13:40 +02:00
parent 7a3b464306
commit 29b64aadfd
Signed by: derped
GPG key ID: C0F1D326C7626543
2 changed files with 43 additions and 1 deletions

View file

@ -1,7 +1,42 @@
{ config, ... }: { config, lib, ... }:
with lib;
{ {
networking = { networking = {
hostName = config.machine.hostName; hostName = config.machine.hostName;
useNetworkd = config.machine.useNetworkd;
useDHCP = !config.machine.useNetworkd;
dhcpcd.enable = !config.machine.useNetworkd;
}; };
# Based on
# https://github.com/NixOS/nixpkgs/issues/10001#issuecomment-905532069
systemd.network = mkIf config.machine.useNetworkd {
enable = true;
networks = let
networkConfig = {
DHCP = "yes";
DNSSEC = "yes";
DNSOverTLS = "yes";
DNS = [ "1.1.1.1" "1.0.0.1" ];
};
in {
"40-wired" = {
enable = true;
name = "en*";
dhcpV4Config.RouteMetric = 2048;
inherit networkConfig;
};
"40-wireless" = {
enable = true;
name = "wl*";
dhcpV4Config.RouteMetric = 1024;
inherit networkConfig;
};
};
};
# Wait for any interface to become available, not for all
systemd.services."systemd-networkd-wait-online".serviceConfig.ExecStart = [
"" "${config.systemd.package}/lib/systemd/systemd-networkd-wait-online --any"
];
} }

View file

@ -59,6 +59,13 @@ in {
The Machines HostName The Machines HostName
''; '';
}; };
useNetworkd = mkOption {
type = types.bool;
default = false;
description = ''
Disables dhcpcd and enables networkd.
'';
};
binaryCaches = mkOption { binaryCaches = mkOption {
type = types.listOf types.str; type = types.listOf types.str;
default = []; default = [];