diff --git a/lib/maintainers.nix b/lib/maintainers.nix index a393648790a3..e7d26337c5f3 100644 --- a/lib/maintainers.nix +++ b/lib/maintainers.nix @@ -212,6 +212,7 @@ refnil = "Martin Lavoie "; relrod = "Ricky Elrod "; renzo = "Renzo Carbonara "; + rick68 = "Wei-Ming Yang "; rickynils = "Rickard Nilsson "; rob = "Rob Vermaas "; robberer = "Longrin Wischnewski "; diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index ebfe5afe52f3..8ee54ce7ef4b 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -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 diff --git a/nixos/modules/services/networking/softether.nix b/nixos/modules/services/networking/softether.nix new file mode 100644 index 000000000000..49538af7d351 --- /dev/null +++ b/nixos/modules/services/networking/softether.nix @@ -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" ]; + }) + + ]); + +} diff --git a/pkgs/servers/softether/4.18.nix b/pkgs/servers/softether/4.18.nix new file mode 100644 index 000000000000..4b5b67cf85b2 --- /dev/null +++ b/pkgs/servers/softether/4.18.nix @@ -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; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 9bc1ea2f1b26..96696026eacb 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -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 { };