1 { config, lib, pkgs, ... }:
13 Whether to run v2ray server.
15 Either `configFile` or `config` must be specified.
19 package = mkPackageOption pkgs "v2ray" { };
21 configFile = mkOption {
22 type = types.nullOr types.str;
24 example = "/etc/v2ray/config.json";
26 The absolute path to the configuration file.
28 Either `configFile` or `config` must be specified.
30 See <https://www.v2fly.org/en_US/v5/config/overview.html>.
35 type = types.nullOr (types.attrsOf types.unspecified);
48 The configuration object.
50 Either `configFile` or `config` must be specified.
52 See <https://www.v2fly.org/en_US/v5/config/overview.html>.
60 cfg = config.services.v2ray;
61 configFile = if cfg.configFile != null
63 else pkgs.writeTextFile {
65 text = builtins.toJSON cfg.config;
67 ${cfg.package}/bin/v2ray test -c $out
74 assertion = (cfg.configFile == null) != (cfg.config == null);
75 message = "Either but not both `configFile` and `config` should be specified for v2ray.";
79 environment.etc."v2ray/config.json".source = configFile;
81 systemd.packages = [ cfg.package ];
83 systemd.services.v2ray = {
84 restartTriggers = [ config.environment.etc."v2ray/config.json".source ];
86 # Workaround: https://github.com/NixOS/nixpkgs/issues/81138
87 wantedBy = [ "multi-user.target" ];