summaryrefslogtreecommitdiff
path: root/sys/net.nix
blob: b4413509693fda84c792af9e56c8a84f885ed367 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
{ lib, config, pkgs, ... }:
with lib; let
  cfg = config.local;
in
{
  options.local = with lib.types; {
    hostname = mkOption {
      type = str;
    };

    dhcpInterface = mkOption {
      type = nullOr str;
      default = null;
    };
  };

  config = {
    environment.systemPackages = [ pkgs.dhcpcd ];

    networking = {
      hostName = cfg.hostname;

      useDHCP = false;
      useNetworkd = true;

      wireguard.enable = true;
    };

    systemd.network.networks."40-${cfg.dhcpInterface}" = mkIf (cfg.dhcpInterface != null) {
      matchConfig.Name = cfg.dhcpInterface;

      networkConfig = {
        DHCP = "ipv4";
        IPv6AcceptRA = true;
        IPv6PrivacyExtensions = "kernel";
      };

      # make routing on this interface a dependency for network-online.target
      linkConfig.RequiredForOnline = "routable";
    };
  };
}