Skip to content

Commit

Permalink
Merge pull request #2803 from Pandapip1/ipv6-flake
Browse files Browse the repository at this point in the history
Automtaically add ipv6 entries to nix flake
  • Loading branch information
StevenBlack authored Jan 23, 2025
2 parents abd3994 + ec8562f commit 9f4ceb2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
20 changes: 12 additions & 8 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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));
};
};

Expand Down
3 changes: 3 additions & 0 deletions readme_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.)
Expand Down

0 comments on commit 9f4ceb2

Please sign in to comment.