mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-08 03:26:08 +03:00
Merge pull request #38896 from abbradar/shadowsocks
Update shadowsocks-libuv and add shadowsocks service
This commit is contained in:
commit
803dca34bb
3 changed files with 135 additions and 37 deletions
|
@ -547,6 +547,7 @@
|
||||||
./services/networking/searx.nix
|
./services/networking/searx.nix
|
||||||
./services/networking/seeks.nix
|
./services/networking/seeks.nix
|
||||||
./services/networking/skydns.nix
|
./services/networking/skydns.nix
|
||||||
|
./services/networking/shadowsocks.nix
|
||||||
./services/networking/shairport-sync.nix
|
./services/networking/shairport-sync.nix
|
||||||
./services/networking/shout.nix
|
./services/networking/shout.nix
|
||||||
./services/networking/sniproxy.nix
|
./services/networking/sniproxy.nix
|
||||||
|
|
112
nixos/modules/services/networking/shadowsocks.nix
Normal file
112
nixos/modules/services/networking/shadowsocks.nix
Normal file
|
@ -0,0 +1,112 @@
|
||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
|
let
|
||||||
|
cfg = config.services.shadowsocks;
|
||||||
|
|
||||||
|
opts = {
|
||||||
|
server = cfg.localAddress;
|
||||||
|
server_port = cfg.port;
|
||||||
|
method = cfg.encryptionMethod;
|
||||||
|
mode = cfg.mode;
|
||||||
|
user = "nobody";
|
||||||
|
fast_open = true;
|
||||||
|
} // optionalAttrs (cfg.password != null) { password = cfg.password; };
|
||||||
|
|
||||||
|
configFile = pkgs.writeText "shadowsocks.json" (builtins.toJSON opts);
|
||||||
|
|
||||||
|
in
|
||||||
|
|
||||||
|
{
|
||||||
|
|
||||||
|
###### interface
|
||||||
|
|
||||||
|
options = {
|
||||||
|
|
||||||
|
services.shadowsocks = {
|
||||||
|
|
||||||
|
enable = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
description = ''
|
||||||
|
Whether to run shadowsocks-libev shadowsocks server.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
localAddress = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "0.0.0.0";
|
||||||
|
description = ''
|
||||||
|
Local address to which the server binds.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
port = mkOption {
|
||||||
|
type = types.int;
|
||||||
|
default = 8388;
|
||||||
|
description = ''
|
||||||
|
Port which the server uses.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
password = mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
default = null;
|
||||||
|
description = ''
|
||||||
|
Password for connecting clients.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
passwordFile = mkOption {
|
||||||
|
type = types.nullOr types.path;
|
||||||
|
default = null;
|
||||||
|
description = ''
|
||||||
|
Password file with a password for connecting clients.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
mode = mkOption {
|
||||||
|
type = types.enum [ "tcp_only" "tcp_and_udp" "udp_only" ];
|
||||||
|
default = "tcp_and_udp";
|
||||||
|
description = ''
|
||||||
|
Relay protocols.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
encryptionMethod = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "chacha20-ietf-poly1305";
|
||||||
|
description = ''
|
||||||
|
Encryption method. See <link xlink:href="https://github.com/shadowsocks/shadowsocks-org/wiki/AEAD-Ciphers"/>.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
###### implementation
|
||||||
|
|
||||||
|
config = mkIf cfg.enable {
|
||||||
|
assertions = singleton
|
||||||
|
{ assertion = cfg.password == null || cfg.passwordFile == null;
|
||||||
|
message = "Cannot use both password and passwordFile for shadowsocks-libev";
|
||||||
|
};
|
||||||
|
|
||||||
|
systemd.services.shadowsocks-libev = {
|
||||||
|
description = "shadowsocks-libev Daemon";
|
||||||
|
after = [ "network.target" ];
|
||||||
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
path = [ pkgs.shadowsocks-libev ] ++ optional (cfg.passwordFile != null) pkgs.jq;
|
||||||
|
serviceConfig.PrivateTmp = true;
|
||||||
|
script = ''
|
||||||
|
${optionalString (cfg.passwordFile != null) ''
|
||||||
|
cat ${configFile} | jq --arg password "$(cat "${cfg.passwordFile}")" '. + { password: $password }' > /tmp/shadowsocks.json
|
||||||
|
''}
|
||||||
|
exec ss-server -c ${if cfg.passwordFile != null then "/tmp/shadowsocks.json" else configFile}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
|
@ -1,47 +1,32 @@
|
||||||
{ withMbedTLS ? true
|
{ stdenv, fetchurl, fetchgit, cmake
|
||||||
, enableSystemSharedLib ? true
|
, libsodium, mbedtls, libev, c-ares, pcre
|
||||||
, stdenv, fetchurl, zlib
|
, asciidoc, xmlto, docbook_xml_dtd_45, docbook_xsl, libxslt
|
||||||
, openssl ? null
|
|
||||||
, mbedtls ? null
|
|
||||||
, libev ? null
|
|
||||||
, libsodium ? null
|
|
||||||
, udns ? null
|
|
||||||
, asciidoc
|
|
||||||
, xmlto
|
|
||||||
, docbook_xml_dtd_45
|
|
||||||
, docbook_xsl
|
|
||||||
, libxslt
|
|
||||||
, pcre
|
|
||||||
}:
|
}:
|
||||||
|
|
||||||
let
|
|
||||||
|
|
||||||
version = "2.5.5";
|
|
||||||
sha256 = "46a72367b7301145906185f1e4136e39d6792d27643826e409ab708351b6d0dd";
|
|
||||||
|
|
||||||
in
|
|
||||||
|
|
||||||
with stdenv.lib;
|
|
||||||
|
|
||||||
stdenv.mkDerivation rec {
|
stdenv.mkDerivation rec {
|
||||||
name = "shadowsocks-libev-${version}";
|
name = "shadowsocks-libev-${version}";
|
||||||
src = fetchurl {
|
version = "3.1.3";
|
||||||
url = "https://github.com/shadowsocks/shadowsocks-libev/archive/v${version}.tar.gz";
|
|
||||||
inherit sha256;
|
# Git tag includes CMake build files which are much more convenient.
|
||||||
|
# fetchgit because submodules.
|
||||||
|
src = fetchgit {
|
||||||
|
url = "https://github.com/shadowsocks/shadowsocks-libev";
|
||||||
|
rev = "refs/tags/v${version}";
|
||||||
|
sha256 = "16q91xh6ixfv7b5rl31an11101irv08119klfx5qgj4i6h7c41s7";
|
||||||
};
|
};
|
||||||
|
|
||||||
buildInputs = [ zlib asciidoc xmlto docbook_xml_dtd_45 docbook_xsl libxslt pcre ]
|
buildInputs = [ libsodium mbedtls libev c-ares pcre ];
|
||||||
++ optional (!withMbedTLS) openssl
|
nativeBuildInputs = [ cmake asciidoc xmlto docbook_xml_dtd_45 docbook_xsl libxslt ];
|
||||||
++ optional withMbedTLS mbedtls
|
|
||||||
++ optionals enableSystemSharedLib [libev libsodium udns];
|
|
||||||
|
|
||||||
configureFlags = optional withMbedTLS
|
cmakeFlags = [ "-DWITH_STATIC=OFF" ];
|
||||||
[ "--with-crypto-library=mbedtls"
|
|
||||||
"--with-mbedtls=${mbedtls}"
|
|
||||||
]
|
|
||||||
++ optional enableSystemSharedLib "--enable-system-shared-lib";
|
|
||||||
|
|
||||||
meta = {
|
postInstall = ''
|
||||||
|
cp lib/* $out/lib
|
||||||
|
chmod +x $out/bin/*
|
||||||
|
mv $out/pkgconfig $out/lib
|
||||||
|
'';
|
||||||
|
|
||||||
|
meta = with stdenv.lib; {
|
||||||
description = "A lightweight secured SOCKS5 proxy";
|
description = "A lightweight secured SOCKS5 proxy";
|
||||||
longDescription = ''
|
longDescription = ''
|
||||||
Shadowsocks-libev is a lightweight secured SOCKS5 proxy for embedded devices and low-end boxes.
|
Shadowsocks-libev is a lightweight secured SOCKS5 proxy for embedded devices and low-end boxes.
|
||||||
|
@ -50,6 +35,6 @@ stdenv.mkDerivation rec {
|
||||||
homepage = https://github.com/shadowsocks/shadowsocks-libev;
|
homepage = https://github.com/shadowsocks/shadowsocks-libev;
|
||||||
license = licenses.gpl3Plus;
|
license = licenses.gpl3Plus;
|
||||||
maintainers = [ maintainers.nfjinjing ];
|
maintainers = [ maintainers.nfjinjing ];
|
||||||
platforms = platforms.all;
|
platforms = platforms.linux;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue