summaryrefslogtreecommitdiff
path: root/sys/net/interfaces.nix
blob: 38889bd2b6a811b34a4757fd1969bcb10754370a (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
{ lib, config, pkgs, ... }:
with lib; let
  cfg = config.local.net;
in
{
  options.local.net = with lib.types; {
    enable = mkEnableOption "networking stack";

    hostname = mkOption {
      type = str;
    };

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

  config = mkIf cfg.enable {
    environment.systemPackages = with pkgs; [
      dhcpcd
      dnsutils
      nmap
      socat
      tcpdump
    ];

    networking = {
      domain = mkDefault config.local.domains.host.main;
      hostName = cfg.hostname;

      firewall.logRefusedConnections = false;

      useDHCP = false;
      enableIPv6 = mkDefault true;
      useNetworkd = mkDefault true;
      useHostResolvConf = false;

      wireguard.enable = true;
    };

    systemd.network.networks = mkIf (cfg.dhcpInterface != null) {
      "40-${cfg.dhcpInterface}" = {
        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";
      };
    };
  };
}