Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/networkmanager: allow iwd as Wi-Fi backend #68147

Merged
merged 1 commit into from Oct 3, 2019

Conversation

colemickens
Copy link
Member

Replaces #51803. Please see it for earlier discussion. I think all I did was rebase and fix merge conflicts. As requested by @dtzWill.

Works well for me. Connecting and disconnecting via nmtui is remarkably faster than with wpa_supplicant (or, at least, without this change and using IWD).

@colemickens
Copy link
Member Author

Should this target staging, maybe?

@worldofpeace
Copy link
Contributor

worldofpeace commented Sep 5, 2019

Should this target staging, maybe?

Don't think so. It shouldn't cause a mass rebuild since the feature is already enabled, changes don't touch the networkmanager expression.

@worldofpeace
Copy link
Contributor

worldofpeace commented Sep 6, 2019

So i tried using this and it appears there is some config that should be shared between the iwd module.
This probably worked for because maybe you were using it before.

diff --git a/nixos/modules/services/networking/networkmanager.nix b/nixos/modules/services/networking/networkmanager.nix
index 0dc4aec95ab..1d4c1dd585e 100644
--- a/nixos/modules/services/networking/networkmanager.nix
+++ b/nixos/modules/services/networking/networkmanager.nix
@@ -526,5 +526,11 @@ in {
       optional cfg.enableStrongSwan pkgs.strongswanNM ++ cfg.packages;
 
     services.udev.packages = cfg.packages;
+
+    systemd.services.iwd.wantedBy = mkIf (cfg.wifi.backend == "iwd") [ "multi-user.target" ];
+
+    systemd.tmpfiles.rules = mkIf (cfg.wifi.backend == "iwd") [
+      "d /var/lib/iwd 0700 root root -"
+    ];
   };
 }

with that it worked on my system.

I have to ask if they're really mutually exclusive? How does NetworkManager use iwd?
Edit: looked and for nixos we need the same configuration as what's in the iwd module. Not sure there's a clearer way to not duplicate it, but I think it's fine for this change.

@worldofpeace
Copy link
Contributor

You should also include #68213 for networkmanager.

@colemickens
Copy link
Member Author

Hm, I thought the assert that's in this change was specifically because NM controls the IWD lifecycle when IWD is used with NM. I may have had the /var/lib/iwd directory because I had briefly directly enabled iwd, but my setup is working fine without the extra wantedBy you have suggested, again (I thought), due to NM controlling the IWD lifecycle in this scenario.

Do you want me to pull the commit from #68213 in here, or just review it and make this PR depend on merging it first?

@worldofpeace
Copy link
Contributor

Hm, I thought the assert that's in this change was specifically because NM controls the IWD lifecycle when IWD is used with NM. I may have had the /var/lib/iwd directory because I had briefly directly enabled iwd, but my setup is working fine without the extra wantedBy you have suggested, again (I thought), due to NM controlling the IWD lifecycle in this scenario.

Yeah, I think because of that the state directories would already have been ready.
The wantedBy is already in the iwd module so that's why it's there.

Do you want me to pull the commit from #68213 in here, or just review it and make this PR depend on merging it first?

I'm not sure if we're going the route of enabling the iwd module conditionally within the networkmanager module (I think it could be possible) or duplicating it.
Looking at the code here, using cfg.packages actually adds the packages to the same options as the iwd module does already. So I think it would be fine to just enable iwd within the networkmanager module.

@worldofpeace
Copy link
Contributor

We discussed in depth on irc

@colemickens colemickens force-pushed the nixpkgs-nm-iwd branch 2 times, most recently from 7a97ee0 to ead2182 Compare September 12, 2019 20:18
@colemickens
Copy link
Member Author

@worldofpeace It seems like chain-enabling the iwd nixos option worked.

Can you take a look? I think I've addressed everything you mentioned now?

@worldofpeace
Copy link
Contributor

@colemickens, new change got merged that added another variable to check into the mix.
I added b07d6f5 for this, I hope you don't mind.

@colemickens
Copy link
Member Author

I had to do some weird merging fixups when I cherrypicked the ell/iwd-bump and then these two commits, but it seems to work fine. Should I squash and repush these, @worldofpeace ?

@worldofpeace
Copy link
Contributor

I had to do some weird merging fixups when I cherrypicked the ell/iwd-bump and then these two commits, but it seems to work fine. Should I squash and repush these, @worldofpeace ?

Sure, I'll also request the review of one more person 👍

@worldofpeace
Copy link
Contributor

It would have been no-op until b4044a3 landed. We could revert it on master to fix the issue, as the assertion for that was broken. And then we can revert my fixup commit and merge.
Though I'm short on time with other things currently.

@JohnAZoidberg
Copy link
Member

I'll check it out until tomorrow how to reconcile this with b4044a3.

@JohnAZoidberg
Copy link
Member

I'm not sure why

networking.networkmanager.enable = true;  
networking.wireless.enable = true;

works for you, @worldofpeace. 🤔
The assertion clearly rules that out. Do you have networking.networkmanager.unmanaged set to a non-empty list somewhere?

With the new changes here, though, I'd add this diff to the PR:

--- i/nixos/modules/services/networking/networkmanager.nix
+++ w/nixos/modules/services/networking/networkmanager.nix
@@ -394,10 +394,12 @@ in {
   config = mkIf cfg.enable {

     assertions = [
-      { assertion = config.networking.wireless.enable == true -> cfg.unmanaged != [];
+      { assertion = config.networking.wireless.enable ->
+          (cfg.unmanaged != [] || cfg.wifi.backend == null);
         message = ''
           You can not use networking.networkmanager with networking.wireless.
-          Except if you mark some interfaces as <literal>unmanaged</literal> by NetworkManager.
+          Except if you mark some interfaces as `unmanaged` by NetworkManager
+          or set the wifi backend to `null`.
         '';
       }
       { assertion = !dynamicHostsEnabled || (dynamicHostsEnabled && cfg.dns == "dnsmasq");

@worldofpeace
Copy link
Contributor

Huh, I tested again on a running system and I get the assertion message. I guess you can't test this with a vm.

Also, I'm not sure if networkmanager has a concept of not using any backend. So allowing null as a value doesn't make sense. What actually matters is what's set as unmanaged.

@worldofpeace worldofpeace changed the title networkmanager: allow iwd as Wi-Fi backend nixos/networkmanager: allow iwd as Wi-Fi backend Sep 21, 2019
@worldofpeace
Copy link
Contributor

@JohnAZoidberg I believe this should be correct now.

@ofborg ofborg bot added 6.topic: GNOME GNOME desktop environment and its underlying platform 6.topic: pantheon The Pantheon desktop environment 6.topic: xfce The Xfce Desktop Environment labels Sep 21, 2019
Copy link
Member

@JohnAZoidberg JohnAZoidberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you're right. NM seems to use supplicant if no wifi.backend is given.

@xaverdh
Copy link
Contributor

xaverdh commented Sep 24, 2019

This works for me. But dhclient gives me the following error:

Can't bind to dhcp address: Address already in use
Please make sure there is no other dhcp server
running and that there's no entry for dhcp or
bootp in /etc/inetd.conf.   Also make sure you
are not running HP JetAdmin software, which
includes a bootp server.

If you think you have received this message due to a bug rather
than a configuration issue please read the section on submitting
bugs on either our web page at www.isc.org or in the README file
before submitting a bug.  These pages explain the proper
process and the information we find helpful for debugging.

exiting.

So I guess dhclient shouldn't be running when using iwd?

@worldofpeace
Copy link
Contributor

Interesting,

This works for me. But dhclient gives me the following error:

Can't bind to dhcp address: Address already in use
Please make sure there is no other dhcp server
running and that there's no entry for dhcp or
bootp in /etc/inetd.conf.   Also make sure you
are not running HP JetAdmin software, which
includes a bootp server.

If you think you have received this message due to a bug rather
than a configuration issue please read the section on submitting
bugs on either our web page at www.isc.org or in the README file
before submitting a bug.  These pages explain the proper
process and the information we find helpful for debugging.

exiting.

So I guess dhclient shouldn't be running when using iwd?

We currently default to internal. Also, I'm not sure if the problem would be them conflicting in any way. iwd has nothing to do with dhcp.

@xaverdh
Copy link
Contributor

xaverdh commented Sep 24, 2019

We currently default to internal. Also, I'm not sure if the problem would be them conflicting in any way. iwd has nothing to do with dhcp.

Actually, I think dhclient is the default if I read the code on master correctly.
Also from the Arch Wiki:
Since version 0.19, iwd can assign IP address(es) and set up routes using a built-in DHCP client or with static configuration.
Although according to https://git.kernel.org/pub/scm/network/wireless/iwd.git/commit/?id=199e647ffde38584d5bab609de38bea973082ffe iwd's internal dhcp should be off by default.

@worldofpeace
Copy link
Contributor

@xaverdh Oh, that change hasn't hit master yet 1ff3a0c.

And it does seem it has this function. I don't think the module for iwd handles any config file so I bet our issue is right there.

@xaverdh
Copy link
Contributor

xaverdh commented Sep 25, 2019

Indeed with internal dhcp everything works just fine.

@jluttine
Copy link
Member

For your information, this pull request fixes #69368 (thanks @xaverdh). (Or not sure if fixing the issue is correctly said, but at least offers one workaround.)

@asymmetric
Copy link
Contributor

OT: what's the advantage of using iwd as a NM backend as opposed to just using iwctl?

@jluttine
Copy link
Member

Not familiar with these, so I might speak nonsense, but AFAIU, NetworkManager has everything in one place. So you can manage wired&wireless connections and VPN from one app/applet/trayicon.

This introduces an option wifi.backend to the networkmanager module.

Co-authored-by: Cole Mickens <cole.mickens@gmail.com>
Co-authored-by: worldofpeace <worldofpeace@protonmail.ch>
@worldofpeace
Copy link
Contributor

Rebased as I've removed the basePackages #70041 code which was unneeded.

@worldofpeace worldofpeace merged commit c76a1ea into NixOS:master Oct 3, 2019
@ofborg ofborg bot removed 6.topic: GNOME GNOME desktop environment and its underlying platform 6.topic: pantheon The Pantheon desktop environment 6.topic: xfce The Xfce Desktop Environment labels Oct 3, 2019
@flokli flokli mentioned this pull request Oct 15, 2019
10 tasks
@colemickens colemickens deleted the nixpkgs-nm-iwd branch January 30, 2020 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants