NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.11k stars 14.15k forks source link

Wi-Fi fails to work when connman is enabled with networking.connman.enable = true. #23196

Closed nihil-2019 closed 3 years ago

nihil-2019 commented 7 years ago

Issue description

When connman is enabled with networking.connman.enable = true, connman fails to see Wi-Fi. It will not be listed in technologies & when running enable wifi in connmanctl you will get the cryptic & confusing error Error wifi: Method "SetProperty" with signature "sv" on interface "net.connman.Technology" doesn't exist

Oddly enough, connman works fine when networking.connman.enable = false & networking.wireless.enable = true (specifically, when wpa_supplicant is running, which of course also requires a valid wpa_supplicant.conf otherwise it'll fail.) & connmand is manually run as root.

Steps to reproduce

1.Put networking.connman.enable = true in configuration.nix.

  1. Run nixos-rebuild switch --upgrade

Technical details

domenkozar commented 7 years ago

cc @matejc

lukateras commented 6 years ago

See workaround in https://github.com/yegortimoshenko/overlay/commit/4b868de06aab147dd7b78bff13392c4076a7168a.

stefano-m commented 6 years ago

FTR I have applied a similar workaround to @yegortimoshenko in my configuration.nix

  networking.wireless = {
    enable = true; # Actually automatically enabled by connman.
    networks = {
      # Fake ssid so NixOS creates wpa_supplicant.conf
      # otherwise the service fails and WiFi is not available.
      # https://github.com/NixOS/nixpkgs/issues/23196
      S4AKR00UNUN21W1NV2Y5MDDW8 = {};
    };
  };

I think that it would be possible to fix this if the connman configuration did something similar when it's being instantiated:

  1. check wireless.networks
  2. if empty, add an entry that is a random string (to reduce the chance of collisions)

If people are interested, I'd be willing to submit a PR (with some guidance from maintainers/developers).

BTW, this happens in:

Thanks!

doronbehar commented 5 years ago

So isn't it a duplicate of https://github.com/NixOS/nixpkgs/issues/56125 ?

doronbehar commented 4 years ago

This workaround is no longer needed.

stefano-m commented 4 years ago

@doronbehar unfortunately I can still reproduce the issue with a fresh NixOS 20.03.2651.0a40a3999eb.

Would it be possible to reopen this issue please? I don't want to create duplicates.

Thanks.

doronbehar commented 4 years ago

@stefano-m many things have changed since your last comment - e.g the names of the options. I think it'd be better to open a new issue with better info of the NixOS version you use (I can confirm I don't experience this issue anymore on unstable) and ccing the module's maintainer.

stefano-m commented 4 years ago

56125 fixes the issue with iwd but the problem is still present with wpa_supplicant.

I can open a new GitHub issue allright, but the problem on the latest stable 20.03 (fresh installation) is the same as described here with the same workaround https://github.com/NixOS/nixpkgs/issues/23196#issuecomment-392932006).

If the problem has been fixed in unstable, unfortunately it does not make the situation any better for users that are on the stable channel.

Also, AFAIU this does not even seem to be fixed in unstable, because networking.wireless.enable with no networks configured still relies on a /etc/wpa_supplicant.conf file

https://github.com/NixOS/nixpkgs/blob/0e623f14b645ce0e773efb700f10c28eb2b7d5fd/nixos/modules/services/networking/wpa_supplicant.nix#L7

https://github.com/NixOS/nixpkgs/blob/0e623f14b645ce0e773efb700f10c28eb2b7d5fd/nixos/modules/services/networking/wpa_supplicant.nix#L28

that may or may not exist. In the case of connman, that file does not exist, which causes the wpa supplicant service to fail which causes connman to be unable to use wifi.

jraygauthier commented 4 years ago

Alternative workaround (which is also nice for plain wpa supplicant use so that wpa_gui can be used by users in the network group):

{
  users.groups = {
    "network" = {};
  };

  systemd.services.wpa_supplicant_initial_cfg = {
      description = "WPA Supplicant Initial Configuration";

      before = [ "network.target" "wpa_supplicant.service" ];
      wants = [ "network.target" ];
      wantedBy = [ "multi-user.target" "wpa_supplicant.service" ];

      path = [];

      script = ''
        if ! test -e "/etc/wpa_supplicant.conf"; then
          printf "ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=network\nupdate_config=1\n" > /etc/wpa_supplicant.conf
        fi
        chmod 600 /etc/wpa_supplicant.conf
      '';

      serviceConfig = {
        Type = "oneshot";
        RemainAfterExit = true;
      };
  };

  networking = {
    wireless.enable = true;
    connman.enable = true;
  };
}
doronbehar commented 4 years ago

If the problem has been fixed in unstable, unfortunately it does not make the situation any better for users that are on the stable channel.

I agree :grimacing: though we are near yet a 20.09 release and I sure hope whatever commit that fixed it on unstable will reach 20.09. I'll reopen as it seems others are still facing this issue on 20.03. If anyone is capable of verifying that the issue persists on 20.03 or 20.09, it'll help.

stefano-m commented 4 years ago

Well, I'm happy that this has been reopened although, looking at the code on master, I have the feeling that this is not yet solved.

The problem is that connman sets networking.wifi.enable to true but it does not set a default configuration for wpa_supplicant causing the wpa_supplicant service to fail.

I wish I had more time to look into it since it's been bothering me for a while. I hope that eventually I'll be able to post a PR.

Thanks for keeping this issue open.

knuton commented 3 years ago

Is it possible that this is related to https://github.com/NixOS/nixpkgs/issues/101963?

Applying @rnhmjoj's fix (https://github.com/NixOS/nixpkgs/pull/104722) I observe reliable availability of wifi in NixOS 20.09 (including on first boot), even when removing the dummy network workaround.

stale[bot] commented 3 years ago

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

doronbehar commented 3 years ago

I close this considering @knuton's report that this is not an issue on stable and unstable anymore.

stefano-m commented 3 years ago

Interesting... I have recently moved to NixOS 21.05 and the issue was still present for me. I don't mind that this issue has been closed. If I ever get to it I might investigate further and possibly submit a patch.

In the meantime I changed my workaround slightly:

  environment.etc."wpa_supplicant.conf".text = lib.mkIf
    config.services.connman.enable
    ''
      # Dummy config file. Connman uses wpa_supplicant directly.
    '';

The only annoying thing is that with 21.05 I get a warning whenever I rebuild because "wpa_supplicant" has not interfaces:

trace: warning: No network interfaces for wpa_supplicant have been configured: the service
may randomly fail to start at boot. You should specify at least one using the option
networking.wireless.interfaces.

I guess this can be avoided by conditionally disabling the warning is services.connman.enable is true.

rnhmjoj commented 3 years ago

@stefano-m I must be missing something: why are you enabling networking.wireless when using services.connman? You say connman starts wpa_supplicant manually, so you should configure the its daemon using networking.wireless.

stefano-m commented 3 years ago

Not sure I follow...

IIRC services.connman.enable = true also enables networking.wireless

https://github.com/NixOS/nixpkgs/blob/bad3ccd099ebe9a8aa017bda8500ab02787d90aa/nixos/modules/services/networking/connman.nix#L152

and I guess that then the warning follows.

Connman configures wpa_supplicant on its own, I don't need to do anything directly.

rnhmjoj commented 3 years ago

Ah, I missed that line, thanks. So, connman starts the daemon and writes to /etc/wpa_supplicant.conf at runtime?

stefano-m commented 3 years ago

AFAIU no, it does not, it just sets networking.wireless to true (and disables NetworkManager).

I guess that ideally, it should create a dummy /etc/wpa_supplicant.conf if none exists, and at the same time networking.wireless should disable the warning if connman is enabled.

knuton commented 3 years ago

I close this considering @knuton's report that this is not an issue on stable and unstable anymore.

My report above was about a version of nixpkgs with https://github.com/NixOS/nixpkgs/pull/104722 applied, however this patch has been reverted in upstream nixpkgs and no longer is present in 21.05 (see also https://github.com/NixOS/nixpkgs/issues/107341#issuecomment-862155447).

So I can't say how this behaves in current NixOS, sorry. :-)

rnhmjoj commented 3 years ago

This should be finally fixed with #127595 (now in nixos-unstable).