NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.45k stars 13.65k forks source link

ModemManager.service does not start automatically by enabling the service #270809

Open n-hass opened 9 months ago

n-hass commented 9 months ago

Describe the bug

Given the following configuration, ModemManager.service fails to start on boot.

{ config, pkgs, lib, ... }:

{
  environment.systemPackages = with pkgs; [
    vim
    xterm
    raspberrypifw
    usbutils
    ppp
    python311
    gpio-utils
    libgpiod
    networkmanager

    modemmanager
    mobile-broadband-provider-info
    usb-modeswitch
    usb-modeswitch-data
  ];

  time.timeZone = "Australia/Adelaide";

  ### Networking Configuration ###
  networking.hostName = "nixos-dev";
  systemd.services.ModemManager = {
    enable = lib.mkForce true;
  };
  networking.networkmanager = {
    enable = true;

    ensureProfiles.profiles = {
      Cellular = {
        connection = {
          id = "Cellular";
          uuid = "c57dc1eb-5145-4d09-b0cf-281bb039936a";
          type = "gsm";
          interface-name = "cdc-wdm0";
        };
        gsm = {
          apn = "telstra.internet";

          # username and password are not needed for the Telstra network.
          #username = "";
          #password = "";
        };
        ipv4 = {
          method = "auto";
        };
        ipv6 = {
          addr-gen-mode = "default";
          method = "auto";
        };
      };
    };
  };

  services.xserver = {
    enable = false;
    displayManager.gdm.enable = false;
    desktopManager.gnome.enable = false;
  };

  nix.settings.experimental-features = [ "nix-command" "flakes" ];
  system.stateVersion = "23.11";
}

However, a potential workaround exists by specifying ModemManager as being wantedBy network.target, as well as its default multi-user.target:

systemd.services.ModemManager = {
    enable = lib.mkForce true;
    wantedBy = [ "multi-user.target" "network.target" ];
  };

Steps To Reproduce

Steps to reproduce the behavior:

  1. List modemmanager as a system package
  2. Observe modemmanager.service does not start
  3. Observe no change when attempting to force start it by specifying systemd.services.ModemManager.enable = true or lib.mkForce true

Expected behavior

ModemManager.service should start automatically if its specified as a system package.

Notify maintainers

(Had to look through git log, sorry if you are not an active maintainers)

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: `"aarch64-linux"`
 - host os: `Linux 6.6.2, NixOS, 23.11 (Tapir), 23.11.20231128.31b865a`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.1`
 - channels(root): `"nixos-23.11-small, nixos-hardware"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

Priorities

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

tavimori commented 8 months ago

Hi, I have the same problem, and your workaround works for me. However, I found that when adopting your workaround, the ModemManager does start but doesn't load the fccUnlockScript correctly.

I have configured the "networking.networkmanager.fccUnlockScripts" setting accordingly. When I stop the service and manually run ModemManager after login into the system, I can see the fccUnlock is performed correctly. (Perhaps there is something wrong with the service config?)

My current config in /etc/nixos/configuration.nix:

# Enable networking
  networking.networkmanager.enable = true;
  networking.networkmanager.fccUnlockScripts = [
    {
      id = "105b:e0ab";
      path = "${pkgs.modemmanager}/share/ModemManager/fcc-unlock.available.d/105b:e0ab";
    }
  ];

  systemd.services.ModemManager = {
    enable = lib.mkForce true;
    wantedBy = [ "multi-user.target" "network.target" ];
  };

Metadata

[root@nixos:/etc/nixos]# nix-shell -p nix-info --run "nix-info -m"
 - system: "x86_64-linux"
 - host os: Linux 6.1.69, NixOS, 23.11 (Tapir), 23.11.20231225.d02d818
 - multi-user?: yes
 - sandbox: yes
 - version: nix-env (Nix) 2.18.1
 - channels(root): "home-manager, nixos-23.11"
 - nixpkgs: /nix/var/nix/profiles/per-user/root/channels/nixos
tavimori commented 8 months ago

I found that in my case, the ModemManager fails to execute the fcc-unlock-script because the unlock script of 105b:e0ab device uses qmi interfaces and require PATH of libqmi to be added to the service.

The following service config works in my setup:

  systemd.services.ModemManager = {
    enable = lib.mkForce true;
    path = [ pkgs.libqmi ]; # required by fcc-unlock-script of 105b:e0ab
    wantedBy = [ "multi-user.target" "network.target" ];
  };
brianmay commented 1 day ago

I have a similar issue with the unlock script not being run. If I run ModemManager manually it works. I tried the above work around to set the path, but it does not help.

My unlock script, which I found somewhere, has the following at the top:

#!/run/current-system/sw/bin/bash

# SPDX-License-Identifier: CC0-1.0
# 2023 Thilo-Alexander Ginkel <thilo@ginkel.com>
#
# Lenovo-shipped Fibocom FM350-GL (14c3:4d75) FCC unlock

if [[ "$FCC_UNLOCK_DEBUG_LOG" == '1' ]]; then
    exec 3>&1 4>&2
    trap 'exec 2>&4 1>&3' 0 1 2 3
    exec 1>>/var/log/mm-fm350-fcc.log 2>&1
fi

To debug this I had to enable logging, which meant setting FCC_UNLOCK_DEBUG_LOG.

I am not sure the proper way to set this, so I just modified the script with:

FCC_UNLOCK_DEBUG_LOG=1
brianmay commented 1 day ago

Think I worked out it, my unlock script required some more paths:

path = [pkgs.libqmi pkgs.gawk pkgs.xxd];

Suspect mine doesn't require libqmi actually, but can't hurt.