/host-sink

Primary LanguageHaskellGNU Affero General Public License v3.0AGPL-3.0

Host Sink!

Just a small program to generate a list of hosts to be mapped onto localhost. The program generates both a compatible /etc/hosts file as well as an unbound local-data.conf which it outputs into the directory where it was run. It relies on external sources with slightly different formatting and coalesces them inte one list without duplicates.

Config

The program defaults to the following sources:

Which are compiled in. You can also append or replace the sources list using an ini file at ~/.config/host-sink/ini.

[sources]
replace = https://one.com/hosts, https://two.com/hosts
append = https://three.com/hosts

[http-proxy]
host = https://www-gw.example.com
port = 8080

This config results in proyxing through www-gw.example.com:8080 with {one,two,three}.com/hosts as sources.

Usage

If you're using NixOS:

  1. Run host-sink -s -u in the same folder as your configuration.nix

  2. Just put one or both of the following directives into your configuration.nix:

    
       networking.extraHosts = builtins.readFile ./hosts
       services.unbound.extraConfig = builtins.readFile ./local-data.conf
    
    

Notes

This can be trivially done with awk+sort within NixOS using (builtins.fetchurl) but this was slightly more entertaining.