13 enable = mkEnableOption "pptpd, the Point-to-Point Tunneling Protocol daemon";
17 description = "The server-side IP address.";
18 default = "10.124.124.1";
21 clientIpRange = mkOption {
23 description = "The range from which client IPs are drawn.";
24 default = "10.124.124.2-11";
27 maxClients = mkOption {
29 description = "The maximum number of simultaneous connections.";
33 extraPptpdOptions = mkOption {
35 description = "Adds extra lines to the pptpd configuration file.";
39 extraPppdOptions = mkOption {
41 description = "Adds extra lines to the pppd options file.";
51 config = mkIf config.services.pptpd.enable {
52 systemd.services.pptpd =
54 cfg = config.services.pptpd;
56 pptpd-conf = pkgs.writeText "pptpd.conf" ''
57 # Inspired from pptpd-1.4.0/samples/pptpd.conf
58 ppp ${ppp-pptpd-wrapped}/bin/pppd
59 option ${pppd-options}
60 pidfile /run/pptpd.pid
61 localip ${cfg.serverIp}
62 remoteip ${cfg.clientIpRange}
63 connections ${toString cfg.maxClients} # (Will get harmless warning if inconsistent with IP range)
66 ${cfg.extraPptpdOptions}
69 pppd-options = pkgs.writeText "ppp-options-pptpd.conf" ''
70 # From: cat pptpd-1.4.0/samples/options.pptpd | grep -v ^# | grep -v ^$
85 ${cfg.extraPppdOptions}
88 ppp-pptpd-wrapped = pkgs.stdenv.mkDerivation {
89 name = "ppp-pptpd-wrapped";
90 phases = [ "installPhase" ];
91 nativeBuildInputs = with pkgs; [ makeWrapper ];
94 makeWrapper ${pkgs.ppp}/bin/pppd $out/bin/pppd \
95 --set LD_PRELOAD "${pkgs.libredirect}/lib/libredirect.so" \
96 --set NIX_REDIRECTS "/etc/ppp=/etc/ppp-pptpd"
101 description = "pptpd server";
103 requires = [ "network-online.target" ];
104 wantedBy = [ "multi-user.target" ];
107 mkdir -p -m 700 /etc/ppp-pptpd
109 secrets="/etc/ppp-pptpd/chap-secrets"
111 [ -f "$secrets" ] || install -m 600 -o root -g root /dev/stdin "$secrets" << EOF
112 # From: pptpd-1.4.0/samples/chap-secrets
113 # Secrets for authentication using CHAP
114 # client server secret IP addresses
115 #username pptpd password *
120 ExecStart = "${pkgs.pptpd}/bin/pptpd --conf ${pptpd-conf}";
121 KillMode = "process";
122 Restart = "on-success";
124 PIDFile = "/run/pptpd.pid";