NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.35k stars 14.31k forks source link

Enabling Geoclue2 should enable services.avahi #329522

Open SrTobi opened 4 months ago

SrTobi commented 4 months ago

Describe the bug

I noticed that redshift doesn't find the location via geoclue2 anymore. It seems that geoclue2 requires another service called avahi, which didn't run on my system.

Setting

location.provider = "geoclue2";

enables the geoclue2 service, but that one fails to provide location data. Asking for the status gives

[~]$ systemctl status geoclue

Jul 23 23:35:30 thinkjet systemd[1]: Starting Location Lookup Service...
Jul 23 23:35:30 thinkjet .geoclue-wrappe[86012]: Failed to open /etc/geoclue/conf.d/: Error opening directory “/etc/geoclue/conf.d/”: No such file or directory
Jul 23 23:35:30 thinkjet .geoclue-wrappe[86012]: Failed to connect to avahi service: Daemon not running
Jul 23 23:35:30 thinkjet systemd[1]: Started Location Lookup Service.

after manually enabling avahi via

services.avahi.enable = true;

Everything works fine...

Note: I think for many people the avahi service is automatically enabled by other settings. For example guix, gnome, and pulseaudio with hasZeroconf will enable avahi.

Expected behavior

I think when the geoclue2 service is enabled, the avahi service should be enabled too.

Notify maintainers

@davidak, @bobby285271

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.6.41, NixOS, 24.11 (Vicuna), 24.11pre655874.68c9ed8bbed9`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.5`
 - channels(root): `"nixos"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

Add a :+1: reaction to issues you find important.

bobby285271 commented 4 months ago

Hmmm yeah I guess we should do that when services.geoclue2.enableNmea is enabled.

stephen-huan commented 4 months ago

Since the fix is one line, I added it to https://github.com/NixOS/nixpkgs/pull/329654 although the PR is unrelated. Note that since enableNmea is enabled by default, this now pulls in avahi even though avahi isn't necessary for most of the providers (definitely not wifi and static, I haven't tested the others). I consider this minor since someone concerned with minimalism can always disable this with enableNmea = false. We don't have the granularity to know whether enableNmea was explicitly enabled anyways.

@SrTobi to be clear your provider is NMEA, correct?

SrTobi commented 4 months ago

Ok, please wait before merging this... today geoclue isn't working for me anymore even though the avahi service is enabled... I can therefore not be sure if my assessment above is correct... I have to investigate this further.

stephen-huan commented 4 months ago

Some steps that may help narrow the issue:

  1. How are you testing that geoclue works? Through redshift? What does the demo-agent show, e.g. /nix/store/fbs4f1xrx0bj3mggc0rqxx7p91z16ccm-geoclue-2.7.0/libexec/geoclue-2.0/demos/where-am-i (the path to geoclue can be found with ls /nix/store | grep geoclue-2.7.0, for example).

  2. What is your intended provider? (e.g. nmea, wifi, static-source). Does it work if you set your location statically like https://github.com/NixOS/nixpkgs/issues/311595#issuecomment-2247989491?

  3. What do systemctl status geoclue.service, journalctl -u geoclue.service, systemctl status --user geoclue-agent.service, journalctl --user-unit=geoclue-agent.service, systemctl status --user redshift.service, and journalctl --user-unit redshift.service show? If systemctl restart geoclue.service fixes the issue (i.e. the issue only happens at boot), the boot log journalctl -b can also be useful.

  4. Presumably redshift used to work and recently broke. Since the module hasn't been changed in months (https://github.com/NixOS/nixpkgs/commit/6afb255d976f85f3359e4929abd6f5149c323a02), what caused the change? did you upgrade recently? Otherwise, if your provider is wifi, I can think of https://github.com/NixOS/nixpkgs/issues/321121 as a possible culprit.

99linesofcode commented 3 months ago

Please refer to #321121 for more information on why geoclue2 is currently failing. That fact that it is no longer working probably has nothing to do with the changes proposed in https://github.com/NixOS/nixpkgs/pull/329654.

stephen-huan commented 3 months ago

The current working premise implied by https://github.com/NixOS/nixpkgs/issues/329522#issuecomment-2246679016 is that the author of the issue is using the nmea provider, which to the best of my knowledge is the only provider which requires the avahi service. If they were using the wifi provider (the only provider affected by the Mozilla Location Service (MLS) changes), avahi isn't relevant.

The PR https://github.com/NixOS/nixpkgs/pull/329654 adds the static (and compass) source(s), allowing one to circumvent the MLS issues with manual intervention. I initially included the unrelated fix to enable avahi when nmea is enabled since it was simple, but I've since removed it due to the concerns in https://github.com/NixOS/nixpkgs/issues/329522#issuecomment-2249569279.

Re: MLS I already mentioned this in my 4th point of https://github.com/NixOS/nixpkgs/issues/329522#issuecomment-2249622510.

SrTobi commented 2 months ago

Ok, sorry for sitting on it for so long. I just tried to debug this again and now I am not able at all to get any location via geoclue. I'm pretty sure it's because of the deactivation of the Mozilla service.

Curious thing is how I got a location at the time when I opened the issue. Nmea is enabled, but I cannot tell whether the location came from there (though maybe activating avahi made that work... idk). I guess I will use location.provider = "manual" for now.

99linesofcode commented 2 months ago

Ok, sorry for sitting on it for so long. I just tried to debug this again and now I am not able at all to get any location via geoclue. I'm pretty sure it's because of the deactivation of the Mozilla service.

Curious thing is how I got a location at the time when I opened the issue. Nmea is enabled, but I cannot tell whether the location came from there (though maybe activating avahi made that work... idk). I guess I will use location.provider = "manual" for now.

If it helps, myself and others have gotten geoclue2 to work by changing the provider:

https://github.com/NixOS/nixpkgs/issues/68489#issuecomment-2320523312

kira-bruneau commented 4 weeks ago

The original problem was #321121, but it looks like this can still be handled better. Maybe NMEA should be disabled by default, since most desktops & laptops don't have GPS tracking. It would at least get rid of this misleading error for most users.

Then if GPS support is really needed, and NMEA is explicitly enabled, Avahi could be automatically enabled.