From: Steven Black Date: Tue, 24 Feb 2026 16:43:56 +0000 (-0500) Subject: Merge pull request #2813 from toastal/nix-flake-avoid-with-lib X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=9d408efd1f35c7570425cfba1a2a271fd95180c8;p=stevenblack-hosts.git Merge pull request #2813 from toastal/nix-flake-avoid-with-lib nix flake refactor: avoid `with lib;` & use `lib.optional*` --- 9d408efd1f35c7570425cfba1a2a271fd95180c8 diff --cc flake.nix index 0cff5be40,17dee810c..34804aa37 --- a/flake.nix +++ b/flake.nix @@@ -21,22 -22,22 +22,23 @@@ 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)); }; };