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