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

Add networking.hosts and .hostFiles from nixos

Open ibizaman opened this issue 1 year ago • 10 comments

This code was taken nearly verbatim from https://github.com/NixOS/nixpkgs/blob/nixos-unstable/nixos/modules/config/networking.nix

The few changes were related to making the default /etc/hosts match the Apple's stock one. This implied no 127.0.0.2 and forcing the IPV6 ::1 entry.

ibizaman avatar Apr 22 '24 22:04 ibizaman

Possible duplicate of #807? (my PR is older and doesn't have tests though, so maybe this should be preferred)

willemml avatar May 05 '24 19:05 willemml

Sorry @willemml I missed your PR. I didn’t intend to duplicate work.

ibizaman avatar May 07 '24 00:05 ibizaman

This PR seems fine but is blocked as a review is required. How can we help to get it merged?

secana avatar Aug 19 '24 06:08 secana

Oh this would be awesome :)

niklasravnsborg avatar Aug 30 '24 19:08 niklasravnsborg

@Enzime rebasing is done. I tried to do the hash thing but I think I got it wrong.

I did cp /etc/hosts hosts, edited the file to remove the modifications I made, then sha256sum hosts and that's the hash I used. I suppose the hash is wrong though? Could someone provide me with the hash of a stock /etc/hosts file?

ibizaman avatar Sep 03 '24 22:09 ibizaman

It looks right to me:

emily@yuyuko ~> cat /etc/hosts
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1	localhost
255.255.255.255	broadcasthost
::1             localhost
emily@yuyuko ~> shasum -a 256 /etc/hosts
c7dd0e2ed261ce76d76f852596c5b54026b9a894fa481381ffd399b556c0e2da  /etc/hosts

emilazy avatar Sep 03 '24 23:09 emilazy

However the file in doc/ seems to be missing the trailing newline.

emilazy avatar Sep 03 '24 23:09 emilazy

@emilazy good catch! Indeed:

Without the newline:

$ sha256sum doc/known-files/c7dd0e2ed261ce76d76f852596c5b54026b9a894fa481381ffd399b556c0e2da
1b6fb3e08d41ae31b6bfe1f66fecf3ef53e302047993f6235570bc9391f291bb  doc/known-files/c7dd0e2ed261ce76d76f852596c5b54026b9a894fa481381ffd399b556c0e2da

With:

$ sha256sum doc/known-files/c7dd0e2ed261ce76d76f852596c5b54026b9a894fa481381ffd399b556c0e2da
c7dd0e2ed261ce76d76f852596c5b54026b9a894fa481381ffd399b556c0e2da  doc/known-files/c7dd0e2ed261ce76d76f852596c5b54026b9a894fa481381ffd399b556c0e2da

ibizaman avatar Sep 04 '24 02:09 ibizaman

Looks like the tests are broken now

Enzime avatar Sep 04 '24 03:09 Enzime

@Enzime indeed 😞 I have two questions related to the two failures I see.

How can I fix the /etc/hosts file exists issue? Does the error now come from me including a wrong /etc/hosts file? How can I print the /etc/hosts file from CI?

I looked and looked at the test output and can’t see the error printed out. How can I run the tests locally if I use flakes? I tried a few command line incantations but I can’t seem to make it right.

ibizaman avatar Sep 04 '24 04:09 ibizaman