|
10 | 10 | in |
11 | 11 | { |
12 | 12 | nixosModule = { config, ... }: |
13 | | - with nixpkgs.lib; |
14 | 13 | let |
| 14 | + inherit (nixpkgs) lib; |
15 | 15 | cfg = config.networking.stevenBlackHosts; |
16 | | - alternatesList = (if cfg.blockFakenews then [ "fakenews" ] else []) ++ |
17 | | - (if cfg.blockGambling then [ "gambling" ] else []) ++ |
18 | | - (if cfg.blockPorn then [ "porn" ] else []) ++ |
19 | | - (if cfg.blockSocial then [ "social" ] else []); |
| 16 | + alternatesList = |
| 17 | + (lib.optional cfg.blockFakenews "fakenews") |
| 18 | + ++ (lib.optional cfg.blockGambling "gambling") |
| 19 | + ++ (lib.optional cfg.blockPorn "porn") |
| 20 | + ++ (lib.optional cfg.blockSocial "social"); |
20 | 21 | alternatesPath = "alternates/" + builtins.concatStringsSep "-" alternatesList + "/"; |
21 | 22 | in |
22 | 23 | { |
23 | 24 | options.networking.stevenBlackHosts = { |
24 | | - enable = mkEnableOption "Steven Black's hosts file"; |
25 | | - enableIPv6 = mkEnableOption "IPv6 rules" // { |
| 25 | + enable = lib.mkEnableOption "Steven Black's hosts file"; |
| 26 | + enableIPv6 = lib.mkEnableOption "IPv6 rules" // { |
26 | 27 | default = config.networking.enableIPv6; |
27 | 28 | }; |
28 | | - blockFakenews = mkEnableOption "fakenews hosts entries"; |
29 | | - blockGambling = mkEnableOption "gambling hosts entries"; |
30 | | - blockPorn = mkEnableOption "porn hosts entries"; |
31 | | - blockSocial = mkEnableOption "social hosts entries"; |
| 29 | + blockFakenews = lib.mkEnableOption "fakenews hosts entries"; |
| 30 | + blockGambling = lib.mkEnableOption "gambling hosts entries"; |
| 31 | + blockPorn = lib.mkEnableOption "porn hosts entries"; |
| 32 | + blockSocial = lib.mkEnableOption "social hosts entries"; |
32 | 33 | }; |
33 | | - config = mkIf cfg.enable { |
| 34 | + config = lib.mkIf cfg.enable { |
34 | 35 | networking.extraHosts = |
35 | 36 | let |
36 | | - orig = builtins.readFile ("${self}/" + (if alternatesList != [] then alternatesPath else "") + "hosts"); |
| 37 | + orig = builtins.readFile ("${self}/" + (lib.optionalString (alternatesList != []) alternatesPath) + "hosts"); |
37 | 38 | ipv6 = builtins.replaceStrings [ "0.0.0.0" ] [ "::" ] orig; |
38 | | - in orig + (optionalString cfg.enableIPv6 ("\n" + ipv6)); |
| 39 | + in |
| 40 | + orig + (lib.optionalString cfg.enableIPv6 ("\n" + ipv6)); |
39 | 41 | }; |
40 | 42 | }; |
41 | 43 |
|
|
0 commit comments