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-07-15 01:31:09 +02:00
rev = "ca3a99a0499add858969ce8747049e681b85a2e2";
hash = "sha256-DMIal28cTr/8oij89LwSvNp7n1QiwzNmwsiSzV9X49c=";
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"; }