nix-darwin icon indicating copy to clipboard operation
nix-darwin copied to clipboard

Option to configure /etc/hosts file

Open secana opened this issue 1 year ago • 10 comments

Hi!

In NixOS there is the option networking.hosts to configure the /etc/hosts file for additional DNS entries.

Example:

networking.hosts = {
  "127.0.0.2" = ["other-localhost"];
  "192.0.2.1" = ["mail.example.com" "imap.example.com"];
};

See NixOS Wiki - Networking for more information.

However, a similar options seems to be missing on nix-darwin regarding the listed options here: https://daiderd.com/nix-darwin/manual/index.html

Can we add the networking.hosts option to nix-darwin or is there already another way to configure the hosts file?

secana avatar Aug 16 '24 05:08 secana

Agreed! see https://github.com/LnL7/nix-darwin/pull/939

ibizaman avatar Aug 16 '24 17:08 ibizaman

Oh, I searched for similar issues but missed the PR. I'll close this one as a duplicate.

secana avatar Aug 19 '24 06:08 secana

Reopening this until either #939 or #807 gets merged

Enzime avatar Sep 03 '24 03:09 Enzime

👍

Teebor-Choka avatar Nov 27 '24 08:11 Teebor-Choka

#939 is now merged 👍

Enzime avatar Feb 25 '25 02:02 Enzime

#939 was reverted due to some tools having issues with a symlinked hosts file. Can this issue be reopened?

xaverhimmelsbach avatar Mar 10 '25 12:03 xaverhimmelsbach

What's the plan now?

Teebor-Choka avatar Mar 10 '25 18:03 Teebor-Choka

Doh. Sorry for the hassle there.

Would copying the file in place instead of symlinking it work here? Or should we somehow merge the output from nix darwin with the existing file?

ibizaman avatar Mar 11 '25 00:03 ibizaman

I think a merge would make more sense

tymscar avatar Apr 17 '25 13:04 tymscar

I think the best way to do this is probably to have it be an option of types.lines with a default value equal to whatever macOS puts in it by default. Then if a user wants to append to the file, they can just set it (and the module system will concatenate the values), and if they want to remove the default contents, they can use lib.mkForce.

As for how we'll get the file there, I'm less sure. We removed the ability to copy files in environment.etc because it didn't properly track and remove files. An upcoming follow-up to #1205 will allow copying files and properly track them, but at current that PR won't replace environment.etc. I still think extending that is probably a better idea than writing a bespoke implementation of file copying (although that said, /etc/hosts needs to always exist, so I guess we could just unconditionally copy over it).

Samasaur1 avatar Apr 17 '25 17:04 Samasaur1