-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.nix
1569 lines (1474 loc) · 67.3 KB
/
module.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
packages:
{
lib,
config,
pkgs,
...
}:
let
inherit (lib) optionals mkIf optionalAttrs;
cfg = config.services.hysteria;
mkFormatsOption =
options:
lib.mkOption (
options
// (optionalAttrs (!(options ? default)) {
default = null;
type = lib.types.nullOr options.type;
})
);
in
with lib.types;
{
meta.maintainers = with lib.maintainers; [ eum3l ];
imports =
let
mkHysteria =
type:
(
let
format = pkgs.formats.yaml { };
cfg = config.services.hysteria.${type};
settings =
if cfg.settings != null then
format.generate "hysteria-${type}-config.yaml" cfg.settings
else
cfg.settingsFile;
in
{
boot.kernel.sysctl = mkIf (type == "client") (
optionalAttrs (cfg.settings.tun != null) {
"net.ipv4.conf.default.rp_filter" = 2;
"net.ipv4.conf.all.rp_filter" = 2;
}
);
networking.firewall.allowedTCPPorts =
let
getPort = address: lib.toInt (builtins.elemAt (builtins.split ":" address) 2);
in
mkIf (type == "server" && cfg.openFirewall) (
optionals (cfg.settings != null) (
[ (getPort cfg.settings.listen) ]
++ (optionals (cfg.settings.masquerade != null) [
(getPort cfg.settings.masquerade.listenHTTP)
(getPort cfg.settings.masquerade.listenHTTPS)
])
)
);
security.wrappers."hysteria-${type}" = rec {
owner = cfg.user;
group = owner;
capabilities = "cap_net_bind_service${lib.optionalString (type == "client") ",cap_net_admin"}+ep";
source = "${cfg.package}/bin/hysteria";
};
systemd.services."hysteria-${type}" = {
description = "Hysteria ${type}";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
preStart = mkIf (settings != null) "ln -sf ${settings} config.yaml";
script = ''
${config.security.wrapperDir}/hysteria-${type} ${type} \
--disable-update-check \
-f ${cfg.logFormat} \
-l ${cfg.logLevel} \
-c config.yaml
'';
serviceConfig = {
WorkingDirectory = cfg.dir;
Restart = "always";
User = cfg.user;
};
};
users = {
groups.${cfg.user} = { };
users.${cfg.user} = {
description = "hysteria ${type} user";
isSystemUser = true;
group = cfg.user;
home = cfg.dir;
createHome = true;
homeMode = "750";
};
};
}
);
in
[
(mkIf cfg.client.enable (mkHysteria "client"))
(mkIf cfg.server.enable (mkHysteria "server"))
{
assertions =
let
set = value: value != null;
in
mkIf (set cfg.server.settings) [
(mkIf (set cfg.server.settings.acl) {
assertion = (!set cfg.server.settings.acl.inline) && (!set cfg.server.settings.acl.file);
message = ''
You can either set `file` or `inline`, but not both. (server.settings.acl)
'';
})
{
assertion = !((set cfg.server.settings.tls) && (set cfg.server.settings.acme));
message = ''
You can either set `tls` or `acme`, but not both. (server.settings)
'';
}
];
}
];
options.services.hysteria =
let
defaultOptions = type: {
enable = lib.mkEnableOption ''
Hysteria (${type}, a powerful, lightning fast and censorship resistant proxy.
'';
package = lib.mkPackageOption packages.${pkgs.system} "hysteria" { default = "hysteria"; };
settingsFile = mkFormatsOption {
type = path;
description = ''
Path to file containing Hysteria settings.
'';
};
logFormat = mkFormatsOption {
description = ''
Format of the logs.
'';
default = "json";
example = "console";
type = enum [
"json"
"console"
];
};
logLevel = mkFormatsOption {
description = ''
Level of the logs.
'';
default = "info";
example = "warn";
type = enum [
"debug"
"info"
"warn"
"error"
];
};
dir = mkFormatsOption {
default = "/var/lib/hysteria-${type}";
type = singleLineStr;
description = ''
Working directory of the OpenGFW service and home of `hysteria-${type}.user`.
'';
};
user = mkFormatsOption {
description = "Username of the Hysteria user";
type = str;
default = "hysteria-${type}";
};
};
defaultSettings = {
obfs = mkFormatsOption {
description = ''
By default, the Hysteria protocol mimics HTTP/3.
If your network specifically blocks QUIC or HTTP/3 traffic (but not UDP in general), obfuscation can be used to work around this.
We currently have an obfuscation implementation called "Salamander" that converts packets into seamingly random bytes with no pattern.
This feature requires a password that must be identical on both the client and server sides.
'';
type = submodule {
options = {
type = mkFormatsOption {
description = "Obfuscation type";
default = "salamander";
type = enum [ "salamander" ];
};
salamander = {
password = mkFormatsOption {
example = "cry_me_a_r1ver";
description = ''
Replace with a strong password of your choice.
'';
type = str;
};
};
};
};
};
quic = mkFormatsOption {
description = ''
The default stream and connection receive window sizes are 8MB and 20MB, respectively.
**We do not recommend changing these values unless you fully understand what you are doing.**
If you choose to change these values, we recommend keeping the ratio of stream receive window to connection receive window at 2:5.
'';
type = submodule {
options = {
initStreamReceiveWindow = mkFormatsOption {
description = "The initial QUIC stream receive window size.";
default = 8388608;
type = int;
};
maxStreamReceiveWindow = mkFormatsOption {
description = "The maximum QUIC stream receive window size.";
default = 8388608;
type = int;
};
initConnReceiveWindow = mkFormatsOption {
description = "The initial QUIC connection receive window size.";
default = 20971520;
type = int;
};
maxConnReceiveWindow = mkFormatsOption {
description = "The maximum QUIC connection receive window size.";
default = 20971520;
type = int;
};
maxIdleTimeout = mkFormatsOption {
description = ''
The maximum idle timeout.
How long the server will consider the client still connected without any activity.
'';
default = "30s";
example = "60s";
type = str;
};
maxIncomingStreams = mkFormatsOption {
description = "The maximum number of concurrent incoming streams.";
default = 1024;
example = 2048;
type = int;
};
disablePathMTUDiscovery = mkFormatsOption {
description = "Disable QUIC path MTU discovery.";
default = false;
example = true;
type = bool;
};
};
};
};
};
in
{
server = (defaultOptions "server") // {
openFirewall = mkFormatsOption {
description = ''
Open the firewall for the Hysteria server.
'';
default = false;
example = true;
type = bool;
};
settings = mkFormatsOption {
description = "Hysteria server settings";
type = submodule {
options = defaultSettings // {
listen = mkFormatsOption {
default = ":443";
type = str;
description = ''
The server's listen address.
When the IP address is omitted, the server will listen on all interfaces, both IPv4 and IPv6.
To listen on IPv4 only, you can use `0.0.0.0:443`.
To listen on IPv6 only, you can use `[::]:443`.
'';
};
tls = mkFormatsOption {
description = ''
Certificates are read on every TLS handshake.
This means you can update the files without restarting the server.
'';
type = submodule {
options = {
cert = mkFormatsOption {
example = "./some.crt";
description = "TLS certificate";
type = path;
};
key = mkFormatsOption {
example = "./some.key";
description = "TLS private key";
type = path;
};
sniGuard = mkFormatsOption {
example = "strict";
type = enum [
"strict"
"disable"
"dns-san"
];
description = ''
Verify the SNI provided by the client.
Accept the connection only when it matches what's in the certificate.
Terminate the TLS handshake otherwise.
Set to `strict` to enforce this behavior.
Set to `disable` to disable this entirely.
The default is `dns-san`, which enables this feature
only when the certificate contains the "Subject Alternative Name"
extension with a domain name in it.
'';
};
};
};
};
sniff = mkFormatsOption {
description = ''
Certificates are read on every TLS handshake.
This means you can update the files without restarting the server.
'';
type = submodule {
options = {
enable = mkFormatsOption {
description = "Whether to enable protocol sniffing.";
default = false;
example = true;
type = bool;
};
timeout = mkFormatsOption {
description = ''
Sniffing timeout. If the protocol/domain cannot be determined within this time,
the original address will be used to initiate the connection.
'';
example = "2s";
type = str;
};
rewriteDomain = mkFormatsOption {
description = ''
Whether to rewrite requests that are already in domain name form.
If enabled, requests with the target address already in domain name form will still be sniffed.
'';
default = false;
example = true;
type = bool;
};
tcpPorts = mkFormatsOption {
description = ''
List of TCP ports. Only TCP requests on these ports will be sniffed.
'';
type = str;
example = "80,443,8000-9000";
};
udpPorts = mkFormatsOption {
description = ''
List of UDP ports. Only UDP requests on these ports will be sniffed.
'';
type = str;
example = "all";
};
};
};
};
acme = mkFormatsOption {
description = "ACME configuration.";
type = submodule {
options = {
domains = mkFormatsOption {
example = [
"domain1.com"
"domain2.org"
];
default = lib.attrNames config.security.acme.certs;
description = "Your domains";
type = listOf str;
};
email = mkFormatsOption {
example = "[email protected]";
default = config.security.acme.defaults.email;
description = "Your email address";
type = str;
};
ca = mkFormatsOption {
default = "letsencrypt";
example = "zerossl";
description = ''
The CA to use.
'';
type = enum [
"letsencrypt"
"zerossl"
];
};
http.altPort = mkFormatsOption {
example = 8888;
description = ''
Listening port for HTTP challenges.
> **NOTE**: Changing to a port other than 80 requires port forwarding or HTTP reverse proxy, or the challenge will fail!
'';
type = int;
};
tls.altPort = mkFormatsOption {
example = 44333;
description = ''
Listening port for TLS-ALPN challenges.
> **NOTE**: Changing to a port other than 443 requires port forwarding or TLS reverse proxy, or the challenge will fail!
'';
type = int;
};
dir = mkFormatsOption {
default = "acme";
description = "Directory to store ACME credentials.";
type = str;
};
listenHost = mkFormatsOption {
default = "0.0.0.0";
example = "192.168.5.150";
description = ''
Listening address for ACME verification (no port).
Defaults to listening on all available interfaces.
'';
type = str;
};
type = mkFormatsOption {
description = "ACME challenge type.";
example = "http";
type = enum [
"http"
"tls"
"dns"
];
};
dns = mkFormatsOption {
description = ''
ACME DNS can obtain certificates through the DNS service provider API. T
his function does not rely on specific ports (does not occupy 80/443) and external access.
'';
type = submodule {
options = {
name = mkFormatsOption {
description = "Name of the DNS provider.";
example = "cloudflare";
type = enum [
"cloudflare"
"duckdns"
"gandi"
"godaddy"
"namedotcom"
"vultr"
];
};
config = mkFormatsOption {
description = ''
ACME DNS provider configuration. [ACME DNS Config documentation](https://v2.hysteria.network/docs/advanced/ACME-DNS-Config/)
'';
example.cloudflare_api_token = "Dxabckw9dB_jYBdi89kgyaS8wRjqqSsd679urScKOBP";
type = attrsOf str;
};
};
};
};
};
};
};
bandwidth = mkFormatsOption {
description = ''
The bandwidth values on the server side act as speed limits, limiting the maximum rate at which the server will send and receive data (per client).
> **NOTE**: that the server's upload speed is the client's download speed, and vice versa.
You can omit these values or set them to zero on either or both sides, which would mean no limit.
Supported units are:
+ bps or b (bits per second)
+ kbps or kb or k (kilobits per second)
+ mbps or mb or m (megabits per second)
+ gbps or gb or g (gigabits per second)
+ tbps or tb or t (terabits per second)
'';
type = submodule {
options = {
up = mkFormatsOption {
description = "The server's upload bandwidth.";
default = "1 gbps";
example = "0";
type = str;
};
down = mkFormatsOption {
description = "The server's download bandwidth.";
default = "1 gbps";
example = "0";
type = str;
};
};
};
};
ignoreClientBandwidth = mkFormatsOption {
description = ''
`ignoreClientBandwidth` is a special option that, when enabled, makes the server to disregard any bandwidth hints set by clients,
opting to use a more traditional congestion control algorithm (currently BBR) instead.
This effectively overrides any bandwidth values set by clients in both directions.
This feature is primarily useful for server owners who prefer congestion fairness over other network traffic,
or who do not trust users to accurately set their own bandwidth values.
[Bandwidth negotiation process](https://v2.hysteria.network/docs/advanced/Full-Server-Config/#bandwidth-negotiation-process)
'';
default = false;
example = true;
type = bool;
};
speedTest = mkFormatsOption {
description = ''
`speedTest` enables the built-in speed test server.
When enabled, clients can test their download and upload speeds with the server.
For more information, see the [Speed Test documentation](https://v2.hysteria.network/docs/advanced/Speed-Test/).
'';
default = false;
example = true;
type = bool;
};
disableUDP = mkFormatsOption {
description = ''
`disableUDP` disables UDP forwarding, only allowing TCP connections.
'';
example = true;
default = false;
type = bool;
};
udpIdleTimeout = mkFormatsOption {
description = ''
`udpIdleTimeout` specifies the amount of time the server will keep a local UDP port open for each UDP session that has no activity.
This is conceptually similar to the NAT UDP session timeout.
'';
default = "60s";
example = "120s";
type = str;
};
auth = mkFormatsOption {
description = ''
Authentication payload:
```json
{
"addr": "123.123.123.123:44556",
"auth": "something_something",
"tx": 123456
}
```
'';
type = submodule {
options = {
type = mkFormatsOption {
description = "Authentication type.";
default = "password";
example = "userpass";
type = enum [
"password"
"userpass"
"http"
"command"
];
};
password = mkFormatsOption {
description = "Replace with a strong password of your choice.";
example = "your_password";
type = str;
};
userpass = mkFormatsOption {
description = "A map of username-password pairs.";
example = {
user1 = "pass1";
user2 = "pass2";
user3 = "pass3";
};
type = attrsOf str;
};
http = mkFormatsOption {
description = ''
When using HTTP authentication, the server will send a `POST` request to the backend server with the authentication payload when a client attempts to connect.
Your endpoint must respond with a JSON object with the following fields:
```json
{
"ok": true,
"id": "john_doe"
}
```
> **NOTE**: The HTTP status code must be 200 for the authentication to be considered successful.
'';
type = submodule {
options = {
url = mkFormatsOption {
description = ''
The URL of the backend server that handles authentication.
'';
example = "http://your.backend.com/auth";
type = str;
};
insecure = mkFormatsOption {
description = ''
Disable TLS verification for the backend server (only applies to HTTPS URLs).
'';
example = true;
default = false;
type = bool;
};
};
};
};
command = mkFormatsOption {
description = ''
The path to the command that handles authentication.
When using command authentication,
the server will execute the specified command with the following arguments from the authentication payload when a client attempts to connect:
```
/etc/some_command addr auth tx
```
The command must print the client's unique identifier to `stdout` and return with exit code 0 if the client is allowed to connect,
or return with a non-zero exit code if the client is rejected.
If the command fails to execute, the client will be rejected.
'';
example = "/etc/some_command";
type = str;
};
};
};
};
resolver = mkFormatsOption {
description = ''
You can specify what **resolver** (DNS server) to use to resolve domain names in client requests.
If omitted, Hysteria will use the system's default **resolver**.
'';
type = submodule {
options =
let
timeoutDescription = "The timeout for DNS queries.";
sniDescription = "The SNI to use for the TLS resolver.";
insecureDescription = "Disable TLS verification for the TLS resolver.";
in
{
type = mkFormatsOption {
description = "Resolver type";
example = "tls";
type = enum [
"tcp"
"udp"
"tls"
"https"
];
};
tcp = {
addr = mkFormatsOption {
description = "The address of the TCP resolver.";
default = "8.8.8.8:53";
type = str;
};
timeout = mkFormatsOption {
description = timeoutDescription;
default = "4s";
example = "8s";
type = str;
};
};
udp = {
addr = mkFormatsOption {
description = "The address of the UDP resolver.";
default = "8.8.4.4:53";
type = str;
};
timeout = mkFormatsOption {
description = timeoutDescription;
default = "4s";
example = "8s";
type = str;
};
};
tls = {
addr = mkFormatsOption {
description = "The address of the TLS resolver.";
default = "1.1.1.1:853";
type = str;
};
timeout = mkFormatsOption {
description = timeoutDescription;
default = "10s";
type = str;
};
sni = mkFormatsOption {
default = "cloudflare-dns.com";
description = sniDescription;
type = str;
};
insecure = mkFormatsOption {
description = insecureDescription;
default = false;
example = true;
type = bool;
};
};
https = {
addr = mkFormatsOption {
description = "The address of the HTTPS resolver.";
default = "1.1.1.1:443";
type = str;
};
timeout = mkFormatsOption {
description = timeoutDescription;
default = "10s";
example = "5s";
type = str;
};
sni = mkFormatsOption {
description = sniDescription;
default = "cloudflare-dns.com";
type = str;
};
insecure = mkFormatsOption {
description = insecureDescription;
default = false;
example = true;
type = bool;
};
};
};
};
};
acl = mkFormatsOption {
description = ''
ACL, often used in combination with outbounds, is a very powerful feature of the Hysteria server that allows you to customize the way client's requests are handled.
For example, you can use ACL to block certain addresses, or to use different outbounds for different websites.
For details on syntax, usage and other information, please refer to the [ACL documentation](https://v2.hysteria.network/docs/advanced/ACL/).
You can have either `file` or `inline`, but not both.
> **NOTE**: Hysteria currently uses the protobuf-based "dat" format for geoip/geosite data originating from v2ray.
> If you don't need any customization, you can omit the `geoip` or `geosite` fields and let Hysteria automatically download the latest version [Loyalsoldier/v2ray-rules-dat](https://github.com/Loyalsoldier/v2ray-rules-dat) to your working directory.
> The files will only be downloaded and used if your ACL has at least one rule that uses this feature.
'';
type = submodule {
options = {
file = mkFormatsOption {
description = "The path to the ACL file.";
example = "./some.txt";
type = path;
};
inline = mkFormatsOption {
description = "The list of inline ACL rules. [ACL documentation](https://v2.hysteria.network/docs/advanced/ACL/)]";
example = [
"reject(suffix:v2ex.com)"
"reject(all, udp/443)"
"reject(geoip:cn)"
"reject(geosite:netflix)"
];
type = listOf str;
};
geoip = mkFormatsOption {
description = ''
Optional. The path to the GeoIP database file.
If this field is omitted, Hysteria will automatically download the latest database to your working directory.
'';
example = "./geoip.dat";
type = path;
};
geosite = mkFormatsOption {
description = ''
Optional. The path to the GeoSite database file.
If this field is omitted, Hysteria will automatically download the latest database to your working directory.
'';
example = "./geosite.dat";
type = path;
};
geoUpdateInterval = mkFormatsOption {
description = ''
Optional. The interval at which to refresh the GeoIP/GeoSite databases.
168 hours (1 week) by default. Only applies if the GeoIP/GeoSite databases are automatically downloaded.
> Hysteria currently only downloads the GeoIP/GeoSite databases once at startup.
> You will need to use external tools to periodically restart the Hysteria server in order to update the databases regularly through geoUpdateInterval.
> This may change in future versions.
'';
default = "168h";
example = "100h";
type = str;
};
};
};
};
outbounds = mkFormatsOption {
description = ''
Outbounds are used to define the "exit" through which a connection should be routed.
For example, when [combined with ACL](https://v2.hysteria.network/docs/advanced/ACL/),
you can route all traffic except Netflix directly through the local interface, while routing Netflix traffic through a SOCKS5 proxy.
Currently, Hysteria supports the following outbound types:
+ direct: Direct connection through the local interface.
+ socks5: SOCKS5 proxy.
+ http: HTTP/HTTPS proxy.
> **NOTE**: HTTP/HTTPS proxies do not support UDP at the protocol level. Sending UDP traffic to HTTP outbounds will result in rejection.
**If you do not use ACL, all connections will always be routed through the first ("default") outbound in the list, and all other outbounds will be ignored.**
'';
example = [
{
name = "my_outbound_1";
type = "direct";
}
{
name = "my_outbound_2";
type = "socks5";
socks5 = {
addr = "shady.proxy.ru:1080";
username = "hackerman";
password = "Elliot Alderson";
};
}
{
name = "my_outbound_3";
type = "http";
http = {
url = "http://username:[email protected]:8081";
insecure = false;
};
}
{
name = "hoho";
type = "direct";
direct = {
mode = "auto";
bindIPv4 = "2.4.6.8";
bindIPv6 = "0:0:0:0:0:ffff:0204:0608";
bindDevice = "eth233";
};
}
];
type = listOf (submodule {
options = {
name = mkFormatsOption {
description = "The name of the outbound. This is used in ACL rules.";
example = "my_outbound_1";
type = str;
};
type = mkFormatsOption {
description = "Type of outbound";
default = "direct";
example = "socks5";
type = enum [
"direct"
"socks5"
"http"
];
};
socks5 = {
addr = mkFormatsOption {
description = "The address of the SOCKS5 proxy.";
example = "shady.proxy.ru:1080";
type = str;
};
username = mkFormatsOption {
description = "Optional. The username for the SOCKS5 proxy, if authentication is required.";
example = "hackerman";
type = str;
};
password = mkFormatsOption {
description = "Optional. The password for the SOCKS5 proxy, if authentication is required.";
example = "Elliot Alderson";
type = str;
};
};
http = {
url = mkFormatsOption {
description = "The URL of the HTTP/HTTPS proxy. (Can be `http://` or `https://`)";
example = "http://username:[email protected]:8081";
type = str;
};
insecure = mkFormatsOption {
description = "Optional. Whether to disable TLS verification. Applies to HTTPS proxies only.";
default = false;
example = true;
type = bool;
};
};
direct = mkFormatsOption {
description = ''
The direct outbound has a few additional options that can be used to customize its behavior:
> **NOTE**: The options `bindIPv4`, `bindIPv6`, and `bindDevice` are mutually exclusive.
> You can either specify `bindIPv4` and/or `bindIPv6` without `bindDevice`, or use `bindDevice` without `bindIPv4` and `bindIPv6`.
'';
type = submodule {
options = {
mode = mkFormatsOption {
description = ''
The available mode values are:
+ `auto`: Default. Dual-stack "happy eyeballs" mode. The client will attempt to connect to the destination using both IPv4 and IPv6 addresses (if available), and use the first one that succeeds.
+ `64`: Always use IPv6 if available, otherwise use IPv4.
+ `46`: Always use IPv4 if available, otherwise use IPv6.
+ `6`: Always use IPv6. Fail if no IPv6 address is available.
+ `4`: Always use IPv4. Fail if no IPv4 address is available.
'';
default = "auto";
type = enum [
"auto"
"64"
"46"
"6"
"4"
];
};
bindIPv4 = mkFormatsOption {
example = "2.4.6.8";
description = "The local IPv4 address to bind to.
";
type = str;
};
bindIPv6 = mkFormatsOption {
example = "0:0:0:0:0:ffff:0204:0608";
description = "The local IPv6 address to bind to.
";
type = str;
};
bindDevice = mkFormatsOption {
example = "eth233";
description = "The local network interface to bind to.
";
type = str;
};
};
};
};
};
});
};
trafficStats = mkFormatsOption {
description = ''
The Traffic Stats API allows you to query the server's traffic statistics and kick clients using an HTTP API.
For endpoints and usage, please refer to the [Traffic Stats API documentation](https://v2.hysteria.network/docs/advanced/Traffic-Stats-API/).
> **NOTE**: If you don't set a secret, anyone with access to your API listening address will be able to see traffic stats and kick users.
> We strongly recommend setting a secret, or at least using ACL to block users from accessing the API.
'';
type = submodule {
options = {
listen = mkFormatsOption {
description = "The address to listen on.";
example = ":9999";
type = str;
};
secret = mkFormatsOption {
description = "The secret key to use for authentication. Attach this to the `Authorization` header in your HTTP requests.";
example = "some_secret";
type = str;
};
};
};