git.iko.soy/typeable/nixpkgs
on master help sign in
captive-browser: init at 2019-04-14
commit9498c8f44321f61d6698bc275abc4e1d6141b18c authorvolth <volth@volth.com> dateThu 21 Mar 2019, 12:23 (8 years ago) parentc8022b5
4 files changed+125
nixos/modules/module-list.nix+1 nixos/modules/programs/captive-browser.nix+108 pkgs/applications/networking/browsers/captive-browser/default.nix+14 pkgs/top-level/all-packages.nix+2
nixos/modules/module-list.nix+1
@@ -90,6 +90,7 @@
9090 ./programs/bcc.nix
9191 ./programs/blcr.nix
9292 ./programs/browserpass.nix
93+ ./programs/captive-browser.nix
9394 ./programs/ccache.nix
9495 ./programs/cdemu.nix
9596 ./programs/chromium.nix
nixos/modules/programs/captive-browser.nixnew file+108
@@ -0,0 +1,108 @@
1+{ config, lib, pkgs, ... }:
2+
3+with lib;
4+
5+let
6+ cfg = config.programs.captive-browser;
7+in
8+{
9+ ###### interface
10+
11+ options = {
12+ programs.captive-browser = {
13+ enable = mkEnableOption "captive browser";
14+
15+ package = mkOption {
16+ type = types.package;
17+ default = pkgs.captive-browser;
18+ };
19+
20+ interface = mkOption {
21+ type = types.str;
22+ description = "your public network interface (wlp3s0, wlan0, eth0, ...)";
23+ };
24+
25+ # the options below are the same as in "captive-browser.toml"
26+ browser = mkOption {
27+ type = types.str;
28+ default = concatStringsSep " " [ ''${pkgs.chromium}/bin/chromium''
29+ ''--user-data-dir=$HOME/.chromium-captive''
30+ ''--proxy-server="socks5://$PROXY"''
31+ ''--host-resolver-rules="MAP * ~NOTFOUND , EXCLUDE localhost"''
32+ ''--no-first-run''
33+ ''--new-window''
34+ ''--incognito''
35+ ''http://cache.nixos.org/''
36+ ];
37+ description = ''
38+ the shell (/bin/sh) command executed once the proxy starts.
39+ When browser exits, the proxy exits. An extra env var PROXY is available.
40+
41+ Here, we use a separate Chrome instance in Incognito mode, so that
42+ it can run (and be waited for) alongside the default one, and that
43+ it maintains no state across runs. To configure this browser open a
44+ normal window in it, settings will be preserved.
45+
46+ @volth: chromium is to open a plain HTTP (not HTTPS nor redirect to HTTPS!) website.
47+ upstream uses http://example.com but I have seen captive portals whose DNS server resolves "example.com" to 127.0.0.1
48+ '';
49+ };
50+
51+ dhcp-dns = mkOption {
52+ type = types.str;
53+ description = ''
54+ the shell (/bin/sh) command executed to obtain the DHCP
55+ DNS server address. The first match of an IPv4 regex is used.
56+ IPv4 only, because let's be real, it's a captive portal.
57+ '';
58+ };
59+
60+ socks5-addr = mkOption {
61+ type = types.str;
62+ default = "localhost:1666";
63+ description = ''the listen address for the SOCKS5 proxy server'';
64+ };
65+ };
66+ };
67+
68+ ###### implementation
69+
70+ config = mkIf cfg.enable {
71+
72+ programs.captive-browser.dhcp-dns = mkOptionDefault (
73+ if config.networking.networkmanager.enable then
74+ "${pkgs.networkmanager}/bin/nmcli dev show ${escapeShellArg cfg.interface} | ${pkgs.gnugrep}/bin/fgrep IP4.DNS"
75+ else if config.networking.dhcpcd.enable then
76+ "${pkgs.dhcpcd}/bin/dhcpcd -U ${escapeShellArg cfg.interface} | ${pkgs.gnugrep}/bin/fgrep domain_name_servers"
77+ else if config.networking.useNetworkd then
78+ "${cfg.package}/bin/systemd-networkd-dns ${escapeShellArg cfg.interface}"
79+ else
80+ "${config.security.wrapperDir}/udhcpc --quit --now -f -i ${escapeShellArg cfg.interface} -O dns --script ${
81+ pkgs.writeScript "udhcp-script" ''
82+ #!/bin/sh
83+ if [ "$1" = bound ]; then
84+ echo "$dns"
85+ fi
86+ ''}"
87+ );
88+
89+ security.wrappers.udhcpc = {
90+ capabilities = "cap_net_raw+p";
91+ source = "${pkgs.busybox}/bin/udhcpc";
92+ };
93+
94+ security.wrappers.captive-browser = {
95+ capabilities = "cap_net_raw+p";
96+ source = pkgs.writeScript "captive-browser" ''
97+ #!${pkgs.bash}/bin/bash
98+ export XDG_CONFIG_HOME=${pkgs.writeTextDir "captive-browser.toml" ''
99+ browser = """${cfg.browser}"""
100+ dhcp-dns = """${cfg.dhcp-dns}"""
101+ socks5-addr = """${cfg.socks5-addr}"""
102+ bind-device = """${cfg.interface}"""
103+ ''}
104+ exec ${cfg.package}/bin/captive-browser
105+ '';
106+ };
107+ };
108+}
pkgs/applications/networking/browsers/captive-browser/default.nixnew file+14
@@ -0,0 +1,14 @@
1+{ fetchFromGitHub, buildGoPackage }:
2+
3+buildGoPackage rec {
4+ name = "captive-browser";
5+ version = "2019-04-14";
6+ goPackagePath = name;
7+
8+ src = fetchFromGitHub {
9+ owner = "FiloSottile";
10+ repo = "captive-browser";
11+ rev = "b96bd8a2aca14505cf8432935ee9add15ec39a57";
12+ sha256 = "1k7r7rckb81m11hr6nzw3w8wx76hbl4740xg4818vdm5py1hv5ij";
13+ };
14+}
pkgs/top-level/all-packages.nix+2
@@ -9729,6 +9729,8 @@ in
97299729
97309730 capnproto = callPackage ../development/libraries/capnproto { };
97319731
9732+ captive-browser = callPackage ../applications/networking/browsers/captive-browser { };
9733+
97329734 ndn-cxx = callPackage ../development/libraries/ndn-cxx { };
97339735
97349736 cddlib = callPackage ../development/libraries/cddlib {};