2018-07-08 03:22:39 +03:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.mobile.boot.stage-1;
|
2019-09-24 03:31:56 +03:00
|
|
|
device_name = device_config.name;
|
|
|
|
device_config = config.mobile.device;
|
2019-09-22 05:44:44 +03:00
|
|
|
system_type = config.mobile.system.type;
|
2018-07-08 03:22:39 +03:00
|
|
|
in
|
|
|
|
{
|
|
|
|
# FIXME Generic USB gadget support to come.
|
|
|
|
options.mobile.boot.stage-1.usb = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Enables USB features.
|
|
|
|
For now, only Android-based devices are supported.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
features = mkOption {
|
2019-09-13 05:23:13 +03:00
|
|
|
type = types.listOf types.str;
|
2018-07-08 03:22:39 +03:00
|
|
|
default = [];
|
|
|
|
description = ''
|
|
|
|
`android_usb` features to enable.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config.mobile.boot.stage-1 = lib.mkIf cfg.usb.enable {
|
|
|
|
usb.features = []
|
|
|
|
++ optional cfg.networking.enable "rndis"
|
|
|
|
;
|
2019-09-24 03:31:56 +03:00
|
|
|
|
2018-07-08 03:22:39 +03:00
|
|
|
# TODO: Only run, when we have the android usb driver
|
|
|
|
init = lib.mkOrder AFTER_DEVICE_INIT ''
|
|
|
|
# Setting up Android-specific USB.
|
2018-07-11 21:44:39 +03:00
|
|
|
(
|
2018-07-08 03:22:39 +03:00
|
|
|
SYS=/sys/class/android_usb/android0
|
2018-07-11 21:44:39 +03:00
|
|
|
if [ -e "$SYS" ]; then
|
|
|
|
printf "%s" "0" > "$SYS/enable"
|
|
|
|
printf "%s" "18D1" > "$SYS/idVendor"
|
|
|
|
printf "%s" "D001" > "$SYS/idProduct"
|
2018-11-06 06:50:08 +03:00
|
|
|
printf "%s" "0" > "$SYS/bDeviceClass"
|
2019-09-24 03:31:56 +03:00
|
|
|
printf "%s" "${concatStringsSep "," cfg.usb.features}" > "$SYS/functions"
|
|
|
|
printf "%s" "mobile-nixos" > "$SYS/iManufacturer"
|
|
|
|
printf "%s" "${device_name}" > "$SYS/iProduct"
|
|
|
|
printf "%s" "0123456789" > "$SYS/iSerial"
|
|
|
|
|
|
|
|
sleep 0.1
|
2018-07-11 21:44:39 +03:00
|
|
|
printf "%s" "1" > "$SYS/enable"
|
|
|
|
fi
|
|
|
|
)
|
2018-07-08 03:22:39 +03:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|