1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7{
8 ###### interface
9
10 options = {
11
12 hardware.usb-modeswitch = {
13 enable = lib.mkOption {
14 type = lib.types.bool;
15 default = false;
16 description = ''
17 Enable this option to support certain USB WLAN and WWAN adapters.
18
19 These network adapters initial present themselves as Flash Drives containing their drivers.
20 This option enables automatic switching to the networking mode.
21 '';
22 };
23 };
24 };
25
26 ###### implementation
27
28 imports = [
29 (lib.mkRenamedOptionModule [ "hardware" "usbWwan" ] [ "hardware" "usb-modeswitch" ])
30 ];
31
32 config = lib.mkIf config.hardware.usb-modeswitch.enable {
33 # Attaches device specific handlers.
34 services.udev.packages = with pkgs; [ usb-modeswitch-data ];
35
36 # Triggered by udev, usb-modeswitch creates systemd services via a
37 # template unit in the usb-modeswitch package.
38 systemd.packages = with pkgs; [ usb-modeswitch ];
39
40 # The systemd service requires the usb-modeswitch-data. The
41 # usb-modeswitch package intends to discover this via the
42 # filesystem at /usr/share/usb_modeswitch, and merge it with user
43 # configuration in /etc/usb_modeswitch.d. Configuring the correct
44 # path in the package is difficult, as it would cause a cyclic
45 # dependency.
46 environment.etc."usb_modeswitch.d".source = "${pkgs.usb-modeswitch-data}/share/usb_modeswitch";
47 };
48}