···2233with lib;
4455+let
66+77+ defaultUserGroup = "usbmux";
88+ apple = "05ac";
99+1010+ cfg = config.services.usbmuxd;
1111+1212+in
1313+514{
66- options.services.usbmuxd.enable = mkOption {
77- type = types.bool;
88- default = false;
99- description = ''
1010- Enable the usbmuxd ("USB multiplexing daemon") service. This daemon is in
1111- charge of multiplexing connections over USB to an iOS device. This is
1212- needed for transferring data from and to iOS devices (see ifuse). Also
1313- this may enable plug-n-play tethering for iPhones.
1515+ options.services.usbmuxd = {
1616+ enable = mkOption {
1717+ type = types.bool;
1818+ default = false;
1919+ description = ''
2020+ Enable the usbmuxd ("USB multiplexing daemon") service. This daemon is
2121+ in charge of multiplexing connections over USB to an iOS device. This is
2222+ needed for transferring data from and to iOS devices (see ifuse). Also
2323+ this may enable plug-n-play tethering for iPhones.
2424+ '';
2525+ };
2626+2727+ user = mkOption {
2828+ type = types.str;
2929+ default = defaultUserGroup;
3030+ description = ''
3131+ The user usbmuxd should use to run after startup.
3232+ '';
3333+ };
3434+3535+ group = mkOption {
3636+ type = types.str;
3737+ default = defaultUserGroup;
3838+ description = ''
3939+ The group usbmuxd should use to run after startup.
4040+ '';
4141+ };
4242+ };
4343+4444+ config = mkIf cfg.enable {
4545+4646+ users.extraUsers = optional (cfg.user == defaultUserGroup) {
4747+ name = cfg.user;
4848+ description = "usbmuxd user";
4949+ group = cfg.group;
5050+ };
5151+5252+ users.extraGroups = optional (cfg.group == defaultUserGroup) {
5353+ name = cfg.group;
5454+ };
5555+5656+ # Give usbmuxd permission for Apple devices
5757+ services.udev.extraRules = ''
5858+ SUBSYSTEM=="usb", ATTR{idVendor}=="${apple}", GROUP="${cfg.group}"
1459 '';
1515- };
16601717- config = mkIf config.services.usbmuxd.enable {
1861 systemd.services.usbmuxd = {
1962 description = "usbmuxd";
2063 wantedBy = [ "multi-user.target" ];
2164 unitConfig.Documentation = "man:usbmuxd(8)";
2222- serviceConfig.ExecStart = "${pkgs.usbmuxd}/bin/usbmuxd -f";
6565+ serviceConfig = {
6666+ # Trigger the udev rule manually. This doesn't require replugging the
6767+ # device when first enabling the option to get it to work
6868+ ExecStartPre = "${pkgs.libudev}/bin/udevadm trigger -s usb -a idVendor=${apple}";
6969+ ExecStart = "${pkgs.usbmuxd}/bin/usbmuxd -U ${cfg.user} -f";
7070+ };
2371 };
7272+2473 };
2574}