Merge pull request #9376 from rick68/softether

softether: support SoftEther VPN 4.18
This commit is contained in:
lethalman 2015-08-26 10:45:46 +02:00
commit a45a0911d4
5 changed files with 208 additions and 0 deletions

View file

@ -212,6 +212,7 @@
refnil = "Martin Lavoie <broemartino@gmail.com>";
relrod = "Ricky Elrod <ricky@elrod.me>";
renzo = "Renzo Carbonara <renzocarbonara@gmail.com>";
rick68 = "Wei-Ming Yang <rick68@gmail.com>";
rickynils = "Rickard Nilsson <rickynils@gmail.com>";
rob = "Rob Vermaas <rob.vermaas@gmail.com>";
robberer = "Longrin Wischnewski <robberer@freakmail.de>";

View file

@ -331,6 +331,7 @@
./services/networking/seeks.nix
./services/networking/skydns.nix
./services/networking/shout.nix
./services/networking/softether.nix
./services/networking/spiped.nix
./services/networking/sslh.nix
./services/networking/ssh/lshd.nix

View file

@ -0,0 +1,150 @@
{ config, lib, pkgs, ... }:
with lib;
let
pkg = pkgs.softether;
cfg = config.services.softether;
in
{
###### interface
options = {
services.softether = {
enable = mkEnableOption "SoftEther VPN services";
vpnserver.enable = mkEnableOption "SoftEther VPN Server";
vpnbridge.enable = mkEnableOption "SoftEther VPN Bridge";
vpnclient = {
enable = mkEnableOption "SoftEther VPN Client";
up = mkOption {
type = types.lines;
default = "";
description = ''
Shell commands executed when the Virtual Network Adapter(s) is/are starting.
'';
};
down = mkOption {
type = types.lines;
default = "";
description = ''
Shell commands executed when the Virtual Network Adapter(s) is/are shutting down.
'';
};
};
dataDir = mkOption {
type = types.string;
default = "${pkg.dataDir}";
description = ''
Data directory for SoftEther VPN.
'';
};
};
};
###### implementation
config = mkIf cfg.enable (
mkMerge [{
environment.systemPackages = [
(pkgs.lib.overrideDerivation pkg (attrs: {
dataDir = cfg.dataDir;
}))
];
jobs.softether = {
description = "SoftEther VPN services initial job";
startOn = "started network-interfaces";
preStart = ''
for d in vpnserver vpnbridge vpnclient vpncmd; do
if ! test -e ${cfg.dataDir}/$d; then
${pkgs.coreutils}/bin/mkdir -m0700 -p ${cfg.dataDir}/$d
install -m0600 ${pkg}${cfg.dataDir}/$d/hamcore.se2 ${cfg.dataDir}/$d/hamcore.se2
fi
done
rm -rf ${cfg.dataDir}/vpncmd/vpncmd
ln -s ${pkg}${cfg.dataDir}/vpncmd/vpncmd ${cfg.dataDir}/vpncmd/vpncmd
'';
exec = "true";
};
}
(mkIf (cfg.vpnserver.enable) {
systemd.services.vpnserver = {
description = "SoftEther VPN Server";
after = [ "network-interfaces.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
ExecStart = "${pkg}/bin/vpnserver start";
ExecStop = "${pkg}/bin/vpnserver stop";
Type = "forking";
};
preStart = ''
rm -rf ${cfg.dataDir}/vpnserver/vpnserver
ln -s ${pkg}${cfg.dataDir}/vpnserver/vpnserver ${cfg.dataDir}/vpnserver/vpnserver
'';
postStop = ''
rm -rf ${cfg.dataDir}/vpnserver/vpnserver
'';
};
})
(mkIf (cfg.vpnbridge.enable) {
systemd.services.vpnbridge = {
description = "SoftEther VPN Bridge";
after = [ "network-interfaces.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
ExecStart = "${pkg}/bin/vpnbridge start";
ExecStop = "${pkg}/bin/vpnbridge stop";
Type = "forking";
};
preStart = ''
rm -rf ${cfg.dataDir}/vpnbridge/vpnbridge
ln -s ${pkg}${cfg.dataDir}/vpnbridge/vpnbridge ${cfg.dataDir}/vpnbridge/vpnbridge
'';
postStop = ''
rm -rf ${cfg.dataDir}/vpnbridge/vpnbridge
'';
};
})
(mkIf (cfg.vpnclient.enable) {
systemd.services.vpnclient = {
description = "SoftEther VPN Client";
after = [ "network-interfaces.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
ExecStart = "${pkg}/bin/vpnclient start";
ExecStop = "${pkg}/bin/vpnclient stop";
Type = "forking";
};
preStart = ''
rm -rf ${cfg.dataDir}/vpnclient/vpnclient
ln -s ${pkg}${cfg.dataDir}/vpnclient/vpnclient ${cfg.dataDir}/vpnclient/vpnclient
'';
postStart = ''
sleep 1
${cfg.vpnclient.up}
'';
postStop = ''
rm -rf ${cfg.dataDir}/vpnclient/vpnclient
sleep 1
${cfg.vpnclient.down}
'';
};
boot.kernelModules = [ "tun" ];
})
]);
}

View file

@ -0,0 +1,53 @@
{ stdenv, fetchurl
, openssl, readline, ncurses, zlib }:
let
os = if stdenv.isLinux then "1"
else if stdenv.isFreeBSD then "2"
else if stdenv.isSunOS then "3"
else if stdenv.isDarwin then "4"
else if stdenv.isOpenBSD then "5"
else "";
cpuBits = if stdenv.is64bit then "2" else "1";
in
stdenv.mkDerivation rec {
name = "softether-${version}";
version = "4.18";
build = "9570";
compiledDate = "2015.07.26";
dataDir = "/var/lib/softether";
src = fetchurl {
url = "http://www.softether-download.com/files/softether/v${version}-${build}-rtm-${compiledDate}-tree/Source_Code/softether-src-v${version}-${build}-rtm.tar.gz";
sha256 = "585d61e524d3cad90806cbeb52ebe54b5144359e6c44676e8e7fb5683ffd4574";
};
buildInputs = [ openssl readline ncurses zlib ];
preConfigure = ''
echo "${os}
${cpuBits}
" | ./configure
rm configure
'';
buildPhase = ''
mkdir -p $out/bin
sed -i \
-e "/INSTALL_BINDIR=/s|/usr/bin|/bin|g" \
-e "/_DIR=/s|/usr|${dataDir}|g" \
-e "s|\$(INSTALL|$out/\$(INSTALL|g" \
-e "/echo/s|echo $out/|echo |g" \
Makefile
'';
meta = with stdenv.lib; {
description = "An Open-Source Free Cross-platform Multi-protocol VPN Program";
homepage = https://www.softether.org/;
license = licenses.gpl2;
maintainers = [ maintainers.rick68 ];
platforms = platforms.all;
};
}

View file

@ -3040,6 +3040,9 @@ let
socat2pre = lowPrio (callPackage ../tools/networking/socat/2.x.nix { });
softether_4_18 = callPackage ../servers/softether/4.18.nix { };
softether = softether_4_18;
sourceHighlight = callPackage ../tools/text/source-highlight { };
spaceFM = callPackage ../applications/misc/spacefm { };