1{
2 config,
3 pkgs,
4 lib,
5 ...
6}:
7
8with lib;
9
10let
11 cfg = config.services.v2raya;
12in
13
14{
15 options = {
16 services.v2raya = {
17 enable = options.mkEnableOption "the v2rayA service";
18
19 package = options.mkPackageOption pkgs "v2raya" { };
20 cliPackage = options.mkPackageOption pkgs "v2ray" {
21 example = "pkgs.xray";
22 extraDescription = "This is the package used for overriding the value of the `v2ray` attribute in the package set by `services.v2raya.package`.";
23 };
24 };
25 };
26
27 config = mkIf config.services.v2raya.enable {
28 environment.systemPackages = [ (cfg.package.override { v2ray = cfg.cliPackage; }) ];
29
30 systemd.services.v2raya =
31 let
32 nftablesEnabled = config.networking.nftables.enable;
33 iptablesServices = [
34 "iptables.service"
35 ] ++ optional config.networking.enableIPv6 "ip6tables.service";
36 tableServices = if nftablesEnabled then [ "nftables.service" ] else iptablesServices;
37 in
38 {
39 unitConfig = {
40 Description = "v2rayA service";
41 Documentation = "https://github.com/v2rayA/v2rayA/wiki";
42 After = [
43 "network.target"
44 "nss-lookup.target"
45 ] ++ tableServices;
46 Wants = [ "network.target" ];
47 };
48
49 serviceConfig = {
50 User = "root";
51 ExecStart = "${getExe (cfg.package.override { v2ray = cfg.cliPackage; })} --log-disable-timestamp";
52 Environment = [ "V2RAYA_LOG_FILE=/var/log/v2raya/v2raya.log" ];
53 LimitNPROC = 500;
54 LimitNOFILE = 1000000;
55 Restart = "on-failure";
56 Type = "simple";
57 };
58
59 wantedBy = [ "multi-user.target" ];
60 path =
61 with pkgs;
62 [
63 iptables
64 bash
65 iproute2
66 ]
67 ++ lib.optionals nftablesEnabled [ nftables ]; # required by v2rayA TProxy functionality
68 };
69 };
70
71 meta.maintainers = with maintainers; [ elliot ];
72}