git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/pppd: init (#71105)

nixos/pppd: init

commitfff04a0a495692a691adfc05a46fcff5c9a2a7d5 authorFlorian Klink <flokli@flokli.de> dateThu 17 Oct 2019, 01:15 (7 years ago) parent8f118b1ae02b3d
5 files changed+203
maintainers/maintainer-list.nix+6 nixos/modules/module-list.nix+1 nixos/modules/services/networking/pppd.nix+133 nixos/tests/all-tests.nix+1 nixos/tests/pppd.nix+62
maintainers/maintainer-list.nix+6
@@ -1450,6 +1450,12 @@
14501450 githubId = 245394;
14511451 name = "Hannu Hartikainen";
14521452 };
1453+ danderson = {
1454+ email = "dave@natulte.net";
1455+ github = "danderson";
1456+ githubId = 1918;
1457+ name = "David Anderson";
1458+ };
14531459 danharaj = {
14541460 email = "dan@obsidian.systems";
14551461 github = "danharaj";
nixos/modules/module-list.nix+1
@@ -666,6 +666,7 @@
666666 ./services/networking/polipo.nix
667667 ./services/networking/powerdns.nix
668668 ./services/networking/pdns-recursor.nix
669+ ./services/networking/pppd.nix
669670 ./services/networking/pptpd.nix
670671 ./services/networking/prayer.nix
671672 ./services/networking/privoxy.nix
nixos/modules/services/networking/pppd.nixnew file+133
@@ -0,0 +1,133 @@
1+{ config, lib, pkgs, ... }:
2+
3+with lib;
4+
5+let
6+ cfg = config.services.pppd;
7+in
8+{
9+ meta = {
10+ maintainers = with maintainers; [ danderson ];
11+ };
12+
13+ options = {
14+ services.pppd = {
15+ enable = mkEnableOption "pppd";
16+
17+ package = mkOption {
18+ default = pkgs.ppp;
19+ defaultText = "pkgs.ppp";
20+ type = types.package;
21+ description = "pppd package to use.";
22+ };
23+
24+ peers = mkOption {
25+ default = {};
26+ type = types.attrsOf (types.submodule (
27+ { name, ... }:
28+ {
29+ options = {
30+ name = mkOption {
31+ type = types.str;
32+ default = name;
33+ example = "dialup";
34+ description = "Name of the PPP peer.";
35+ };
36+
37+ enable = mkOption {
38+ type = types.bool;
39+ default = true;
40+ example = false;
41+ description = "Whether to enable this PPP peer.";
42+ };
43+
44+ autostart = mkOption {
45+ type = types.bool;
46+ default = true;
47+ example = false;
48+ description = "Whether the PPP session is automatically started at boot time.";
49+ };
50+
51+ config = mkOption {
52+ type = types.lines;
53+ default = "";
54+ description = "pppd configuration for this peer, see the pppd(8) man page.";
55+ };
56+ };
57+ }));
58+ };
59+ };
60+ };
61+
62+ config = let
63+ enabledConfigs = filter (f: f.enable) (attrValues cfg.peers);
64+
65+ mkEtc = peerCfg: {
66+ "ppp/peers/${peerCfg.name}".text = peerCfg.config;
67+ };
68+
69+ mkSystemd = peerCfg: {
70+ "pppd-${peerCfg.name}" = {
71+ restartTriggers = [ config.environment.etc."ppp/peers/${peerCfg.name}".source ];
72+ before = [ "network.target" ];
73+ wants = [ "network.target" ];
74+ after = [ "network-pre.target" ];
75+ environment = {
76+ # pppd likes to write directly into /var/run. This is rude
77+ # on a modern system, so we use libredirect to transparently
78+ # move those files into /run/pppd.
79+ LD_PRELOAD = "${pkgs.libredirect}/lib/libredirect.so";
80+ NIX_REDIRECTS = "/var/run=/run/pppd";
81+ };
82+ serviceConfig = {
83+ ExecStart = "${getBin cfg.package}/sbin/pppd call ${peerCfg.name} nodetach nolog";
84+ Restart = "always";
85+ RestartSec = 5;
86+
87+ AmbientCapabilities = "CAP_SYS_TTY_CONFIG CAP_NET_ADMIN CAP_NET_RAW CAP_SYS_ADMIN";
88+ CapabilityBoundingSet = "CAP_SYS_TTY_CONFIG CAP_NET_ADMIN CAP_NET_RAW CAP_SYS_ADMIN";
89+ KeyringMode = "private";
90+ LockPersonality = true;
91+ MemoryDenyWriteExecute = true;
92+ NoNewPrivileges = true;
93+ PrivateMounts = true;
94+ PrivateTmp = true;
95+ ProtectControlGroups = true;
96+ ProtectHome = true;
97+ ProtectHostname = true;
98+ ProtectKernelModules = true;
99+ # pppd can be configured to tweak kernel settings.
100+ ProtectKernelTunables = false;
101+ ProtectSystem = "strict";
102+ RemoveIPC = true;
103+ RestrictAddressFamilies = "AF_PACKET AF_UNIX AF_PPPOX AF_ATMPVC AF_ATMSVC AF_INET AF_INET6 AF_IPX";
104+ RestrictNamespaces = true;
105+ RestrictRealtime = true;
106+ RestrictSUIDSGID = true;
107+ SecureBits = "no-setuid-fixup-locked noroot-locked";
108+ SystemCallFilter = "@system-service";
109+ SystemCallArchitectures = "native";
110+
111+ # All pppd instances on a system must share a runtime
112+ # directory in order for PPP multilink to work correctly. So
113+ # we give all instances the same /run/pppd directory to store
114+ # things in.
115+ #
116+ # For the same reason, we can't set PrivateUsers=true, because
117+ # all instances need to run as the same user to access the
118+ # multilink database.
119+ RuntimeDirectory = "pppd";
120+ RuntimeDirectoryPreserve = true;
121+ };
122+ wantedBy = mkIf peerCfg.autostart [ "multi-user.target" ];
123+ };
124+ };
125+
126+ etcFiles = map mkEtc enabledConfigs;
127+ systemdConfigs = map mkSystemd enabledConfigs;
128+
129+ in mkIf cfg.enable {
130+ environment.etc = mkMerge etcFiles;
131+ systemd.services = mkMerge systemdConfigs;
132+ };
133+}
nixos/tests/all-tests.nix+1
@@ -227,6 +227,7 @@ in
227227 postgresql = handleTest ./postgresql.nix {};
228228 postgresql-wal-receiver = handleTest ./postgresql-wal-receiver.nix {};
229229 powerdns = handleTest ./powerdns.nix {};
230+ pppd = handleTest ./pppd.nix {};
230231 predictable-interface-names = handleTest ./predictable-interface-names.nix {};
231232 printing = handleTest ./printing.nix {};
232233 prometheus = handleTest ./prometheus.nix {};
nixos/tests/pppd.nixnew file+62
@@ -0,0 +1,62 @@
1+import ./make-test.nix (
2+ let
3+ chap-secrets = {
4+ text = ''"flynn" * "reindeerflotilla" *'';
5+ mode = "0640";
6+ };
7+ in {
8+ nodes = {
9+ server = {config, pkgs, ...}: {
10+ config = {
11+ # Run a PPPoE access concentrator server. It will spawn an
12+ # appropriate PPP server process when a PPPoE client sets up a
13+ # PPPoE session.
14+ systemd.services.pppoe-server = {
15+ restartTriggers = [
16+ config.environment.etc."ppp/pppoe-server-options".source
17+ config.environment.etc."ppp/chap-secrets".source
18+ ];
19+ after = ["network.target"];
20+ serviceConfig = {
21+ ExecStart = "${pkgs.rpPPPoE}/sbin/pppoe-server -F -O /etc/ppp/pppoe-server-options -q ${pkgs.ppp}/sbin/pppd -I eth1 -L 192.0.2.1 -R 192.0.2.2";
22+ };
23+ wantedBy = ["multi-user.target"];
24+ };
25+ environment.etc = {
26+ "ppp/pppoe-server-options".text = ''
27+ lcp-echo-interval 10
28+ lcp-echo-failure 2
29+ plugin rp-pppoe.so
30+ require-chap
31+ nobsdcomp
32+ noccp
33+ novj
34+ '';
35+ "ppp/chap-secrets" = chap-secrets;
36+ };
37+ };
38+ };
39+ client = {config, pkgs, ...}: {
40+ services.pppd = {
41+ enable = true;
42+ peers.test = {
43+ config = ''
44+ plugin rp-pppoe.so eth1
45+ name "flynn"
46+ noipdefault
47+ persist
48+ noauth
49+ debug
50+ '';
51+ };
52+ };
53+ environment.etc."ppp/chap-secrets" = chap-secrets;
54+ };
55+ };
56+
57+ testScript = ''
58+ startAll;
59+ $client->waitUntilSucceeds("ping -c1 -W1 192.0.2.1");
60+ $server->waitUntilSucceeds("ping -c1 -W1 192.0.2.2");
61+ '';
62+ })