mirror of
https://github.com/StevenBlack/hosts.git
synced 2026-07-01 10:46:51 +00:00
Merge pull request #2813 from toastal/nix-flake-avoid-with-lib
nix flake refactor: avoid `with lib;` & use `lib.optional*`
This commit is contained in:
30
flake.nix
30
flake.nix
@@ -10,33 +10,35 @@
|
||||
in
|
||||
{
|
||||
nixosModule = { config, ... }:
|
||||
with nixpkgs.lib;
|
||||
let
|
||||
inherit (nixpkgs) lib;
|
||||
cfg = config.networking.stevenBlackHosts;
|
||||
alternatesList = (if cfg.blockFakenews then [ "fakenews" ] else []) ++
|
||||
(if cfg.blockGambling then [ "gambling" ] else []) ++
|
||||
(if cfg.blockPorn then [ "porn" ] else []) ++
|
||||
(if cfg.blockSocial then [ "social" ] else []);
|
||||
alternatesList =
|
||||
(lib.optional cfg.blockFakenews "fakenews")
|
||||
++ (lib.optional cfg.blockGambling "gambling")
|
||||
++ (lib.optional cfg.blockPorn "porn")
|
||||
++ (lib.optional cfg.blockSocial "social");
|
||||
alternatesPath = "alternates/" + builtins.concatStringsSep "-" alternatesList + "/";
|
||||
in
|
||||
{
|
||||
options.networking.stevenBlackHosts = {
|
||||
enable = mkEnableOption "Steven Black's hosts file";
|
||||
enableIPv6 = mkEnableOption "IPv6 rules" // {
|
||||
enable = lib.mkEnableOption "Steven Black's hosts file";
|
||||
enableIPv6 = lib.mkEnableOption "IPv6 rules" // {
|
||||
default = config.networking.enableIPv6;
|
||||
defaultText = literalExpression "config.networking.enableIPv6";
|
||||
};
|
||||
blockFakenews = mkEnableOption "fakenews hosts entries";
|
||||
blockGambling = mkEnableOption "gambling hosts entries";
|
||||
blockPorn = mkEnableOption "porn hosts entries";
|
||||
blockSocial = mkEnableOption "social hosts entries";
|
||||
blockFakenews = lib.mkEnableOption "fakenews hosts entries";
|
||||
blockGambling = lib.mkEnableOption "gambling hosts entries";
|
||||
blockPorn = lib.mkEnableOption "porn hosts entries";
|
||||
blockSocial = lib.mkEnableOption "social hosts entries";
|
||||
};
|
||||
config = mkIf cfg.enable {
|
||||
config = lib.mkIf cfg.enable {
|
||||
networking.extraHosts =
|
||||
let
|
||||
orig = builtins.readFile ("${self}/" + (if alternatesList != [] then alternatesPath else "") + "hosts");
|
||||
orig = builtins.readFile ("${self}/" + (lib.optionalString (alternatesList != []) alternatesPath) + "hosts");
|
||||
ipv6 = builtins.replaceStrings [ "0.0.0.0" ] [ "::" ] orig;
|
||||
in orig + (optionalString cfg.enableIPv6 ("\n" + ipv6));
|
||||
in
|
||||
orig + (lib.optionalString cfg.enableIPv6 ("\n" + ipv6));
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user