aboutsummaryrefslogtreecommitdiff
path: root/pkgs/bindtointerface.nix
blob: 6b268257b052d165717fa935cdd4fc7501f7447f (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
{
  pkgs,
  lib,
  stdenv,
  gcc,
}:
stdenv.mkDerivation {
  pname = "bindtointerface";
  version = "1.0";
  nativeBuildInputs = [ gcc ];

  src = pkgs.fetchFromGitHub {
    owner = "JsBergbau";
    repo = "BindToInterface";
    rev = "d477326d85f64fdd1dc46382fe698e46f4843100";
    hash = "sha256-B29nXjy8RyFEOsYtko8l9i38sDauX2eW+pLsQssNTmQ=";
  };

  buildPhase = ''
    gcc \
      -nostartfiles \
      -fpic \
      -shared $src/bindToInterface.c \
      -o bindToInterface.so \
      -ldl \
      -D_GNU_SOURCE
  '';

  installPhase = ''
    mkdir -p $out/bin $out/lib
    cp bindToInterface.so $out/lib

    cat <<EOF > $out/bin/vpn
    #!/usr/bin/env bash

    env LD_PRELOAD=$out/lib/bindToInterface.so "\$@"
    EOF
    chmod +x $out/bin/vpn
  '';

  meta = with lib; {
    description = "With this program you can bind applications to a specific network interface / network adapter.";
    homepage = "https://github.com/JsBergbau/BindToInterface";
    license = licenses.gpl2;
    maintainers = [ maintainers.Fuwn ];
    platforms = platforms.linux;
  };
}