at 25.11-pre 2.7 kB view raw
1{ 2 config, 3 lib, 4 pkgs, 5 ... 6}: 7let 8 cfg = config.networking.modemmanager; 9in 10{ 11 meta = { 12 maintainers = lib.teams.freedesktop.members; 13 }; 14 15 options = with lib; { 16 networking.modemmanager = { 17 enable = mkOption { 18 type = types.bool; 19 default = false; 20 description = '' 21 Whether to use ModemManager to manage modem devices. 22 This is usually used by some higher layer manager such as NetworkManager 23 but can be used standalone especially if using a modem for non-IP 24 connectivity (e.g. GPS). 25 ''; 26 }; 27 28 package = mkPackageOption pkgs "modemmanager" { }; 29 30 fccUnlockScripts = mkOption { 31 type = types.listOf ( 32 types.submodule { 33 options = { 34 id = mkOption { 35 type = types.str; 36 description = "vid:pid of either the PCI or USB vendor and product ID"; 37 }; 38 path = mkOption { 39 type = types.path; 40 description = "Path to the unlock script"; 41 }; 42 }; 43 } 44 ); 45 default = [ ]; 46 example = literalExpression ''[{ id = "03f0:4e1d"; path = "''${pkgs.modemmanager}/share/ModemManager/fcc-unlock.available.d/03f0:4e1d"; }]''; 47 description = '' 48 List of FCC unlock scripts to enable on the system, behaving as described in 49 https://modemmanager.org/docs/modemmanager/fcc-unlock/#integration-with-third-party-fcc-unlock-tools. 50 ''; 51 }; 52 }; 53 }; 54 55 config = lib.mkIf cfg.enable { 56 environment.etc = builtins.listToAttrs ( 57 map ( 58 e: 59 lib.nameValuePair "ModemManager/fcc-unlock.d/${e.id}" { 60 source = e.path; 61 } 62 ) cfg.fccUnlockScripts 63 ); 64 65 systemd.services.ModemManager = { 66 aliases = [ "dbus-org.freedesktop.ModemManager1.service" ]; 67 path = lib.optionals (cfg.fccUnlockScripts != [ ]) [ 68 pkgs.libqmi 69 pkgs.libmbim 70 ]; 71 }; 72 73 /* 74 [modem-manager] 75 Identity=unix-group:networkmanager 76 Action=org.freedesktop.ModemManager* 77 ResultAny=yes 78 ResultInactive=no 79 ResultActive=yes 80 */ 81 security.polkit.enable = true; 82 security.polkit.extraConfig = '' 83 polkit.addRule(function(action, subject) { 84 if ( 85 subject.isInGroup("networkmanager") 86 && action.id.indexOf("org.freedesktop.ModemManager") == 0 87 ) 88 { return polkit.Result.YES; } 89 }); 90 ''; 91 92 environment.systemPackages = [ cfg.package ]; 93 systemd.packages = [ cfg.package ]; 94 services.dbus.packages = [ cfg.package ]; 95 services.udev.packages = [ cfg.package ]; 96 }; 97}