nm-applet woes

Having troubles getting nm-applet to cooperate on a WM other than Gnome (say, Xmonad)?
It runs, but doesn’t remember the WLAN password? You need to sudo it to life on your own?

There, I’ve been through this recently, deciding to forfeit netcfg in favour of NetworkManager + Gnome network applet so I don’t have to type each new network I come across into wpa_supplicant.conf, and here is a recipe how to get it to run and work properly with the Gnome keyring. It took me almost two days of battling with gnome-keyring-daemon, D-bus and policykit to figure it out, so I may as well help you out with the steps I followed to get it working. Mind you, I’m not a Linux guru, so I can’t say if everything I did was essential to getting it working, but it probably most of it is.

So there, let’s assume we have a working install of Arch Linux with an Xserver. I myself use SLiM as the login manager, it generally just calls the ~/.xinitrc script with a parameter of session name. I guess these instructions can be applied to pretty much any other distro/WM combo as long as you know how your package manager works ; )

1. Installing NetworkManager
First of all we would like to install the NetworkManager package. On Arch Linux we do it like this (of course if for some inexplicable reason you are root drop the sudo):

sudo pacman -S networkmanager

Then we need to configure it, as per ArchWiki:
We need to make sure it will broadcast our hostname properly. To see to that we create file /etc/NetworkManager/nm-system-settings.conf and fill it with:

[main]
plugins=keyfile

[keyfile]
hostname=your_hostname_from_/etc/hosts_here

where keyfile plugin is the minimum required for NetworkManager to run.

You may also want to make sure that your /etc/hosts file is still like it was (NM could change it if you by accident tried to connect before filling the config file) and your user is in network group with groups; if you aren’t, then

sudo gpasswd -a YOUR_USERNAME_HERE network

should do the trick.

NetworkManager at this moment is ready to rock – you can bring down the network daemon with /etc/rc.d/network stop and do the same to the network interfaces:

sudo ifconfig eth0 down
sudo ifconfig wlan0 down

If you have any other interfaces than eth0 and wlan0 then bring them down too.
Then you should comment out the lines in /etc/rc.conf that initialize the interfaces and network:

#eth0="dhcp"                                                                    
#wlan0="dhcp"                                                                   
INTERFACES=(!eth0 !wlan0)

The ! before interfaces work just like in the daemon array – they stop kernel from bringing them up. Speaking of daemons array, you need to modify it like so:

DAEMONS=(... dbus ... networkmanager ... !network ...)

where ... are other daemons.
Generally you need to stop network (if you have net-profiles you can also get rid of it too) from running and run dbus anywhere before networkmanager (the sooner the better, because more other daemons can depend on it. If you use anything like netfs or (open)ntpd it’s better to disable them in the daemon array and use NetworkManager’s dispatcher daemon, as described here.

There, a sudo reboot and we have a working NetworkManager. But what now? Oh noes, there’s no internets!

2. nm-applet… not working!
So having set up a NetworkManager, now we need a shiny network managing applet like Ubuntu does:


In theory doing:

sudo pacman -S network-manager-applet gnome-keyring

should install the Gnome network applet that is displayed in the tray and provides useful quick connect capability and Gnome keyring that remembers long WEP passphrases for us, but that’s where the reality kicks in.
It doesn’t work.
That is, yes we can do sudo nm-applet & and it will run (of course if you have any tray manager as trayer or stalonetray or a tray comes with your WM to host it’s icon), appear in the tray and connect to a network asking you for a password. But next time you try this, you need to type the password in again.
WHAT THE HELL? Isn’t that what we installed Gnome keyring in first place for? Well, yes, but turns out that the applet can’t communicate with the daemon even though we have dbus daemon up and running (you can for example install seahorse and see it can’t communicate too).
And to add to that everytime I tried to add nm-applet to the ~/.xinitrc it wouldn’t start up – it turns out it needed to be sudoed because policykit wouldn’t let it run as a normal user.
But first see what’s up with that D-bus.

3. Put on a D-bus…
It turns out that it couldn’t communicate with the daemon, because I missed one step when installing D-bus – you not only need to have the dbus daemon running, but also to spawn and register a session bus, which you do in your ~/.xinitrc, preferably like this (to avoid having more than one session bus):

if test -x "$DBUS_SESSION_BUS_ADDRESS" ; then
	eval "$(dbus-launch --sh-syntax --exit-with-session)"
fi

You should place it before launching any application dependent on D-bus connection, like the Gnome keyring daemon.
That should let all the applications communicate with D-bus next time you run your Xserver.

4. nm-applet… still not exactly working!
What? We have the D-bus session bus up and running, but that nm-applet bugger still bothers us about the password. Dang. What’s wrong this time? It turn out that simply running gnome-keyring-daemon from ~/.xinitrc is not enough – you need to introduce some environment variables gnome-keyring-daemon spews upon execution. The proper (as per Arch developers) way to run the daemon from ~/.xinitrc is:

eval "$(gnome-keyring-daemon -s --components=pkcs11,secrets,ssh)"

The eval instruction evaluates the output of gnome-keyring-daemon as if it you typed it into the shell and the output is formed such as definitions of environment variables – tadaam, done. It’s the same trick we used on dbus-launch to register the session bus in the environment.
You should also, per official Gnome documentation, add these to their respective files:

  • In /etc/pam.d/your_display_manager_here (for SLiM it would be /etc/pam.d/slim, add lines like this at the end of ther espective ‘auth’, ‘session’ blocks:
    auth    optional        pam_gnome_keyring.so
    session optional        pam_gnome_keyring.so  auto_start
  • In /etc/pam.d/passwd, add a line like this to the ‘password’ block:
    password        optional        pam_gnome_keyring.so

This should have Gnome keyring thing working like it should (you can again try with seahorse if it connects to the keyring, which it should).

5. autorunning nm-applet…
Okay, we got rid of the annoying ask-for-password-on-every-WLAN-connection popup replacing it with slightly less annoying one-time-keyring-password popup (which too can be rid of if you really want), but we still have to run the nm-applet by hand using sudo. It’s generally a policykit issue that can be solved as mentioned here. After doing this you can easily start the applet without any sudo magic, for example from Xmonad or ~/.xinitrc.
You can do it like so:

nm-applet --sm-disable &

That’s probably it, a collection of tips to make Gnome network management applet working like it should put in one place. Hope it solves any problems you may be having with setting this up.

Leave a comment