From 42f462e38724e66c4e6603bd3efdf89c40031ec9 Mon Sep 17 00:00:00 2001 From: Elliot Date: Fri, 3 Feb 2023 10:21:56 +0800 Subject: [PATCH 1/2] v2raya: make code more readable --- pkgs/tools/networking/v2raya/default.nix | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/pkgs/tools/networking/v2raya/default.nix b/pkgs/tools/networking/v2raya/default.nix index 23ba50cc7cb1..45a7838b2f6e 100644 --- a/pkgs/tools/networking/v2raya/default.nix +++ b/pkgs/tools/networking/v2raya/default.nix @@ -11,12 +11,14 @@ let pname = "v2raya"; version = "2.0.0"; + src = fetchFromGitHub { owner = "v2rayA"; repo = "v2rayA"; rev = "v${version}"; sha256 = "sha256-1fWcrMd+TSrlS1H0z7XwVCQzZAa8DAFtlekEZNRMAPA="; }; + web = mkYarnPackage { inherit pname version; src = "${src}/gui"; @@ -32,21 +34,32 @@ let dontInstall = true; dontFixup = true; }; + + assetsDir = symlinkJoin { + name = "assets"; + paths = [ v2ray-geoip v2ray-domain-list-community ]; + }; + in buildGoModule { inherit pname version; + src = "${src}/service"; vendorSha256 = "sha256-Ud4pwS0lz7zSTowg3gXNllfDyj8fu33H1L20szxPcOA="; + ldflags = [ "-s" "-w" "-X github.com/v2rayA/v2rayA/conf.Version=${version}" ]; + subPackages = [ "." ]; + nativeBuildInputs = [ makeWrapper ]; preBuild = '' cp -a ${web} server/router/web ''; + postInstall = '' install -Dm 444 ${src}/install/universal/v2raya.desktop -t $out/share/applications install -Dm 444 ${src}/install/universal/v2raya.png -t $out/share/icons/hicolor/512x512/apps @@ -55,11 +68,9 @@ buildGoModule { wrapProgram $out/bin/v2rayA \ --prefix PATH ":" "${lib.makeBinPath [ v2ray ]}" \ - --prefix XDG_DATA_DIRS ":" ${symlinkJoin { - name = "assets"; - paths = [ v2ray-geoip v2ray-domain-list-community ]; - }}/share + --prefix XDG_DATA_DIRS ":" ${assetsDir}/share ''; + meta = with lib; { description = "A Linux web GUI client of Project V which supports V2Ray, Xray, SS, SSR, Trojan and Pingtunnel"; homepage = "https://github.com/v2rayA/v2rayA"; From e78f2115bf0c1c2f238bf918ed368fcf633da862 Mon Sep 17 00:00:00 2001 From: Elliot Date: Fri, 3 Feb 2023 10:22:23 +0800 Subject: [PATCH 2/2] v2raya: v2rayA should start after nftables --- nixos/modules/services/networking/v2raya.nix | 49 ++++++++++++-------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/nixos/modules/services/networking/v2raya.nix b/nixos/modules/services/networking/v2raya.nix index 2d697b4fb56f..0bea73798daf 100644 --- a/nixos/modules/services/networking/v2raya.nix +++ b/nixos/modules/services/networking/v2raya.nix @@ -12,27 +12,38 @@ with lib; config = mkIf config.services.v2raya.enable { environment.systemPackages = [ pkgs.v2raya ]; - systemd.services.v2raya = { - unitConfig = { - Description = "v2rayA service"; - Documentation = "https://github.com/v2rayA/v2rayA/wiki"; - After = [ "network.target" "nss-lookup.target" "iptables.service" "ip6tables.service" ]; - Wants = [ "network.target" ]; - }; + systemd.services.v2raya = + let + nftablesEnabled = config.networking.nftables.enable; + iptablesServices = [ + "iptables.service" + ] ++ optional config.networking.enableIPv6 "ip6tables.service"; + tableServices = if nftablesEnabled then [ "nftables.service" ] else iptablesServices; + in + { + unitConfig = { + Description = "v2rayA service"; + Documentation = "https://github.com/v2rayA/v2rayA/wiki"; + After = [ + "network.target" + "nss-lookup.target" + ] ++ tableServices; + Wants = [ "network.target" ]; + }; - serviceConfig = { - User = "root"; - ExecStart = "${getExe pkgs.v2raya} --log-disable-timestamp"; - Environment = [ "V2RAYA_LOG_FILE=/var/log/v2raya/v2raya.log" ]; - LimitNPROC = 500; - LimitNOFILE = 1000000; - Restart = "on-failure"; - Type = "simple"; - }; + serviceConfig = { + User = "root"; + ExecStart = "${getExe pkgs.v2raya} --log-disable-timestamp"; + Environment = [ "V2RAYA_LOG_FILE=/var/log/v2raya/v2raya.log" ]; + LimitNPROC = 500; + LimitNOFILE = 1000000; + Restart = "on-failure"; + Type = "simple"; + }; - wantedBy = [ "multi-user.target" ]; - path = with pkgs; [ iptables bash iproute2 ]; # required by v2rayA TProxy functionality - }; + wantedBy = [ "multi-user.target" ]; + path = with pkgs; [ iptables bash iproute2 ]; # required by v2rayA TProxy functionality + }; }; meta.maintainers = with maintainers; [ elliot ];