git.iko.soy/typeable/nixpkgs
on master help sign in
strongswan module: make it work with ipsec l2tp

l2tp saves its secrets into /etc/ipsec.d but strongswan would not read them. l2tp checks for /etc/ipsec.secrets includes /etc/ipsec.d and if not tries to write into it. Solution: Have the strongswan module create /etc/ipsec.d and /etc/ipsec.secrets when networkmanager_l2tp is installed. Include /etc/ipsec.secrets in /nix/store/hash-strongswan/etc/ipsec.secrets so that it can find l2tp secrets. Also when the ppp 'nopeerdns' option is used, the DNS resolver tries to write into an alternate file /etc/ppp/resolv.conf. This fails when /etc/ppp does not exist so the module creates it by default.

commitfe4f4de1c92714aa9a2add7ffb3ca83a861d6d4e authorMatthieu Coudron <mattator@gmail.com> dateTue 31 Oct 2017, 20:14 (9 years ago) parent11a9e1c
4 files changed+26−10
nixos/modules/services/networking/networkmanager.nix+1 nixos/modules/services/networking/strongswan.nix+19−4 pkgs/tools/networking/network-manager/l2tp.nix+1−6 pkgs/tools/networking/strongswan/default.nix+5
nixos/modules/services/networking/networkmanager.nix+1
@@ -335,6 +335,7 @@ in {
335335
336336 preStart = ''
337337 mkdir -m 700 -p /etc/NetworkManager/system-connections
338+ mkdir -m 700 -p /etc/ipsec.d
338339 mkdir -m 755 -p ${stateDirs}
339340 '';
340341 };
nixos/modules/services/networking/strongswan.nix+19−4
@@ -32,13 +32,13 @@ let
3232 ${caConf}
3333 '';
3434
35− strongswanConf = {setup, connections, ca, secrets, managePlugins, enabledPlugins}: toFile "strongswan.conf" ''
35+ strongswanConf = {setup, connections, ca, secretsFile, managePlugins, enabledPlugins}: toFile "strongswan.conf" ''
3636 charon {
3737 ${if managePlugins then "load_modular = no" else ""}
3838 ${if managePlugins then ("load = " + (concatStringsSep " " enabledPlugins)) else ""}
3939 plugins {
4040 stroke {
41− secrets_file = ${ipsecSecrets secrets}
41+ secrets_file = ${secretsFile}
4242 }
4343 }
4444 }
@@ -135,7 +135,18 @@ in
135135 };
136136 };
137137
138− config = with cfg; mkIf enable {
138+
139+ config = with cfg;
140+ let
141+ secretsFile = ipsecSecrets cfg.secrets;
142+ in
143+ mkIf enable
144+ {
145+
146+ # here we should use the default strongswan ipsec.secrets and
147+ # append to it (default one is empty so not a pb for now)
148+ environment.etc."ipsec.secrets".source = secretsFile;
149+
139150 systemd.services.strongswan = {
140151 description = "strongSwan IPSec Service";
141152 wantedBy = [ "multi-user.target" ];
@@ -143,11 +154,15 @@ in
143154 wants = [ "keys.target" ];
144155 after = [ "network-online.target" "keys.target" ];
145156 environment = {
146− STRONGSWAN_CONF = strongswanConf { inherit setup connections ca secrets managePlugins enabledPlugins; };
157+ STRONGSWAN_CONF = strongswanConf { inherit setup connections ca secretsFile managePlugins enabledPlugins; };
147158 };
148159 serviceConfig = {
149160 ExecStart = "${pkgs.strongswan}/sbin/ipsec start --nofork";
150161 };
162+ preStart = ''
163+ # with 'nopeerdns' setting, ppp writes into this folder
164+ mkdir -m 700 -p /etc/ppp
165+ '';
151166 };
152167 };
153168}
pkgs/tools/networking/network-manager/l2tp.nix+1−6
@@ -41,16 +41,11 @@ stdenv.mkDerivation rec {
4141 ];
4242
4343 enableParallelBuilding = true;
44− configureFlags = [
45− "--with-gnome=${if withGnome then "yes" else "no"}"
46− "--localstatedir=/var"
47− ] ;
48−
4944
5045 meta = with stdenv.lib; {
5146 description = "L2TP plugin for NetworkManager";
5247 inherit (networkmanager.meta) platforms;
53− homepage = http://github.com/nm-l2tp/network-manager-l2tp;
48+ homepage = https://github.com/nm-l2tp/network-manager-l2tp;
5449 license = licenses.gpl2;
5550 maintainers = with maintainers; [ abbradar obadz ];
5651 };
pkgs/tools/networking/strongswan/default.nix+5
@@ -76,6 +76,11 @@ stdenv.mkDerivation rec {
7676 "--enable-sqlite" ]
7777 ++ optional enableNetworkManager "--enable-nm";
7878
79+ postInstall = ''
80+ # this is needed for l2tp
81+ echo "include /etc/ipsec.secrets" >> $out/etc/ipsec.secrets
82+ '';
83+
7984 NIX_LDFLAGS = "-lgcc_s" ;
8085
8186 meta = {