1 { config, lib, pkgs, ... }:
13 Whether to run xray server.
15 Either `settingsFile` or `settings` must be specified.
19 package = mkPackageOption pkgs "xray" { };
21 settingsFile = mkOption {
22 type = types.nullOr types.path;
24 example = "/etc/xray/config.json";
26 The absolute path to the configuration file.
28 Either `settingsFile` or `settings` must be specified.
30 See <https://www.v2fly.org/en_US/config/overview.html>.
35 type = types.nullOr (types.attrsOf types.unspecified);
48 The configuration object.
50 Either `settingsFile` or `settings` must be specified.
52 See <https://www.v2fly.org/en_US/config/overview.html>.
60 cfg = config.services.xray;
61 settingsFile = if cfg.settingsFile != null
63 else pkgs.writeTextFile {
65 text = builtins.toJSON cfg.settings;
67 ${cfg.package}/bin/xray -test -config $out
74 assertion = (cfg.settingsFile == null) != (cfg.settings == null);
75 message = "Either but not both `settingsFile` and `settings` should be specified for xray.";
79 systemd.services.xray = {
80 description = "xray Daemon";
81 after = [ "network.target" ];
82 wantedBy = [ "multi-user.target" ];
85 ExecStart = "${cfg.package}/bin/xray -config ${settingsFile}";
86 CapabilityBoundingSet = "CAP_NET_ADMIN CAP_NET_BIND_SERVICE";
87 AmbientCapabilities = "CAP_NET_ADMIN CAP_NET_BIND_SERVICE";
88 NoNewPrivileges = true;