nix-darwin
nix-darwin copied to clipboard
Option to configure /etc/hosts file
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?
Agreed! see https://github.com/LnL7/nix-darwin/pull/939
Oh, I searched for similar issues but missed the PR. I'll close this one as a duplicate.
Reopening this until either #939 or #807 gets merged
👍
#939 is now merged 👍
#939 was reverted due to some tools having issues with a symlinked hosts file. Can this issue be reopened?
What's the plan now?
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?
I think a merge would make more sense
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).