2017-10-17 16:55:57 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
2017-10-18 20:21:29 +00:00
|
|
|
let
|
|
|
|
|
|
|
|
defaultUserGroup = "usbmux";
|
|
|
|
apple = "05ac";
|
|
|
|
|
|
|
|
cfg = config.services.usbmuxd;
|
|
|
|
|
|
|
|
in
|
|
|
|
|
2017-10-17 16:55:57 +00:00
|
|
|
{
|
2017-10-18 20:21:29 +00:00
|
|
|
options.services.usbmuxd = {
|
2022-12-07 09:58:55 +00:00
|
|
|
|
2017-10-18 20:21:29 +00:00
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
Enable the usbmuxd ("USB multiplexing daemon") service. This daemon is
|
|
|
|
in charge of multiplexing connections over USB to an iOS device. This is
|
|
|
|
needed for transferring data from and to iOS devices (see ifuse). Also
|
|
|
|
this may enable plug-n-play tethering for iPhones.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = defaultUserGroup;
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
The user usbmuxd should use to run after startup.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = defaultUserGroup;
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
The group usbmuxd should use to run after startup.
|
|
|
|
'';
|
|
|
|
};
|
2022-12-07 09:58:55 +00:00
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.usbmuxd;
|
|
|
|
defaultText = literalExpression "pkgs.usbmuxd";
|
|
|
|
description = lib.mdDoc "Which package to use for the usbmuxd daemon.";
|
|
|
|
relatedPackages = [ "usbmuxd" "usbmuxd2" ];
|
|
|
|
};
|
|
|
|
|
2017-10-17 16:55:57 +00:00
|
|
|
};
|
|
|
|
|
2017-10-18 20:21:29 +00:00
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2019-09-14 17:51:29 +00:00
|
|
|
users.users = optionalAttrs (cfg.user == defaultUserGroup) {
|
|
|
|
${cfg.user} = {
|
|
|
|
description = "usbmuxd user";
|
|
|
|
group = cfg.group;
|
|
|
|
isSystemUser = true;
|
|
|
|
};
|
2017-10-18 20:21:29 +00:00
|
|
|
};
|
|
|
|
|
2020-01-12 15:53:27 +00:00
|
|
|
users.groups = optionalAttrs (cfg.group == defaultUserGroup) {
|
2019-09-14 17:51:29 +00:00
|
|
|
${cfg.group} = { };
|
2017-10-18 20:21:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
# Give usbmuxd permission for Apple devices
|
|
|
|
services.udev.extraRules = ''
|
|
|
|
SUBSYSTEM=="usb", ATTR{idVendor}=="${apple}", GROUP="${cfg.group}"
|
|
|
|
'';
|
|
|
|
|
2017-10-17 16:55:57 +00:00
|
|
|
systemd.services.usbmuxd = {
|
|
|
|
description = "usbmuxd";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
unitConfig.Documentation = "man:usbmuxd(8)";
|
2017-10-18 20:21:29 +00:00
|
|
|
serviceConfig = {
|
|
|
|
# Trigger the udev rule manually. This doesn't require replugging the
|
|
|
|
# device when first enabling the option to get it to work
|
2023-11-21 14:09:31 +00:00
|
|
|
ExecStartPre = "${config.systemd.package}/bin/udevadm trigger -s usb -a idVendor=${apple}";
|
2022-12-07 09:58:55 +00:00
|
|
|
ExecStart = "${cfg.package}/bin/usbmuxd -U ${cfg.user} -v";
|
2017-10-18 20:21:29 +00:00
|
|
|
};
|
2017-10-17 16:55:57 +00:00
|
|
|
};
|
2017-10-18 20:21:29 +00:00
|
|
|
|
2017-10-17 16:55:57 +00:00
|
|
|
};
|
|
|
|
}
|