2017-08-05 13:01:52 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
with (import ./param-lib.nix lib);
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.strongswan-swanctl;
|
2018-03-26 16:18:08 +01:00
|
|
|
swanctlParams = import ./swanctl-params.nix lib;
|
2017-08-05 13:01:52 +01:00
|
|
|
in {
|
|
|
|
options.services.strongswan-swanctl = {
|
|
|
|
enable = mkEnableOption "strongswan-swanctl service";
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.strongswan;
|
|
|
|
defaultText = "pkgs.strongswan";
|
|
|
|
description = ''
|
|
|
|
The strongswan derivation to use.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-02-28 10:44:22 +00:00
|
|
|
strongswan.extraConfig = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
Contents of the <literal>strongswan.conf</literal> file.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-03-26 16:18:08 +01:00
|
|
|
swanctl = paramsToOptions swanctlParams;
|
2017-08-05 13:01:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
assertions = [
|
|
|
|
{ assertion = !config.services.strongswan.enable;
|
|
|
|
message = "cannot enable both services.strongswan and services.strongswan-swanctl. Choose either one.";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
environment.etc."swanctl/swanctl.conf".text =
|
|
|
|
paramsToConf cfg.swanctl swanctlParams;
|
|
|
|
|
|
|
|
# The swanctl command complains when the following directories don't exist:
|
|
|
|
# See: https://wiki.strongswan.org/projects/strongswan/wiki/Swanctldirectory
|
|
|
|
system.activationScripts.strongswan-swanctl-etc = stringAfter ["etc"] ''
|
|
|
|
mkdir -p '/etc/swanctl/x509' # Trusted X.509 end entity certificates
|
|
|
|
mkdir -p '/etc/swanctl/x509ca' # Trusted X.509 Certificate Authority certificates
|
|
|
|
mkdir -p '/etc/swanctl/x509ocsp'
|
|
|
|
mkdir -p '/etc/swanctl/x509aa' # Trusted X.509 Attribute Authority certificates
|
|
|
|
mkdir -p '/etc/swanctl/x509ac' # Attribute Certificates
|
|
|
|
mkdir -p '/etc/swanctl/x509crl' # Certificate Revocation Lists
|
|
|
|
mkdir -p '/etc/swanctl/pubkey' # Raw public keys
|
|
|
|
mkdir -p '/etc/swanctl/private' # Private keys in any format
|
|
|
|
mkdir -p '/etc/swanctl/rsa' # PKCS#1 encoded RSA private keys
|
|
|
|
mkdir -p '/etc/swanctl/ecdsa' # Plain ECDSA private keys
|
|
|
|
mkdir -p '/etc/swanctl/bliss'
|
|
|
|
mkdir -p '/etc/swanctl/pkcs8' # PKCS#8 encoded private keys of any type
|
|
|
|
mkdir -p '/etc/swanctl/pkcs12' # PKCS#12 containers
|
|
|
|
'';
|
|
|
|
|
|
|
|
systemd.services.strongswan-swanctl = {
|
|
|
|
description = "strongSwan IPsec IKEv1/IKEv2 daemon using swanctl";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2019-08-24 15:52:17 +01:00
|
|
|
after = [ "network-online.target" ];
|
|
|
|
path = with pkgs; [ kmod iproute iptables utillinux ];
|
2019-03-08 14:59:21 +00:00
|
|
|
environment = {
|
|
|
|
STRONGSWAN_CONF = pkgs.writeTextFile {
|
|
|
|
name = "strongswan.conf";
|
|
|
|
text = cfg.strongswan.extraConfig;
|
|
|
|
};
|
|
|
|
SWANCTL_DIR = "/etc/swanctl";
|
2017-08-05 13:01:52 +01:00
|
|
|
};
|
|
|
|
restartTriggers = [ config.environment.etc."swanctl/swanctl.conf".source ];
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = "${cfg.package}/sbin/charon-systemd";
|
|
|
|
Type = "notify";
|
|
|
|
ExecStartPost = "${cfg.package}/sbin/swanctl --load-all --noprompt";
|
|
|
|
ExecReload = "${cfg.package}/sbin/swanctl --reload";
|
|
|
|
Restart = "on-abnormal";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|