13 enable = mkEnableOption "xl2tpd, the Layer 2 Tunnelling Protocol Daemon";
17 description = "The server-side IP address.";
18 default = "10.125.125.1";
21 clientIpRange = mkOption {
23 description = "The range from which client IPs are drawn.";
24 default = "10.125.125.2-11";
27 extraXl2tpOptions = mkOption {
29 description = "Adds extra lines to the xl2tpd configuration file.";
33 extraPppdOptions = mkOption {
35 description = "Adds extra lines to the pppd options file.";
45 config = mkIf config.services.xl2tpd.enable {
46 systemd.services.xl2tpd =
48 cfg = config.services.xl2tpd;
50 # Config files from https://help.ubuntu.com/community/L2TPServer
51 xl2tpd-conf = pkgs.writeText "xl2tpd.conf" ''
56 local ip = ${cfg.serverIp}
57 ip range = ${cfg.clientIpRange}
58 pppoptfile = ${pppd-options}
62 ${cfg.extraXl2tpOptions}
65 pppd-options = pkgs.writeText "ppp-options-xl2tpd.conf" ''
87 ${cfg.extraPppdOptions}
90 xl2tpd-ppp-wrapped = pkgs.stdenv.mkDerivation {
91 name = "xl2tpd-ppp-wrapped";
92 phases = [ "installPhase" ];
93 nativeBuildInputs = with pkgs; [ makeWrapper ];
97 makeWrapper ${pkgs.ppp}/sbin/pppd $out/bin/pppd \
98 --set LD_PRELOAD "${pkgs.libredirect}/lib/libredirect.so" \
99 --set NIX_REDIRECTS "/etc/ppp=/etc/xl2tpd/ppp"
101 makeWrapper ${pkgs.xl2tpd}/bin/xl2tpd $out/bin/xl2tpd \
102 --set LD_PRELOAD "${pkgs.libredirect}/lib/libredirect.so" \
103 --set NIX_REDIRECTS "${pkgs.ppp}/sbin/pppd=$out/bin/pppd"
108 description = "xl2tpd server";
110 requires = [ "network-online.target" ];
111 wantedBy = [ "multi-user.target" ];
114 install -m 700 -d /etc/xl2tpd/ppp
116 [ -f /etc/xl2tpd/ppp/chap-secrets ] || install -m 600 -o root -g root /dev/stdin /etc/xl2tpd/ppp/chap-secrets <<EOF
117 # Secrets for authentication using CHAP
118 # client server secret IP addresses
119 #username xl2tpd password *
122 # The documentation says this file should be present but doesn't explain why and things work even if not there:
123 [ -f /etc/xl2tpd/l2tp-secrets ] || install -m 600 -o root -g root <(echo -n "* * "; ${pkgs.apg}/bin/apg -n 1 -m 32 -x 32 -a 1 -M LCN) /etc/xl2tpd/l2tp-secrets
125 install -m 701 -o root -g root -d /run/xl2tpd
129 ExecStart = "${xl2tpd-ppp-wrapped}/bin/xl2tpd -D -c ${xl2tpd-conf} -s /etc/xl2tpd/l2tp-secrets -p /run/xl2tpd/pid -C /run/xl2tpd/control";
130 KillMode = "process";
131 Restart = "on-success";
133 PIDFile = "/run/xl2tpd/pid";