diff --git a/flake.nix b/flake.nix index c1b1bcb17..ac991cf5d 100644 --- a/flake.nix +++ b/flake.nix @@ -21,17 +21,21 @@ in { options.networking.stevenBlackHosts = { - enable = mkEnableOption "Use Steven Black's hosts file as extra hosts."; - blockFakenews = mkEnableOption "Additionally block fakenews hosts."; - blockGambling = mkEnableOption "Additionally block gambling hosts."; - blockPorn = mkEnableOption "Additionally block porn hosts."; - blockSocial = mkEnableOption "Additionally block social hosts."; + enable = mkEnableOption "Steven Black's hosts file"; + enableIPv6 = mkEnableOption "IPv6 rules" // { + default = config.networking.enableIPv6; + }; + blockFakenews = mkEnableOption "fakenews hosts entries"; + blockGambling = mkEnableOption "gambling hosts entries"; + blockPorn = mkEnableOption "porn hosts entries"; + blockSocial = mkEnableOption "social hosts entries"; }; config = mkIf cfg.enable { networking.extraHosts = - builtins.readFile ( - "${self}/" + (if alternatesList != [] then alternatesPath else "") + "hosts" - ); + let + orig = builtins.readFile ("${self}/" + (if alternatesList != [] then alternatesPath else "") + "hosts"); + ipv6 = builtins.replaceStrings [ "0.0.0.0" ] [ "::" ] orig; + in orig + (optionalString cfg.enableIPv6 ("\n" + ipv6)); }; }; diff --git a/readme_template.md b/readme_template.md index 223bae865..b9e134fce 100644 --- a/readme_template.md +++ b/readme_template.md @@ -405,6 +405,7 @@ The hosts extensions are also available with the following options: ```nix { networking.stevenBlackHosts = { + enableIPv6 = true; blockFakenews = true; blockGambling = true; blockPorn = true; @@ -413,6 +414,8 @@ The hosts extensions are also available with the following options: } ``` +IPv6 rules are enabled by default when `networking.enableIPv6` is set to `true`. + ## Updating hosts file on Windows (NOTE: See also some third-party Hosts managers, listed below.)