1 { config, lib, pkgs, ... }:
4 defaultUserGroup = "usbmux";
7 cfg = config.services.usbmuxd;
12 options.services.usbmuxd = {
14 enable = lib.mkOption {
15 type = lib.types.bool;
18 Enable the usbmuxd ("USB multiplexing daemon") service. This daemon is
19 in charge of multiplexing connections over USB to an iOS device. This is
20 needed for transferring data from and to iOS devices (see ifuse). Also
21 this may enable plug-n-play tethering for iPhones.
27 default = defaultUserGroup;
29 The user usbmuxd should use to run after startup.
33 group = lib.mkOption {
35 default = defaultUserGroup;
37 The group usbmuxd should use to run after startup.
41 package = lib.mkOption {
42 type = lib.types.package;
43 default = pkgs.usbmuxd;
44 defaultText = lib.literalExpression "pkgs.usbmuxd";
45 description = "Which package to use for the usbmuxd daemon.";
46 relatedPackages = [ "usbmuxd" "usbmuxd2" ];
51 config = lib.mkIf cfg.enable {
53 users.users = lib.optionalAttrs (cfg.user == defaultUserGroup) {
55 description = "usbmuxd user";
61 users.groups = lib.optionalAttrs (cfg.group == defaultUserGroup) {
65 # Give usbmuxd permission for Apple devices
66 services.udev.extraRules = ''
67 SUBSYSTEM=="usb", ATTR{idVendor}=="${apple}", GROUP="${cfg.group}"
70 systemd.services.usbmuxd = {
71 description = "usbmuxd";
72 wantedBy = [ "multi-user.target" ];
73 unitConfig.Documentation = "man:usbmuxd(8)";
75 # Trigger the udev rule manually. This doesn't require replugging the
76 # device when first enabling the option to get it to work
77 ExecStartPre = "${config.systemd.package}/bin/udevadm trigger -s usb -a idVendor=${apple}";
78 ExecStart = "${cfg.package}/bin/usbmuxd -U ${cfg.user} -v";