From 07a9b7b1d83f1cde5544063351d6886a2ca9607c Mon Sep 17 00:00:00 2001 From: oxalica Date: Wed, 21 Sep 2022 14:39:00 +0800 Subject: [PATCH] nixos/{test/,}v2ray: fix for new CLI and use upstream systemd units --- nixos/modules/services/networking/v2ray.nix | 18 ++++++++++-------- nixos/tests/v2ray.nix | 12 ++++++++++-- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/nixos/modules/services/networking/v2ray.nix b/nixos/modules/services/networking/v2ray.nix index 1ff1feed8f47..ba2aa5bc1de7 100644 --- a/nixos/modules/services/networking/v2ray.nix +++ b/nixos/modules/services/networking/v2ray.nix @@ -34,7 +34,7 @@ with lib; Either `configFile` or `config` must be specified. - See . + See . ''; }; @@ -56,7 +56,7 @@ with lib; Either `configFile` or `config` must be specified. - See . + See . ''; }; }; @@ -71,7 +71,7 @@ with lib; name = "v2ray.json"; text = builtins.toJSON cfg.config; checkPhase = '' - ${cfg.package}/bin/v2ray -test -config $out + ${cfg.package}/bin/v2ray test -c $out ''; }; @@ -83,13 +83,15 @@ with lib; } ]; + environment.etc."v2ray/config.json".source = configFile; + + systemd.packages = [ cfg.package ]; + systemd.services.v2ray = { - description = "v2ray Daemon"; - after = [ "network.target" ]; + restartTriggers = [ config.environment.etc."v2ray/config.json".source ]; + + # Workaround: https://github.com/NixOS/nixpkgs/issues/81138 wantedBy = [ "multi-user.target" ]; - serviceConfig = { - ExecStart = "${cfg.package}/bin/v2ray -config ${configFile}"; - }; }; }; } diff --git a/nixos/tests/v2ray.nix b/nixos/tests/v2ray.nix index fb36ea8557d5..9eee962c64e4 100644 --- a/nixos/tests/v2ray.nix +++ b/nixos/tests/v2ray.nix @@ -20,7 +20,7 @@ import ./make-test-python.nix ({ lib, pkgs, ... }: let port = 1081; listen = "127.0.0.1"; protocol = "vmess"; - settings.clients = [v2rayUser]; + settings.clients = [ v2rayUser ]; } ]; outbounds = [ @@ -30,7 +30,7 @@ import ./make-test-python.nix ({ lib, pkgs, ... }: let settings.vnext = [{ address = "127.0.0.1"; port = 1081; - users = [v2rayUser]; + users = [ v2rayUser ]; }]; } { @@ -49,6 +49,14 @@ import ./make-test-python.nix ({ lib, pkgs, ... }: let inboundTag = "vmess_in"; outboundTag = "direct"; } + + # Assert assets "geoip" and "geosite" are accessible. + { + type = "field"; + ip = [ "geoip:private" ]; + domain = [ "geosite:category-ads" ]; + outboundTag = "direct"; + } ]; };