Jump to content

ModemManager: Difference between revisions

From Official NixOS Wiki
Manu (talk | contribs)
m Removed information that is accurate only if the other services defined under the section "Unreliable suspend/resume" are enabled.
Manu (talk | contribs)
As a result from the last findings in https://github.com/NixOS/nixpkgs/issues/493446, the configuration documented here turned out to be wrong. Some configuration was also too much NetworkManager specific. A page dedicated to modems will be created in the future.
 
Line 4: Line 4:
It is possible to enable the modem with:<syntaxhighlight lang="nix">
It is possible to enable the modem with:<syntaxhighlight lang="nix">
networking.modemmanager.enable = true;
networking.modemmanager.enable = true;
</syntaxhighlight>A good rule of thumb is to use NetworkManager as much as possible and rely on ModemManager functionality directly only when necessary (e.g., when having to insert a PIN to unlock the SIM card).
</syntaxhighlight>A good rule of thumb is to use NetworkManager as much as possible for WWAN functionality and rely on ModemManager functionality directly only when necessary (e.g., when having to insert a PIN to unlock the SIM card).
 
== Tips and Tricks ==
 
=== Prevention of WWAN connection on boot ===
Due concerns related to tracking and privacy, it may be wished to never automatically establish a cellular connection on boot. The custom Serviced service below allows to achieve exactly this goal.<syntaxhighlight lang="nixos"># Ensure that the modem does not establish a cellular connection
# on boot.
systemd.services.NetworkManager-radio-wwan-initial-setup = {
  description = "Disable WWAN radio on first ModemManager start";
  wantedBy = [ "multi-user.target" ];
  before = [ "ModemManager.service" ];
  after = [ "NetworkManager.service" ]; # Wait for NetworkManager
  requires = [ "NetworkManager.service" ]; # Ensure NetworkManager is running
 
  serviceConfig = {
    Type = "oneshot";
    RemainAfterExit = true; # The service won't run again on successive ModemManager activations.
    ExecStart = "${pkgs.networkmanager}/bin/nmcli radio wwan off";
  };
};</syntaxhighlight>Note that the state of the cellular connection will be retained even if <code>ModemManager</code> is restarted (as long as the system has not been rebooted).
 
== Troubleshooting ==
 
=== Unreliable suspend/resume ===
Some modems, such as the Fibocom 350-GL, cause the system to automatically wake up from sleep. The behavior is inconsistent: sometimes it happens immediately, but it can also happen a few seconds or minutes after the machine is in suspended. Other times the machine correctly stays in sleep mode and does not wake up. Other times a loop of continuous suspensions and resumes is experienced.
 
As a workaround to the unreliability of such WWAN modules, the user needs to stop the <code>ModemManager</code> service before sleep. At this point, suspend should no longer cause the problems mentioned above. The user needs to restart the <code>ModemManager</code> service once the computer is resumed if they intend to connect to cellular data.
 
It is possible to automate this behavior by creating tailored Systemd services:<syntaxhighlight lang="nixos">
# Stop ModemManager before sleep.target is reached
# due to a bug with the WWAN module, which otherwise
# wakes up the system immediately after suspend.
systemd.services.ModemManager-stop-before-sleep = {
  wantedBy = [ "sleep.target" ];
  before = [ "sleep.target" ];
 
  serviceConfig = {
    Type = "oneshot";
    ExecStart = "${pkgs.systemd}/bin/systemctl stop ModemManager.service";
  };
};
 
# Restart ModemManager shortly after resume from suspend.
# This way the modem can be easily enabled within
# the desktop environment's networks' applet or the CLI.
systemd.services.ModemManager-restart-after-resume = {
  description = "Restart ModemManager after resume";
  wantedBy = [ "post-resume.target" ];
  after = [
    "systemd-suspend.service"
    "systemd-hibernate.service"
    "systemd-hybrid-sleep.service"
  ];
 
  serviceConfig = {
    Type = "oneshot";
    ExecStart = "${pkgs.systemd}/bin/systemctl restart ModemManager.service";
  };
};
</syntaxhighlight>

Latest revision as of 21:27, 2 March 2026

ModemManager is a DBus-activated daemon which manages cellular modems (2G, 3G, 4G and 5G) and establishes cellular data connections.[1]

Configuration

It is possible to enable the modem with:

networking.modemmanager.enable = true;

A good rule of thumb is to use NetworkManager as much as possible for WWAN functionality and rely on ModemManager functionality directly only when necessary (e.g., when having to insert a PIN to unlock the SIM card).