at master 2.0 kB view raw
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 ] 36 ++ optional config.networking.enableIPv6 "ip6tables.service"; 37 tableServices = if nftablesEnabled then [ "nftables.service" ] else iptablesServices; 38 in 39 { 40 unitConfig = { 41 Description = "v2rayA service"; 42 Documentation = "https://github.com/v2rayA/v2rayA/wiki"; 43 After = [ 44 "network.target" 45 "nss-lookup.target" 46 ] 47 ++ tableServices; 48 Wants = [ "network.target" ]; 49 }; 50 51 serviceConfig = { 52 User = "root"; 53 ExecStart = "${getExe (cfg.package.override { v2ray = cfg.cliPackage; })} --log-disable-timestamp"; 54 Environment = [ "V2RAYA_LOG_FILE=/var/log/v2raya/v2raya.log" ]; 55 LimitNPROC = 500; 56 LimitNOFILE = 1000000; 57 Restart = "on-failure"; 58 Type = "simple"; 59 }; 60 61 wantedBy = [ "multi-user.target" ]; 62 path = 63 with pkgs; 64 [ 65 iptables 66 bash 67 iproute2 68 ] 69 ++ lib.optionals nftablesEnabled [ nftables ]; # required by v2rayA TProxy functionality 70 }; 71 }; 72 73 meta.maintainers = with maintainers; [ elliot ]; 74}