Skip to content

Commit 9272f02

Browse files
committed
flake.nix: Filter *out* IPv6 rules
1 parent 869d4ec commit 9272f02

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

flake.nix

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,23 @@
1212
nixosModule = { config, ... }:
1313
with nixpkgs.lib;
1414
let
15+
inherit (nixpkgs) lib;
1516
cfg = config.networking.stevenBlackHosts;
1617
alternatesList = (if cfg.blockFakenews then [ "fakenews" ] else []) ++
1718
(if cfg.blockGambling then [ "gambling" ] else []) ++
1819
(if cfg.blockPorn then [ "porn" ] else []) ++
1920
(if cfg.blockSocial then [ "social" ] else []);
20-
alternatesPath = "alternates/" + builtins.concatStringsSep "-" alternatesList + "/";
21+
alternatesPath = "/alternates/" + builtins.concatStringsSep "-" alternatesList;
22+
orig = builtins.readFile (
23+
self.outPath + (if alternatesList != [ ] then alternatesPath else "") + "/hosts"
24+
);
25+
filtered =
26+
if cfg.enableIPv6 then
27+
orig
28+
else
29+
lib.concatStringsSep "\n" (
30+
lib.filter (line: !(lib.strings.hasPrefix "::" line)) (lib.strings.splitString "\n" orig)
31+
);
2132
in
2233
{
2334
options.networking.stevenBlackHosts = {
@@ -32,11 +43,7 @@
3243
blockSocial = mkEnableOption "social hosts entries";
3344
};
3445
config = mkIf cfg.enable {
35-
networking.extraHosts =
36-
let
37-
orig = builtins.readFile ("${self}/" + (if alternatesList != [] then alternatesPath else "") + "hosts");
38-
ipv6 = builtins.replaceStrings [ "0.0.0.0" ] [ "::" ] orig;
39-
in orig + (optionalString cfg.enableIPv6 ("\n" + ipv6));
46+
networking.extraHosts = filtered;
4047
};
4148
};
4249

0 commit comments

Comments
 (0)