Skip to content

Commit

Permalink
networking: unbreak NixOS networking.hosts
Browse files Browse the repository at this point in the history
This allows better integration with NixOS ecosystem.

Signed-off-by: Humaid Alqasimi <[email protected]>
  • Loading branch information
humaidq-tii authored and brianmcgillion committed Nov 15, 2024
1 parent d25dc39 commit b7f43e9
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions modules/common/networking/hosts.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
let
cfg = config.ghaf.networking.hosts;
inherit (lib)
foldr
mkIf
types
mkOption
optionals
recursiveUpdate
types
;

hostsEntrySubmodule = types.submodule {
Expand Down Expand Up @@ -81,12 +83,6 @@ let
}
];

mkHostEntryTxt =
{ ip, name }:
"${ipBase}.${toString ip}\t${name}\n"
+ lib.optionalString config.ghaf.profiles.debug.enable "${debugBase}.${toString ip}\t${name}-debug\n";
entriesTxt = map mkHostEntryTxt hostsEntries;

mkHostEntry =
{ ip, name }:
{
Expand All @@ -105,7 +101,7 @@ let
in
{
options.ghaf.networking.hosts = {
enable = (lib.mkEnableOption "Ghaf hosts file generation") // {
enable = (lib.mkEnableOption "Ghaf hosts entries") // {
default = true;
};
entries = mkOption {
Expand All @@ -122,10 +118,10 @@ in
inherit entries;
};

# Generate hosts file
environment.etc.hosts = lib.mkForce {
text = lib.foldl' (acc: x: acc + x) "127.0.0.1 localhost\n" entriesTxt;
mode = "0444";
};
networking.hosts = foldr recursiveUpdate { } (
map (vm: {
"${vm.ip}" = [ "${vm.name}" ];
}) config.ghaf.networking.hosts.entries
);
};
}

0 comments on commit b7f43e9

Please sign in to comment.