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";
|
2020-12-26 05:10:44 +00:00
|
|
|
rev = "a204d5a1e9049dd12378fa5f9c5ab3fc6bf3d63e";
|
|
|
|
hash = "sha256-8WVEvpxxvxmOpP1XVgO2GFAbEHO1QileWZ3behpgYEs=";
|
2019-12-16 09:36:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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-07-31 04:17:28 +00:00
|
|
|
0.0.0.0 ''
|
|
|
|
[
|
2020-01-04 05:06:31 +00:00
|
|
|
"# auto-generated: must be first"
|
2019-12-16 09:36:51 +00:00
|
|
|
|
2020-01-04 05:06:31 +00:00
|
|
|
# starts here
|
|
|
|
];
|
|
|
|
|
2020-07-31 04:17:28 +00:00
|
|
|
in
|
|
|
|
{ networking.extraHosts = readFile "${hosts}/etc/hosts"; }
|