1 { config, lib, pkgs, ... }:
12 description = lib.mdDoc ''
13 Whether to run v2ray server.
15 Either `configFile` or `config` must be specified.
22 defaultText = literalExpression "pkgs.v2ray";
23 description = lib.mdDoc ''
24 Which v2ray package to use.
28 configFile = mkOption {
29 type = types.nullOr types.str;
31 example = "/etc/v2ray/config.json";
32 description = lib.mdDoc ''
33 The absolute path to the configuration file.
35 Either `configFile` or `config` must be specified.
37 See <https://www.v2fly.org/en_US/v5/config/overview.html>.
42 type = types.nullOr (types.attrsOf types.unspecified);
54 description = lib.mdDoc ''
55 The configuration object.
57 Either `configFile` or `config` must be specified.
59 See <https://www.v2fly.org/en_US/v5/config/overview.html>.
67 cfg = config.services.v2ray;
68 configFile = if cfg.configFile != null
70 else pkgs.writeTextFile {
72 text = builtins.toJSON cfg.config;
74 ${cfg.package}/bin/v2ray test -c $out
81 assertion = (cfg.configFile == null) != (cfg.config == null);
82 message = "Either but not both `configFile` and `config` should be specified for v2ray.";
86 environment.etc."v2ray/config.json".source = configFile;
88 systemd.packages = [ cfg.package ];
90 systemd.services.v2ray = {
91 restartTriggers = [ config.environment.etc."v2ray/config.json".source ];
93 # Workaround: https://github.com/NixOS/nixpkgs/issues/81138
94 wantedBy = [ "multi-user.target" ];