lol

usbmuxd service: user and group options

+60 -11
+60 -11
nixos/modules/services/hardware/usbmuxd.nix
··· 2 2 3 3 with lib; 4 4 5 + let 6 + 7 + defaultUserGroup = "usbmux"; 8 + apple = "05ac"; 9 + 10 + cfg = config.services.usbmuxd; 11 + 12 + in 13 + 5 14 { 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. 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}" 14 59 ''; 15 - }; 16 60 17 - config = mkIf config.services.usbmuxd.enable { 18 61 systemd.services.usbmuxd = { 19 62 description = "usbmuxd"; 20 63 wantedBy = [ "multi-user.target" ]; 21 64 unitConfig.Documentation = "man:usbmuxd(8)"; 22 - serviceConfig.ExecStart = "${pkgs.usbmuxd}/bin/usbmuxd -f"; 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 + }; 23 71 }; 72 + 24 73 }; 25 74 }