os/profiles/network/adblocking/default.nix
Timothy DeHerrera c67b846929
profiles: add concept of suites
* Import attrs of profiles automatically with `defaultImport`.
* Refactor profiles to ensure all are functions returning a module.
* Add a suites.nix with collections of profiles.
* Add suites as `specialArgs` to modules.
* Add suite import to NixOS host.
2021-02-03 13:16:14 -07:00

45 lines
933 B
Nix

{ 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 = "a204d5a1e9049dd12378fa5f9c5ab3fc6bf3d63e";
hash = "sha256-8WVEvpxxvxmOpP1XVgO2GFAbEHO1QileWZ3behpgYEs=";
};
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
'';
};
whitelist = concatStringsSep "|" [ ".*pirate(bay|proxy).*" ];
blacklist = concatStringsSep ''
0.0.0.0 ''
[
"# auto-generated: must be first"
# starts here
];
in
{ networking.extraHosts = readFile "${hosts}/etc/hosts"; }