Skip to content

Commit

Permalink
nix flake: use lib.mkAfter to allow extraHosts
Browse files Browse the repository at this point in the history
At present, if a user uses ``networking.stevenBlockHosts.enable = true``
in tandem with ``networking.extraHosts``, the ``extraHosts`` will
override this Flake which is an unexpected behavior. By using
``lib.mkAfter``, a user can now prepend extra hosts. Meaning:

.. code:: nix

  {
    networking = {
      stevenBlockHosts.enable = true;
      extraHosts = ''
        127.0.0.1 myproject.localhost
      '';
    };
  }

will now output

.. code::

  127.0.0.1 localhost
  ::1 localhost

  127.0.0.1 myproject.localhost

  # Title: StevenBlack/hosts with the fakenews extension
  #
  # …

instead of removing StevenBlack/hosts.

Format: text/x-rst
  • Loading branch information
toastal committed Feb 8, 2025
1 parent 04e625d commit 74b7d5e
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
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 []) ++
Expand All @@ -35,7 +36,8 @@
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));
in
lib.mkAfter (orig + (lib.optionalString cfg.enableIPv6 ("\n" + ipv6)));
};
};

Expand Down

0 comments on commit 74b7d5e

Please sign in to comment.