diff --git a/nixos/modules/services/networking/shadowsocks.nix b/nixos/modules/services/networking/shadowsocks.nix index 6009a91cbb20a1..d2541f9a6dffca 100644 --- a/nixos/modules/services/networking/shadowsocks.nix +++ b/nixos/modules/services/networking/shadowsocks.nix @@ -147,7 +147,7 @@ in description = "shadowsocks-libev Daemon"; after = [ "network.target" ]; wantedBy = [ "multi-user.target" ]; - path = [ pkgs.shadowsocks-libev cfg.plugin ] ++ optional (cfg.passwordFile != null) pkgs.jq; + path = [ pkgs.shadowsocks-libev ] ++ optional (cfg.plugin != null) cfg.plugin ++ optional (cfg.passwordFile != null) pkgs.jq; serviceConfig.PrivateTmp = true; script = '' ${optionalString (cfg.passwordFile != null) '' diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index e50c2c7c801f2f..8048c885e15c2a 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -309,7 +309,7 @@ in sanoid = handleTest ./sanoid.nix {}; sddm = handleTest ./sddm.nix {}; service-runner = handleTest ./service-runner.nix {}; - shadowsocks = handleTest ./shadowsocks.nix {}; + shadowsocks = handleTest ./shadowsocks {}; shattered-pixel-dungeon = handleTest ./shattered-pixel-dungeon.nix {}; shiori = handleTest ./shiori.nix {}; signal-desktop = handleTest ./signal-desktop.nix {}; diff --git a/nixos/tests/shadowsocks.nix b/nixos/tests/shadowsocks/common.nix similarity index 82% rename from nixos/tests/shadowsocks.nix rename to nixos/tests/shadowsocks/common.nix index 6cb288f7611860..8cbbc3f2068488 100644 --- a/nixos/tests/shadowsocks.nix +++ b/nixos/tests/shadowsocks/common.nix @@ -1,5 +1,10 @@ -import ./make-test-python.nix ({ pkgs, lib, ... }: { - name = "shadowsocks"; +{ name +, plugin ? null +, pluginOpts ? "" +}: + +import ../make-test-python.nix ({ pkgs, lib, ... }: { + inherit name; meta = { maintainers = with lib.maintainers; [ hmenke ]; }; @@ -22,8 +27,9 @@ import ./make-test-python.nix ({ pkgs, lib, ... }: { port = 8488; fastOpen = false; mode = "tcp_and_udp"; - plugin = "${pkgs.shadowsocks-v2ray-plugin}/bin/v2ray-plugin"; - pluginOpts = "server;host=nixos.org"; + } // lib.optionalAttrs (plugin != null) { + inherit plugin; + pluginOpts = "server;${pluginOpts}"; }; services.nginx = { enable = true; @@ -42,10 +48,7 @@ import ./make-test-python.nix ({ pkgs, lib, ... }: { description = "connect to shadowsocks"; after = [ "network.target" ]; wantedBy = [ "multi-user.target" ]; - path = with pkgs; [ - shadowsocks-libev - shadowsocks-v2ray-plugin - ]; + path = with pkgs; [ shadowsocks-libev ]; script = '' exec ss-local \ -s 192.168.0.1 \ @@ -54,8 +57,9 @@ import ./make-test-python.nix ({ pkgs, lib, ... }: { -k 'pa$$w0rd' \ -m chacha20-ietf-poly1305 \ -a nobody \ - --plugin "${pkgs.shadowsocks-v2ray-plugin}/bin/v2ray-plugin" \ - --plugin-opts "host=nixos.org" + ${lib.optionalString (plugin != null) '' + --plugin "${plugin}" --plugin-opts "${pluginOpts}" + ''} ''; }; }; diff --git a/nixos/tests/shadowsocks/default.nix b/nixos/tests/shadowsocks/default.nix new file mode 100644 index 00000000000000..37a8c3c9d0d3bc --- /dev/null +++ b/nixos/tests/shadowsocks/default.nix @@ -0,0 +1,16 @@ +{ system ? builtins.currentSystem +, config ? { } +, pkgs ? import ../../.. { inherit system config; } +}: + +{ + "basic" = import ./common.nix { + name = "basic"; + }; + + "v2ray-plugin" = import ./common.nix { + name = "v2ray-plugin"; + plugin = "${pkgs.shadowsocks-v2ray-plugin}/bin/v2ray-plugin"; + pluginOpts = "host=nixos.org"; + }; +}