about summary refs log tree commit diff
path: root/nixpkgs/pkgs/tools/networking/linux-router/default.nix
blob: acf02a2cc211ee9b34cc52b49ce97b8ff790fe28 (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
{ lib
, stdenv
, fetchFromGitHub
, makeWrapper

# --- Runtime Dependencies ---
, bash
, procps
, iproute2
, dnsmasq
, iptables
, coreutils
, flock
, gawk
, getopt
, gnugrep
, gnused
, which
# `nmcli` is not required for create_ap.
# Use NetworkManager by default because it is very likely already present
, useNetworkManager ? true
, networkmanager

# --- WiFi Hotspot Dependencies ---
, useWifiDependencies ? true
, hostapd
, iw
# You only need this if 'iw' can not recognize your adapter.
, useWirelessTools ? true
, wirelesstools # for iwconfig
# To fall back to haveged if entropy is low.
# Defaulting to false because not having it does not break things.
# If it is really needed, warnings will be logged to journal.
, useHaveged ? false
, haveged
# You only need this if you wish to show WiFi QR codes in terminal
, useQrencode ? true
, qrencode
}:

stdenv.mkDerivation rec {
  pname = "linux-router";
  version = "0.6.7";

  src = fetchFromGitHub {
    owner = "garywill";
    repo = "linux-router";
    rev = "refs/tags/${version}";
    hash = "sha256-Ote/arHCU6qiTXdK2RXv9848aeW6rcBsrb6nfxIzQLs=";
  };

  nativeBuildInputs = [
    makeWrapper
  ];

  dontBuild = true;

  installPhase = with lib; let
      binPath = makeBinPath ([ procps iproute2 getopt bash dnsmasq
        iptables coreutils which flock gnugrep gnused gawk ]
        ++ optional useNetworkManager                          networkmanager
        ++ optional useWifiDependencies                        hostapd
        ++ optional useWifiDependencies                        iw
        ++ optional (useWifiDependencies && useWirelessTools)  wirelesstools
        ++ optional (useWifiDependencies && useHaveged)        haveged
        ++ optional (useWifiDependencies && useQrencode)       qrencode);
    in
    ''
      mkdir -p $out/bin/ $out/.bin-wrapped
      mv lnxrouter $out/.bin-wrapped/lnxrouter
      makeWrapper $out/.bin-wrapped/lnxrouter $out/bin/lnxrouter --prefix PATH : ${binPath}
    '';

  meta = with lib; {
    homepage = "https://github.com/garywill/linux-router";
    description = "Set Linux as router / Wifi hotspot / proxy in one command";
    longDescription = ''
      Features:

      - Create a NATed sub-network
      - Provide Internet
      - DHCP server and RA
      - DNS server
      - IPv6 (behind NATed LAN, like IPv4)
      - Creating Wifi hotspot:
        - Channel selecting
        - Choose encryptions: WPA2/WPA, WPA2, WPA, No encryption
        - Create AP on the same interface you are getting Internet (require same channel)
      - Transparent proxy (redsocks)
      - DNS proxy
      - Compatible with NetworkManager (automatically set interface as unmanaged)
    '';
    changelog = "https://github.com/garywill/linux-router/releases/tag/${version}";
    license = licenses.lgpl21Only;
    maintainers = with maintainers; [ x3ro ];
    platforms = platforms.linux;
  };
}