aboutsummaryrefslogtreecommitdiff
path: root/nixpkgs/nixos/modules/services/networking
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/nixos/modules/services/networking')
-rw-r--r--nixpkgs/nixos/modules/services/networking/firewall.nix15
-rw-r--r--nixpkgs/nixos/modules/services/networking/networkmanager.nix25
-rw-r--r--nixpkgs/nixos/modules/services/networking/pppd.nix134
3 files changed, 162 insertions, 12 deletions
diff --git a/nixpkgs/nixos/modules/services/networking/firewall.nix b/nixpkgs/nixos/modules/services/networking/firewall.nix
index 5b3aa19af3b..5919962837a 100644
--- a/nixpkgs/nixos/modules/services/networking/firewall.nix
+++ b/nixpkgs/nixos/modules/services/networking/firewall.nix
@@ -331,6 +331,17 @@ in
'';
};
+ package = mkOption {
+ type = types.package;
+ default = pkgs.iptables;
+ defaultText = "pkgs.iptables";
+ example = literalExample "pkgs.iptables-nftables-compat";
+ description =
+ ''
+ The iptables package to use for running the firewall service."
+ '';
+ };
+
logRefusedConnections = mkOption {
type = types.bool;
default = true;
@@ -536,7 +547,7 @@ in
networking.firewall.trustedInterfaces = [ "lo" ];
- environment.systemPackages = [ pkgs.iptables ] ++ cfg.extraPackages;
+ environment.systemPackages = [ cfg.package ] ++ cfg.extraPackages;
boot.kernelModules = (optional cfg.autoLoadConntrackHelpers "nf_conntrack")
++ map (x: "nf_conntrack_${x}") cfg.connectionTrackingModules;
@@ -555,7 +566,7 @@ in
before = [ "network-pre.target" ];
after = [ "systemd-modules-load.service" ];
- path = [ pkgs.iptables ] ++ cfg.extraPackages;
+ path = [ cfg.package ] ++ cfg.extraPackages;
# FIXME: this module may also try to load kernel modules, but
# containers don't have CAP_SYS_MODULE. So the host system had
diff --git a/nixpkgs/nixos/modules/services/networking/networkmanager.nix b/nixpkgs/nixos/modules/services/networking/networkmanager.nix
index 176d26e07b0..05a78d1c448 100644
--- a/nixpkgs/nixos/modules/services/networking/networkmanager.nix
+++ b/nixpkgs/nixos/modules/services/networking/networkmanager.nix
@@ -24,9 +24,6 @@ let
enableIwd = cfg.wifi.backend == "iwd";
- # /var/lib/misc is for dnsmasq.leases.
- stateDirs = "/var/lib/NetworkManager /var/lib/dhclient /var/lib/misc";
-
configFile = pkgs.writeText "NetworkManager.conf" ''
[main]
plugins=keyfile
@@ -202,7 +199,7 @@ in {
dhcp = mkOption {
type = types.enum [ "dhclient" "dhcpcd" "internal" ];
- default = "dhclient";
+ default = "internal";
description = ''
Which program (or internal library) should be used for DHCP.
'';
@@ -472,17 +469,25 @@ in {
systemd.packages = cfg.packages;
+ systemd.tmpfiles.rules = [
+ "d /etc/NetworkManager/system-connections 0700 root root -"
+ "d /etc/ipsec.d 0700 root root -"
+ "d /var/lib/NetworkManager-fortisslvpn 0700 root root -"
+
+ "d /var/lib/dhclient 0755 root root -"
+ "d /var/lib/misc 0755 root root -" # for dnsmasq.leases
+ ];
+
systemd.services.NetworkManager = {
wantedBy = [ "network.target" ];
restartTriggers = [ configFile ];
- preStart = ''
- mkdir -m 700 -p /etc/NetworkManager/system-connections
- mkdir -m 700 -p /etc/ipsec.d
- mkdir -m 755 -p ${stateDirs}
- '';
-
aliases = [ "dbus-org.freedesktop.NetworkManager.service" ];
+
+ serviceConfig = {
+ StateDirectory = "NetworkManager";
+ StateDirectoryMode = 755; # not sure if this really needs to be 755
+ };
};
systemd.services.NetworkManager-wait-online = {
diff --git a/nixpkgs/nixos/modules/services/networking/pppd.nix b/nixpkgs/nixos/modules/services/networking/pppd.nix
new file mode 100644
index 00000000000..e96c27bd84b
--- /dev/null
+++ b/nixpkgs/nixos/modules/services/networking/pppd.nix
@@ -0,0 +1,134 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let
+ cfg = config.services.pppd;
+in
+{
+ meta = {
+ maintainers = with maintainers; [ danderson ];
+ };
+
+ options = {
+ services.pppd = {
+ enable = mkEnableOption "pppd";
+
+ package = mkOption {
+ default = pkgs.ppp;
+ defaultText = "pkgs.ppp";
+ type = types.package;
+ description = "pppd package to use.";
+ };
+
+ peers = mkOption {
+ default = {};
+ description = "pppd peers.";
+ type = types.attrsOf (types.submodule (
+ { name, ... }:
+ {
+ options = {
+ name = mkOption {
+ type = types.str;
+ default = name;
+ example = "dialup";
+ description = "Name of the PPP peer.";
+ };
+
+ enable = mkOption {
+ type = types.bool;
+ default = true;
+ example = false;
+ description = "Whether to enable this PPP peer.";
+ };
+
+ autostart = mkOption {
+ type = types.bool;
+ default = true;
+ example = false;
+ description = "Whether the PPP session is automatically started at boot time.";
+ };
+
+ config = mkOption {
+ type = types.lines;
+ default = "";
+ description = "pppd configuration for this peer, see the pppd(8) man page.";
+ };
+ };
+ }));
+ };
+ };
+ };
+
+ config = let
+ enabledConfigs = filter (f: f.enable) (attrValues cfg.peers);
+
+ mkEtc = peerCfg: {
+ "ppp/peers/${peerCfg.name}".text = peerCfg.config;
+ };
+
+ mkSystemd = peerCfg: {
+ "pppd-${peerCfg.name}" = {
+ restartTriggers = [ config.environment.etc."ppp/peers/${peerCfg.name}".source ];
+ before = [ "network.target" ];
+ wants = [ "network.target" ];
+ after = [ "network-pre.target" ];
+ environment = {
+ # pppd likes to write directly into /var/run. This is rude
+ # on a modern system, so we use libredirect to transparently
+ # move those files into /run/pppd.
+ LD_PRELOAD = "${pkgs.libredirect}/lib/libredirect.so";
+ NIX_REDIRECTS = "/var/run=/run/pppd";
+ };
+ serviceConfig = {
+ ExecStart = "${getBin cfg.package}/sbin/pppd call ${peerCfg.name} nodetach nolog";
+ Restart = "always";
+ RestartSec = 5;
+
+ AmbientCapabilities = "CAP_SYS_TTY_CONFIG CAP_NET_ADMIN CAP_NET_RAW CAP_SYS_ADMIN";
+ CapabilityBoundingSet = "CAP_SYS_TTY_CONFIG CAP_NET_ADMIN CAP_NET_RAW CAP_SYS_ADMIN";
+ KeyringMode = "private";
+ LockPersonality = true;
+ MemoryDenyWriteExecute = true;
+ NoNewPrivileges = true;
+ PrivateMounts = true;
+ PrivateTmp = true;
+ ProtectControlGroups = true;
+ ProtectHome = true;
+ ProtectHostname = true;
+ ProtectKernelModules = true;
+ # pppd can be configured to tweak kernel settings.
+ ProtectKernelTunables = false;
+ ProtectSystem = "strict";
+ RemoveIPC = true;
+ RestrictAddressFamilies = "AF_PACKET AF_UNIX AF_PPPOX AF_ATMPVC AF_ATMSVC AF_INET AF_INET6 AF_IPX";
+ RestrictNamespaces = true;
+ RestrictRealtime = true;
+ RestrictSUIDSGID = true;
+ SecureBits = "no-setuid-fixup-locked noroot-locked";
+ SystemCallFilter = "@system-service";
+ SystemCallArchitectures = "native";
+
+ # All pppd instances on a system must share a runtime
+ # directory in order for PPP multilink to work correctly. So
+ # we give all instances the same /run/pppd directory to store
+ # things in.
+ #
+ # For the same reason, we can't set PrivateUsers=true, because
+ # all instances need to run as the same user to access the
+ # multilink database.
+ RuntimeDirectory = "pppd";
+ RuntimeDirectoryPreserve = true;
+ };
+ wantedBy = mkIf peerCfg.autostart [ "multi-user.target" ];
+ };
+ };
+
+ etcFiles = map mkEtc enabledConfigs;
+ systemdConfigs = map mkSystemd enabledConfigs;
+
+ in mkIf cfg.enable {
+ environment.etc = mkMerge etcFiles;
+ systemd.services = mkMerge systemdConfigs;
+ };
+}