1 { config, lib, pkgs, ... }:
6 cfg = config.services.softether;
8 package = cfg.package.override { dataDir = cfg.dataDir; };
17 services.softether = {
19 enable = mkEnableOption (lib.mdDoc "SoftEther VPN services");
23 default = pkgs.softether;
24 defaultText = literalExpression "pkgs.softether";
25 description = lib.mdDoc ''
26 softether derivation to use.
30 vpnserver.enable = mkEnableOption (lib.mdDoc "SoftEther VPN Server");
32 vpnbridge.enable = mkEnableOption (lib.mdDoc "SoftEther VPN Bridge");
35 enable = mkEnableOption (lib.mdDoc "SoftEther VPN Client");
39 description = lib.mdDoc ''
40 Shell commands executed when the Virtual Network Adapter(s) is/are starting.
46 description = lib.mdDoc ''
47 Shell commands executed when the Virtual Network Adapter(s) is/are shutting down.
54 default = "/var/lib/softether";
55 description = lib.mdDoc ''
56 Data directory for SoftEther VPN.
66 config = mkIf cfg.enable (
69 environment.systemPackages = [ package ];
71 systemd.services.softether-init = {
72 description = "SoftEther VPN services initial task";
73 wantedBy = [ "network.target" ];
76 RemainAfterExit = false;
79 for d in vpnserver vpnbridge vpnclient vpncmd; do
80 if ! test -e ${cfg.dataDir}/$d; then
81 ${pkgs.coreutils}/bin/mkdir -m0700 -p ${cfg.dataDir}/$d
82 install -m0600 ${package}${cfg.dataDir}/$d/hamcore.se2 ${cfg.dataDir}/$d/hamcore.se2
85 rm -rf ${cfg.dataDir}/vpncmd/vpncmd
86 ln -s ${package}${cfg.dataDir}/vpncmd/vpncmd ${cfg.dataDir}/vpncmd/vpncmd
91 (mkIf (cfg.vpnserver.enable) {
92 systemd.services.vpnserver = {
93 description = "SoftEther VPN Server";
94 after = [ "softether-init.service" ];
95 requires = [ "softether-init.service" ];
96 wantedBy = [ "network.target" ];
99 ExecStart = "${package}/bin/vpnserver start";
100 ExecStop = "${package}/bin/vpnserver stop";
103 rm -rf ${cfg.dataDir}/vpnserver/vpnserver
104 ln -s ${package}${cfg.dataDir}/vpnserver/vpnserver ${cfg.dataDir}/vpnserver/vpnserver
107 rm -rf ${cfg.dataDir}/vpnserver/vpnserver
112 (mkIf (cfg.vpnbridge.enable) {
113 systemd.services.vpnbridge = {
114 description = "SoftEther VPN Bridge";
115 after = [ "softether-init.service" ];
116 requires = [ "softether-init.service" ];
117 wantedBy = [ "network.target" ];
120 ExecStart = "${package}/bin/vpnbridge start";
121 ExecStop = "${package}/bin/vpnbridge stop";
124 rm -rf ${cfg.dataDir}/vpnbridge/vpnbridge
125 ln -s ${package}${cfg.dataDir}/vpnbridge/vpnbridge ${cfg.dataDir}/vpnbridge/vpnbridge
128 rm -rf ${cfg.dataDir}/vpnbridge/vpnbridge
133 (mkIf (cfg.vpnclient.enable) {
134 systemd.services.vpnclient = {
135 description = "SoftEther VPN Client";
136 after = [ "softether-init.service" ];
137 requires = [ "softether-init.service" ];
138 wantedBy = [ "network.target" ];
141 ExecStart = "${package}/bin/vpnclient start";
142 ExecStop = "${package}/bin/vpnclient stop";
145 rm -rf ${cfg.dataDir}/vpnclient/vpnclient
146 ln -s ${package}${cfg.dataDir}/vpnclient/vpnclient ${cfg.dataDir}/vpnclient/vpnclient
153 rm -rf ${cfg.dataDir}/vpnclient/vpnclient
155 ${cfg.vpnclient.down}
158 boot.kernelModules = [ "tun" ];