2019-12-16 09:36:51 +00:00
|
|
|
{ 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
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-01-04 05:06:31 +00:00
|
|
|
whitelist = concatStringsSep "|" [ ".*pirate(bay|proxy).*" ];
|
2019-12-16 09:36:51 +00:00
|
|
|
|
2020-01-04 05:06:31 +00:00
|
|
|
blacklist = concatStringsSep ''
|
2019-12-16 09:36:51 +00:00
|
|
|
|
2020-01-04 05:06:31 +00:00
|
|
|
0.0.0.0 '' [
|
|
|
|
"# auto-generated: must be first"
|
2019-12-16 09:36:51 +00:00
|
|
|
|
2020-01-04 05:06:31 +00:00
|
|
|
# starts here
|
|
|
|
];
|
|
|
|
|
|
|
|
in { networking.extraHosts = readFile "${hosts}/etc/hosts"; }
|