at 25.11-pre 2.3 kB view raw
1{ 2 config, 3 lib, 4 pkgs, 5 ... 6}: 7let 8 9 defaultUserGroup = "usbmux"; 10 apple = "05ac"; 11 12 cfg = config.services.usbmuxd; 13 14in 15 16{ 17 options.services.usbmuxd = { 18 19 enable = lib.mkOption { 20 type = lib.types.bool; 21 default = false; 22 description = '' 23 Enable the usbmuxd ("USB multiplexing daemon") service. This daemon is 24 in charge of multiplexing connections over USB to an iOS device. This is 25 needed for transferring data from and to iOS devices (see ifuse). Also 26 this may enable plug-n-play tethering for iPhones. 27 ''; 28 }; 29 30 user = lib.mkOption { 31 type = lib.types.str; 32 default = defaultUserGroup; 33 description = '' 34 The user usbmuxd should use to run after startup. 35 ''; 36 }; 37 38 group = lib.mkOption { 39 type = lib.types.str; 40 default = defaultUserGroup; 41 description = '' 42 The group usbmuxd should use to run after startup. 43 ''; 44 }; 45 46 package = lib.mkOption { 47 type = lib.types.package; 48 default = pkgs.usbmuxd; 49 defaultText = lib.literalExpression "pkgs.usbmuxd"; 50 description = "Which package to use for the usbmuxd daemon."; 51 relatedPackages = [ 52 "usbmuxd" 53 "usbmuxd2" 54 ]; 55 }; 56 57 }; 58 59 config = lib.mkIf cfg.enable { 60 61 users.users = lib.optionalAttrs (cfg.user == defaultUserGroup) { 62 ${cfg.user} = { 63 description = "usbmuxd user"; 64 group = cfg.group; 65 isSystemUser = true; 66 }; 67 }; 68 69 users.groups = lib.optionalAttrs (cfg.group == defaultUserGroup) { 70 ${cfg.group} = { }; 71 }; 72 73 # Give usbmuxd permission for Apple devices 74 services.udev.extraRules = '' 75 SUBSYSTEM=="usb", ATTR{idVendor}=="${apple}", GROUP="${cfg.group}" 76 ''; 77 78 systemd.services.usbmuxd = { 79 description = "usbmuxd"; 80 wantedBy = [ "multi-user.target" ]; 81 unitConfig.Documentation = "man:usbmuxd(8)"; 82 serviceConfig = { 83 # Trigger the udev rule manually. This doesn't require replugging the 84 # device when first enabling the option to get it to work 85 ExecStartPre = "${config.systemd.package}/bin/udevadm trigger -s usb -a idVendor=${apple}"; 86 ExecStart = "${cfg.package}/bin/usbmuxd -U ${cfg.user} -v"; 87 }; 88 }; 89 90 }; 91}