1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 makeWrapper,
6
7 # --- Runtime Dependencies ---
8 bash,
9 procps,
10 iproute2,
11 dnsmasq,
12 iptables,
13 coreutils,
14 flock,
15 gawk,
16 getopt,
17 gnugrep,
18 gnused,
19 which,
20 # `nmcli` is not required for create_ap.
21 # Use NetworkManager by default because it is very likely already present
22 useNetworkManager ? true,
23 networkmanager,
24
25 # --- WiFi Hotspot Dependencies ---
26 useWifiDependencies ? true,
27 hostapd,
28 iw,
29 # You only need this if 'iw' can not recognize your adapter.
30 useWirelessTools ? true,
31 wirelesstools, # for iwconfig
32 # To fall back to haveged if entropy is low.
33 # Defaulting to false because not having it does not break things.
34 # If it is really needed, warnings will be logged to journal.
35 useHaveged ? false,
36 haveged,
37 # You only need this if you wish to show WiFi QR codes in terminal
38 useQrencode ? true,
39 qrencode,
40}:
41
42stdenv.mkDerivation rec {
43 pname = "linux-router";
44 version = "0.7.6";
45
46 src = fetchFromGitHub {
47 owner = "garywill";
48 repo = "linux-router";
49 tag = version;
50 hash = "sha256-iiIDWDPz8MBwsBcJAWVNeuGwaNJ7xh7gFfRqXTG4oGQ=";
51 };
52
53 nativeBuildInputs = [
54 makeWrapper
55 ];
56
57 dontBuild = true;
58
59 installPhase =
60 let
61 binPath = lib.makeBinPath (
62 [
63 procps
64 iproute2
65 getopt
66 bash
67 dnsmasq
68 iptables
69 coreutils
70 which
71 flock
72 gnugrep
73 gnused
74 gawk
75 ]
76 ++ lib.optional useNetworkManager networkmanager
77 ++ lib.optional useWifiDependencies hostapd
78 ++ lib.optional useWifiDependencies iw
79 ++ lib.optional (useWifiDependencies && useWirelessTools) wirelesstools
80 ++ lib.optional (useWifiDependencies && useHaveged) haveged
81 ++ lib.optional (useWifiDependencies && useQrencode) qrencode
82 );
83 in
84 ''
85 mkdir -p $out/bin/ $out/.bin-wrapped
86 mv lnxrouter $out/.bin-wrapped/lnxrouter
87 makeWrapper $out/.bin-wrapped/lnxrouter $out/bin/lnxrouter --prefix PATH : ${binPath}
88 '';
89
90 meta = {
91 homepage = "https://github.com/garywill/linux-router";
92 description = "Set Linux as router / Wifi hotspot / proxy in one command";
93 longDescription = ''
94 Features:
95
96 - Create a NATed sub-network
97 - Provide Internet
98 - DHCP server and RA
99 - DNS server
100 - IPv6 (behind NATed LAN, like IPv4)
101 - Creating Wifi hotspot:
102 - Channel selecting
103 - Choose encryptions: WPA2/WPA, WPA2, WPA, No encryption
104 - Create AP on the same interface you are getting Internet (require same channel)
105 - Transparent proxy (redsocks)
106 - DNS proxy
107 - Compatible with NetworkManager (automatically set interface as unmanaged)
108 '';
109 changelog = "https://github.com/garywill/linux-router/releases/tag/${version}";
110 license = lib.licenses.lgpl21Only;
111 maintainers = with lib.maintainers; [ x3ro ];
112 platforms = lib.platforms.linux;
113 mainProgram = "lnxrouter";
114 };
115}