NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.06k stars 14.12k forks source link

hostname disappears after starting DHCP #36878

Open hlolli opened 6 years ago

hlolli commented 6 years ago

Issue description

On xserver applications I was getting unable to open display ":0.0" after connecting to the internet. Seemingly after discussion on the #nixos irc, this is because hostname which I set to localhost in my config.nix networking.hostname="localhost"; returns localhost but after running sudo dhclient wlp2s0, and essentialy connect to the wifi, (useing wpa_supplicant and networkmanager), causes hostname to return nothing, and all xorg apps to complain about no display ":0.0"

Steps to reproduce

sudo wpa_supplicant -B -i wlp2s0 -Dnl80211 -c /etc/wpa_supplicant.conf
sudo dhclient wlp2s0 firefox => unable to open display ":0.0"`

Technical details

 ~ nix-shell -p nix-info --run "nix-info -m"                        ~
 - system: `"x86_64-linux"`
 - host os: `Linux 4.9.86, NixOS, 17.09.3146.084445b8f38 (Hummingbird)`
 - multi-user?: `yes`
 - sandbox: `no`
 - version: `nix-env (Nix) 1.11.16`
 - channels(root): `"nixos-unstable-18.03pre130932.cc4677c36ee, nixos-17.09.3146.084445b8f38"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs`

ps. a workaround is sudo hostname localhost

lheckemann commented 6 years ago

So I think this is two or maybe even three issues at once [I'm sphalerite on irc! :) ]:

  1. networking.hostname = "localhost"; being equivalent to networking.hostname = null;; AFAIU only the latter should result in the hostname being acquired via DHCP
  2. X applications breaking on hostname change. I'm guessing this is because of the Xauthority cookie being hostname-specific. I wonder how other distros handle this, if at all.
  3. The hostname being set to the empty string via DHCP, maybe this shouldn't happen either?
hlolli commented 5 years ago

So I realized when changing hostname, Xorg needs to authenticate it via login. So a reboot after changing hostname is needed for Xorg to authorize the new hostname.

lheckemann commented 5 years ago

Yes, that's part 2 of my explanation. What should also work is using xhost to authorise the new hostname, or simply restarting only the X server (logging out should be enough for this). Parts 1 and 3 are still problematic though.

hlolli commented 5 years ago

Maybe it's connected with the fact that intetutils 1.9.4 is from 2015? I just bumped into this again when changing my hostname for avahi local domains. I can keep it open, but what are the odds someone looks into a year old ticket :D

lheckemann commented 5 years ago

Higher now that github has a related issues feature ;) it seems there hasn't been a more recent inetutils release though https://ftp.gnu.org/gnu/inetutils/?C=M;O=A

stale[bot] commented 4 years ago

Thank you for your contributions.

This has been automatically marked as stale because it has had no activity for 180 days.

If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.

Here are suggestions that might help resolve this more quickly:

  1. Search for maintainers and people that previously touched the related code and @ mention them in a comment.
  2. Ask on the NixOS Discourse.
  3. Ask on the #nixos channel on irc.freenode.net.
lheckemann commented 4 years ago

no

flokli commented 4 years ago

Might be solved by https://github.com/NixOS/nixpkgs/issues/74847#issuecomment-646160363.

stale[bot] commented 3 years ago

I marked this as stale due to inactivity. → More info