pub-solar-os/profiles/misc/adblocking.nix

45 lines
933 B
Nix
Raw Normal View History

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