git.iko.soy/typeable/nixpkgs
on master help sign in
Merge branch 'strongswan' of github.com:ip1981/nixpkgs

Add strongswan service

commit957eb52f6f4a467910088e8ef3434beca49ce8fc authorShea Levy <shea@shealevy.com> dateTue 25 Nov 2014, 09:37 (12 years ago) parentd250ca44c33004
3 files changed+133−2
nixos/modules/module-list.nix+1 nixos/modules/services/networking/strongswan.nix+130 pkgs/tools/networking/strongswan/default.nix+2−2
nixos/modules/module-list.nix+1
@@ -274,6 +274,7 @@
274274 ./services/networking/spiped.nix
275275 ./services/networking/ssh/lshd.nix
276276 ./services/networking/ssh/sshd.nix
277+ ./services/networking/strongswan.nix
277278 ./services/networking/supybot.nix
278279 ./services/networking/syncthing.nix
279280 ./services/networking/tcpcrypt.nix
nixos/modules/services/networking/strongswan.nixnew file+130
@@ -0,0 +1,130 @@
1+{ config, lib, pkgs, ... }:
2+
3+let
4+
5+ inherit (builtins) toFile;
6+ inherit (lib) concatMapStringsSep concatStringsSep mapAttrsToList
7+ mkIf mkEnableOption mkOption types;
8+
9+ cfg = config.services.strongswan;
10+
11+ ipsecSecrets = secrets: toFile "ipsec.secrets" (
12+ concatMapStringsSep "\n" (f: "include ${f}") secrets
13+ );
14+
15+ ipsecConf = {setup, connections, ca}:
16+ let
17+ # https://wiki.strongswan.org/projects/strongswan/wiki/IpsecConf
18+ makeSections = type: sections: concatStringsSep "\n\n" (
19+ mapAttrsToList (sec: attrs:
20+ "${type} ${sec}\n" +
21+ (concatStringsSep "\n" ( mapAttrsToList (k: v: " ${k}=${v}") attrs ))
22+ ) sections
23+ );
24+ setupConf = makeSections "config" { inherit setup; };
25+ connectionsConf = makeSections "conn" connections;
26+ caConf = makeSections "ca" ca;
27+
28+ in
29+ builtins.toFile "ipsec.conf" ''
30+ ${setupConf}
31+ ${connectionsConf}
32+ ${caConf}
33+ '';
34+
35+ strongswanConf = {setup, connections, ca, secrets}: toFile "strongswan.conf" ''
36+ charon {
37+ plugins {
38+ stroke {
39+ secrets_file = ${ipsecSecrets secrets}
40+ }
41+ }
42+ }
43+
44+ starter {
45+ config_file = ${ipsecConf { inherit setup connections ca; }}
46+ }
47+ '';
48+
49+in
50+{
51+ options.services.strongswan = {
52+ enable = mkEnableOption "strongSwan";
53+
54+ secrets = mkOption {
55+ type = types.listOf types.path;
56+ default = [];
57+ example = [ "/run/keys/ipsec-foo.secret" ];
58+ description = ''
59+ A list of paths to IPSec secret files. These
60+ files will be included into the main ipsec.secrets file
61+ with the `include' directive. It is safer if these paths are absolute.
62+ '';
63+ };
64+
65+ setup = mkOption {
66+ type = types.attrsOf types.str;
67+ default = {};
68+ example = { cachecrls = "yes"; strictcrlpolicy = "yes"; };
69+ description = ''
70+ A set of options for the `config setup' section of
71+ the `ipsec.conf' file. Defines general configuration parameters.
72+ '';
73+ };
74+
75+ connections = mkOption {
76+ type = types.attrsOf (types.attrsOf types.str);
77+ default = {};
78+ example = {
79+ "%default" = {
80+ keyexchange = "ikev2";
81+ keyingtries = "1";
82+ };
83+ roadwarrior = {
84+ auto = "add";
85+ leftcert = "/run/keys/moonCert.pem";
86+ leftid = "@moon.strongswan.org";
87+ leftsubnet = "10.1.0.0/16";
88+ right = "%any";
89+ };
90+ };
91+ description = ''
92+ A set of connections and their options for the `conn xxx'
93+ sections of the `ipsec.conf' file.
94+ '';
95+ };
96+
97+ ca = mkOption {
98+ type = types.attrsOf (types.attrsOf types.str);
99+ default = {};
100+ example = {
101+ strongswan = {
102+ auto = "add";
103+ cacert = "/run/keys/strongswanCert.pem";
104+ crluri = "http://crl2.strongswan.org/strongswan.crl";
105+ };
106+ };
107+ description = ''
108+ A set of CAs (certification authorities) and their options
109+ for the `ca xxx' sections of the `ipsec.conf' file.
110+ '';
111+ };
112+ };
113+
114+ config = with cfg; mkIf enable {
115+ systemd.services.strongswan = {
116+ description = "strongSwan IPSec service";
117+ wantedBy = [ "multi-user.target" ];
118+ path = with pkgs; [ kmod ]; # XXX Linux
119+ wants = [ "keys.target" ];
120+ after = [ "network.target" "keys.target" ];
121+ environment = {
122+ STRONGSWAN_CONF = strongswanConf { inherit setup connections ca secrets; };
123+ };
124+ serviceConfig = {
125+ ExecStart = "${pkgs.strongswan}/sbin/ipsec start --nofork";
126+ };
127+ };
128+ };
129+}
130+
pkgs/tools/networking/strongswan/default.nix+2−2
@@ -1,4 +1,4 @@
1−{ stdenv, fetchurl, gmp, pkgconfig }:
1+{ stdenv, fetchurl, gmp, pkgconfig, python }:
22
33stdenv.mkDerivation rec {
44 name = "strongswan-5.2.1";
@@ -10,7 +10,7 @@ stdenv.mkDerivation rec {
1010
1111 dontPatchELF = true;
1212
13− buildInputs = [ gmp pkgconfig ];
13+ buildInputs = [ gmp pkgconfig python ];
1414
1515 configureFlags = [ "--enable-swanctl" "--enable-cmd" ];
1616