misc#adblocking: init

This commit is contained in:
Timothy DeHerrera 2019-12-16 02:36:51 -07:00
parent 57abccc95c
commit 1bac4a5ab6
No known key found for this signature in database
GPG key ID: 8985725DB5B0C122
2 changed files with 46 additions and 0 deletions

View file

@ -0,0 +1,45 @@
{ pkgs, ... }:
let
inherit (builtins) concatStringsSep;
inherit (pkgs) fetchFromGitHub stdenv gnugrep;
inherit (builtins) readFile fetchurl;
hosts = stdenv.mkDerivation {
name = "hosts";
src = fetchFromGitHub {
owner = "StevenBlack";
repo = "hosts";
rev = "d072586d5e34ee11beef17a58fcca2ad4e319953";
sha256 = "0yq71w7ycm35fyjxhax22cmyn3b6lakw0n1d8rkwzkraa7f6w4pp";
};
nativeBuildInputs = [ gnugrep ];
installPhase = ''
mkdir -p $out/etc
# filter whitelist
grep -Ev '(${whitelist})' hosts > $out/etc/hosts
# filter blacklist
cat << EOF >> $out/etc/hosts
${blacklist}
EOF
'';
};
whitelist = concatStringsSep "|" [
".*pirate(bay|proxy).*"
];
blacklist = concatStringsSep "\n0.0.0.0 " [
"# auto-generated: must be first"
# starts here
];
in
{
networking.extraHosts = readFile "${hosts}/etc/hosts";
}

View file

@ -2,5 +2,6 @@
{
imports = [
./stubby.nix
./adblocking.nix
];
}