1 { config, lib, pkgs, ... }:
6 cfg = config.services.softether;
8 package = cfg.package.override { inherit (cfg) dataDir; };
17 services.softether = {
19 enable = mkEnableOption "SoftEther VPN services";
21 package = mkPackageOption pkgs "softether" { };
23 vpnserver.enable = mkEnableOption "SoftEther VPN Server";
25 vpnbridge.enable = mkEnableOption "SoftEther VPN Bridge";
28 enable = mkEnableOption "SoftEther VPN Client";
33 Shell commands executed when the Virtual Network Adapter(s) is/are starting.
40 Shell commands executed when the Virtual Network Adapter(s) is/are shutting down.
47 default = "/var/lib/softether";
49 Data directory for SoftEther VPN.
59 config = mkIf cfg.enable (
62 environment.systemPackages = [ package ];
64 systemd.services.softether-init = {
65 description = "SoftEther VPN services initial task";
66 wantedBy = [ "network.target" ];
69 RemainAfterExit = false;
72 for d in vpnserver vpnbridge vpnclient vpncmd; do
73 if ! test -e ${cfg.dataDir}/$d; then
74 ${pkgs.coreutils}/bin/mkdir -m0700 -p ${cfg.dataDir}/$d
75 install -m0600 ${package}${cfg.dataDir}/$d/hamcore.se2 ${cfg.dataDir}/$d/hamcore.se2
78 rm -rf ${cfg.dataDir}/vpncmd/vpncmd
79 ln -s ${package}${cfg.dataDir}/vpncmd/vpncmd ${cfg.dataDir}/vpncmd/vpncmd
84 (mkIf cfg.vpnserver.enable {
85 systemd.services.vpnserver = {
86 description = "SoftEther VPN Server";
87 after = [ "softether-init.service" ];
88 requires = [ "softether-init.service" ];
89 wantedBy = [ "network.target" ];
92 ExecStart = "${package}/bin/vpnserver start";
93 ExecStop = "${package}/bin/vpnserver stop";
96 rm -rf ${cfg.dataDir}/vpnserver/vpnserver
97 ln -s ${package}${cfg.dataDir}/vpnserver/vpnserver ${cfg.dataDir}/vpnserver/vpnserver
100 rm -rf ${cfg.dataDir}/vpnserver/vpnserver
105 (mkIf cfg.vpnbridge.enable {
106 systemd.services.vpnbridge = {
107 description = "SoftEther VPN Bridge";
108 after = [ "softether-init.service" ];
109 requires = [ "softether-init.service" ];
110 wantedBy = [ "network.target" ];
113 ExecStart = "${package}/bin/vpnbridge start";
114 ExecStop = "${package}/bin/vpnbridge stop";
117 rm -rf ${cfg.dataDir}/vpnbridge/vpnbridge
118 ln -s ${package}${cfg.dataDir}/vpnbridge/vpnbridge ${cfg.dataDir}/vpnbridge/vpnbridge
121 rm -rf ${cfg.dataDir}/vpnbridge/vpnbridge
126 (mkIf cfg.vpnclient.enable {
127 systemd.services.vpnclient = {
128 description = "SoftEther VPN Client";
129 after = [ "softether-init.service" ];
130 requires = [ "softether-init.service" ];
131 wantedBy = [ "network.target" ];
134 ExecStart = "${package}/bin/vpnclient start";
135 ExecStop = "${package}/bin/vpnclient stop";
138 rm -rf ${cfg.dataDir}/vpnclient/vpnclient
139 ln -s ${package}${cfg.dataDir}/vpnclient/vpnclient ${cfg.dataDir}/vpnclient/vpnclient
146 rm -rf ${cfg.dataDir}/vpnclient/vpnclient
148 ${cfg.vpnclient.down}
151 boot.kernelModules = [ "tun" ];