Skip to content

Commit

Permalink
amneziaVPN: init at 4.8.2.3; nixos/programs/amneziaVPN: init
Browse files Browse the repository at this point in the history
  • Loading branch information
sund3RRR committed Dec 26, 2024
1 parent cf56aed commit 3dd57b4
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 0 deletions.
1 change: 1 addition & 0 deletions nixos/modules/module-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
./programs/_1password.nix
./programs/adb.nix
./programs/alvr.nix
./programs/amnezia-vpn.nix
./programs/appgate-sdp.nix
./programs/appimage.nix
./programs/arp-scan.nix
Expand Down
38 changes: 38 additions & 0 deletions nixos/modules/programs/amnezia-vpn.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
config,
lib,
pkgs,
...
}:
let
cfg = config.programs.amnezia-vpn;
in
{
options.programs.amnezia-vpn = {
enable = lib.mkEnableOption "The AmneziaVPN client";
};

config = lib.mkIf cfg.enable {
environment.systemPackages = [ pkgs.amnezia-vpn ];

services.dbus.packages = [ pkgs.amnezia-vpn ];
services.resolved.enable = true;

systemd = {
services.amnezia-vpn = {
description = "AmneziaVPN Service";
after = [ "network.target" ];
startLimitIntervalSec = 0;
serviceConfig = {
Type = "simple";
Restart = "always";
RestartSec = 1;
ExecStart = "${pkgs.amnezia-vpn}/bin/AmneziaVPN-service";
};
wantedBy = [ "multi-user.target" ];
};
};
};

meta.maintainers = with lib.maintainers; [ sund3RRR ];
}
132 changes: 132 additions & 0 deletions pkgs/by-name/am/amnezia-vpn/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
{
lib,
stdenv,
fetchFromGitHub,
cmake,
pkg-config,
kdePackages,
qt6,
libsecret,
xdg-utils,
amneziawg-go,
tun2socks,
xray,
openvpn,
shadowsocks-rust,
cloak-pt,
wireguard-tools,
writeScriptBin,
}:
let
update-resolvconf =
src:
writeScriptBin "update-resolv-conf.sh" (
builtins.readFile "${src}/deploy/data/linux/client/bin/update-resolv-conf.sh"
);
in
stdenv.mkDerivation (finalAttrs: {
pname = "amnezia-vpn";
version = "4.8.2.3";

src = fetchFromGitHub {
owner = "amnezia-vpn";
repo = "amnezia-client";
rev = "refs/tags/${finalAttrs.version}";
hash = "sha256-bCWPyRW2xnnopcwfPHgQrdP85Ct0CDufJRQ1PvCAiDE=";
fetchSubmodules = true;
};

postPatch = ''
# fix amneziaWG protocol
substituteInPlace client/platforms/linux/daemon/wireguardutilslinux.cpp \
--replace-fail 'm_tunnel.start(appPath.filePath("../../client/bin/wireguard-go"), wgArgs);' 'm_tunnel.start("${amneziawg-go}/bin/amneziawg-go", wgArgs);'
# fix service dns flush
substituteInPlace service/server/router_linux.cpp \
--replace-fail '|| QFileInfo::exists("/usr/lib/systemd/system/nscd.service"))' '|| QFileInfo::exists("/run/systemd/propagate/nscd.service"))'
# fix openvpn and xray protocol executables
substituteInPlace client/utilities.cpp \
--replace-fail 'return Utils::executable("../../client/bin/openvpn", true);' 'return Utils::executable("${openvpn}/bin/openvpn", false);' \
--replace-fail 'return Utils::executable("../../client/bin/tun2socks", true);' 'return Utils::executable("${tun2socks}/bin/tun2socks", false);' \
# fix pkill command and SIGSEGV due to missing return value
--replace-fail 'QProcess::execute(QString("pkill %1").arg(name));' 'QProcess::execute(QString("pkill -f %1").arg(name)); return true;'
# fix openvpn over cloak protocol
substituteInPlace client/protocols/openvpnovercloakprotocol.cpp \
--replace-fail 'return Utils::executable(QString("/ck-client"), true);' 'return Utils::executable(QString("${cloak-pt}/bin/ck-client"), false);'
# fix openvpn over ss protocol
substituteInPlace client/protocols/shadowsocksvpnprotocol.cpp \
--replace-fail 'return Utils::executable(QString("/ss-local"), true);' 'return Utils::executable(QString("${shadowsocks-rust}/bin/ss-local"), false);'
# fix update-resolv-conf.sh path
substituteInPlace client/configurators/openvpn_configurator.cpp \
--replace-fail '.arg(qApp->applicationDirPath());' '.arg("${(update-resolvconf finalAttrs.src)}/bin");'
# fix icon path
substituteInPlace client/ui/qautostart.cpp \
--replace-fail "/usr/share/pixmaps/AmneziaVPN.png" "$out/share/pixmaps/AmneziaVPN.png"
# fix desktop item
substituteInPlace deploy/installer/config/AmneziaVPN.desktop.in \
--replace-fail "#!/usr/bin/env xdg-open" "#!${xdg-utils}/bin/xdg-open" \
--replace-fail "/usr/share/pixmaps/AmneziaVPN.png" "$out/share/pixmaps/AmneziaVPN.png"
'';

strictDeps = true;

nativeBuildInputs = [
cmake
pkg-config
qt6.wrapQtAppsHook
];

buildInputs = [
libsecret
qt6.qtbase
qt6.qttools
kdePackages.qtremoteobjects
kdePackages.qtsvg
kdePackages.qt5compat
];

qtWrapperArgs = [
''--prefix PATH : ${
lib.makeBinPath [
amneziawg-go
tun2socks
xray
shadowsocks-rust
openvpn
cloak-pt
wireguard-tools
]
}''
];

postInstall = ''
# install AmneziaVPN and AmneziaVPN-service
mkdir -p $out/bin
cp client/AmneziaVPN $out/bin/
cp service/server/AmneziaVPN-service $out/bin/
# install .desktop item
mkdir -p $out/share/applications
cp ../AppDir/AmneziaVPN.desktop $out/share/applications/
# install icon
mkdir -p $out/share/pixmaps/
cp ../deploy/data/linux/AmneziaVPN.png $out/share/pixmaps/
'';

meta = with lib; {
description = "Amnezia VPN Client";
downloadPage = "https://amnezia.org/en/downloads";
homepage = "https://amnezia.org/en";
license = licenses.gpl3;
mainProgram = "AmneziaVPN";
maintainers = with maintainers; [ sund3RRR ];
platforms = platforms.unix;
};
})

0 comments on commit 3dd57b4

Please sign in to comment.