···23with lib;
40000000005{
6- options.services.usbmuxd.enable = mkOption {
7- type = types.bool;
8- default = false;
9- description = ''
10- Enable the usbmuxd ("USB multiplexing daemon") service. This daemon is in
11- charge of multiplexing connections over USB to an iOS device. This is
12- needed for transferring data from and to iOS devices (see ifuse). Also
13- this may enable plug-n-play tethering for iPhones.
00000000000000000000000000000000000014 '';
15- };
1617- config = mkIf config.services.usbmuxd.enable {
18 systemd.services.usbmuxd = {
19 description = "usbmuxd";
20 wantedBy = [ "multi-user.target" ];
21 unitConfig.Documentation = "man:usbmuxd(8)";
22- serviceConfig.ExecStart = "${pkgs.usbmuxd}/bin/usbmuxd -f";
0000023 };
024 };
25}
···23with lib;
45+let
6+7+ defaultUserGroup = "usbmux";
8+ apple = "05ac";
9+10+ cfg = config.services.usbmuxd;
11+12+in
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 '';
060061 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}