git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #58036 from volth/captive-browser

nixos/programs.captive-browser: init

commitd1990cff8d87c00230752b355e805c3007864ae1 authorMaximilian Bosch <maximilian@mbosch.me> dateThu 13 Jun 2019, 14:05 (7 years ago) parent3674ff00dfcbeb
4 files changed+133
nixos/modules/module-list.nix+1 nixos/modules/programs/captive-browser.nix+108 pkgs/applications/networking/browsers/captive-browser/default.nix+22 pkgs/top-level/all-packages.nix+2
nixos/modules/module-list.nix+1
@@ -91,6 +91,7 @@
9191 ./programs/bcc.nix
9292 ./programs/blcr.nix
9393 ./programs/browserpass.nix
94+ ./programs/captive-browser.nix
9495 ./programs/ccache.nix
9596 ./programs/cdemu.nix
9697 ./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+22
@@ -0,0 +1,22 @@
1+{ lib, fetchFromGitHub, buildGoPackage }:
2+
3+buildGoPackage rec {
4+ name = "captive-browser";
5+ version = "2019-04-16";
6+ goPackagePath = name;
7+
8+ src = fetchFromGitHub {
9+ owner = "FiloSottile";
10+ repo = "captive-browser";
11+ rev = "08450562e58bf9564ee98ad64ef7b2800e53338f";
12+ sha256 = "17icgjg7h0xm8g4yy38qjhsvlz9pmlmj9kydz01y2nyl0v02i648";
13+ };
14+
15+ meta = with lib; {
16+ description = "Dedicated Chrome instance to log into captive portals without messing with DNS settings";
17+ homepage = https://blog.filippo.io/captive-browser;
18+ license = licenses.mit;
19+ platforms = platforms.linux;
20+ maintainers = with maintainers; [ volth ];
21+ };
22+}
pkgs/top-level/all-packages.nix+2
@@ -10005,6 +10005,8 @@ in
1000510005
1000610006 capnproto = callPackage ../development/libraries/capnproto { };
1000710007
10008+ captive-browser = callPackage ../applications/networking/browsers/captive-browser { };
10009+
1000810010 ndn-cxx = callPackage ../development/libraries/ndn-cxx { };
1000910011
1001010012 cddlib = callPackage ../development/libraries/cddlib {};