about summary refs log tree commit diff
path: root/nixpkgs/pkgs/tools/networking/wsl-vpnkit/default.nix
blob: 39152cbab20589fafa9d161da56315cfaf8e1556 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
{ lib
, resholve
, fetchFromGitHub

  # Runtime dependencies
, coreutils
, dnsutils
, gawk
, gnugrep
, gvproxy
, iproute2
, iptables
, iputils
, wget
}:

let
  version = "0.4.1";
  gvproxyWin = gvproxy.overrideAttrs (_: {
    buildPhase = ''
      GOARCH=amd64 GOOS=windows go build -ldflags '-s -w' -o bin/gvproxy-windows.exe ./cmd/gvproxy
    '';
  });
in
resholve.mkDerivation {
  pname = "wsl-vpnkit";
  inherit version;

  src = fetchFromGitHub {
    owner = "sakai135";
    repo = "wsl-vpnkit";
    rev = "v${version}";
    hash = "sha256-Igbr3L2W32s4uBepllSz07bkbI3qwAKMZkBrXLqGrGA=";
  };

  postPatch = ''
    substituteInPlace wsl-vpnkit \
      --replace "/app/wsl-vm" "${gvproxy}/bin/gvforwarder" \
      --replace "/app/wsl-gvproxy.exe" "${gvproxyWin}/bin/gvproxy-windows.exe"
  '';

  installPhase = ''
    mkdir -p $out/bin
    cp wsl-vpnkit $out/bin
  '';

  solutions.wsl-vpnkit = {
    scripts = [ "bin/wsl-vpnkit" ];
    interpreter = "none";
    inputs = [
      coreutils
      dnsutils
      gawk
      gnugrep
      iproute2
      iptables
      iputils
      wget
    ];

    keep = {
      "$VMEXEC_PATH" = true;
      "$GVPROXY_PATH" = true;
    };

    execer = [
      "cannot:${iproute2}/bin/ip"
      "cannot:${wget}/bin/wget"
    ];

    fix = {
      aliases = true;
      ping = "${iputils}/bin/ping";
    };
  };

  meta = with lib; {
    description = "Provides network connectivity to Windows Subsystem for Linux (WSL) when blocked by VPN";
    homepage = "https://github.com/sakai135/wsl-vpnkit";
    changelog = "https://github.com/sakai135/wsl-vpnkit/releases/tag/v${version}";
    license = licenses.mit;
    maintainers = with maintainers; [ terlar ];
  };
}