devos/profiles/network/adblocking.nix

45 lines
933 B
Nix
Raw Normal View History

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