Release NixOS 23.11
[NixPkgs.git] / nixos / tests / sing-box.nix
blob582d594be3fdb2e22a3f3014a91f6308556c5cf6
1 import ./make-test-python.nix ({ lib, pkgs, ... }: {
3   name = "sing-box";
5   meta = {
6     maintainers = with lib.maintainers; [ nickcao ];
7   };
9   nodes.machine = { pkgs, ... }: {
10     environment.systemPackages = [ pkgs.curl ];
11     services.nginx = {
12       enable = true;
13       statusPage = true;
14     };
15     services.sing-box = {
16       enable = true;
17       settings = {
18         inbounds = [{
19           type = "mixed";
20           tag = "inbound";
21           listen = "127.0.0.1";
22           listen_port = 1080;
23           users = [{
24             username = "user";
25             password = { _secret = pkgs.writeText "password" "supersecret"; };
26           }];
27         }];
28         outbounds = [{
29           type = "direct";
30           tag = "outbound";
31         }];
32       };
33     };
34   };
36   testScript = ''
37     machine.wait_for_unit("nginx.service")
38     machine.wait_for_unit("sing-box.service")
40     machine.wait_for_open_port(80)
41     machine.wait_for_open_port(1080)
43     machine.succeed("curl --fail --max-time 10 --proxy http://user:supersecret@localhost:1080 http://localhost")
44     machine.fail("curl --fail --max-time 10 --proxy http://user:supervillain@localhost:1080 http://localhost")
45     machine.succeed("curl --fail --max-time 10 --proxy socks5://user:supersecret@localhost:1080 http://localhost")
46   '';