2018-07-08 03:22:39 +03:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
2020-01-12 23:49:02 +03:00
|
|
|
device_info = config.mobile.device.info;
|
2018-07-08 03:22:39 +03:00
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2020-01-12 23:49:02 +03:00
|
|
|
options.mobile.usb = {
|
|
|
|
idVendor = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = ''
|
|
|
|
USB vendor ID for the USB gadget.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
idProduct = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = ''
|
|
|
|
USB product ID for the USB gadget.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2018-07-08 03:22:39 +03:00
|
|
|
|
2020-01-12 00:11:05 +03:00
|
|
|
config = lib.mkIf cfg.usb.enable {
|
|
|
|
boot.specialFileSystems = {
|
|
|
|
# This is required for gadgetfs configuration.
|
|
|
|
"/sys/kernel/config" = {
|
|
|
|
# FIXME: remove once added to <nixpkgs/nixos/modules/tasks/filesystems.nix> specialFSTypes
|
|
|
|
device = "configfs";
|
|
|
|
fsType = "configfs";
|
|
|
|
options = [ "nosuid" "noexec" "nodev" ];
|
|
|
|
};
|
|
|
|
};
|
2019-09-24 03:31:56 +03:00
|
|
|
|
2020-01-12 00:11:05 +03:00
|
|
|
mobile.boot.stage-1 = lib.mkIf cfg.usb.enable {
|
|
|
|
kernel.modules = [
|
|
|
|
"configfs"
|
|
|
|
];
|
2019-09-24 03:31:56 +03:00
|
|
|
|
2020-01-12 00:11:05 +03:00
|
|
|
usb.features = []
|
|
|
|
++ optional cfg.networking.enable "rndis"
|
|
|
|
;
|
|
|
|
tasks = [
|
2020-01-12 23:49:02 +03:00
|
|
|
./stage-1/tasks/usb-gadget-task.rb
|
2020-01-12 00:11:05 +03:00
|
|
|
];
|
|
|
|
bootConfig = {
|
|
|
|
boot.usb.features = cfg.usb.features;
|
2020-01-13 22:55:47 +03:00
|
|
|
boot.usb.functions = mkIf (device_info ? gadgetfs) (builtins.listToAttrs (
|
2020-01-12 23:49:02 +03:00
|
|
|
builtins.map (feature: { name = feature; value = device_info.gadgetfs.functions."${feature}"; }) cfg.usb.features
|
2020-01-13 22:55:47 +03:00
|
|
|
));
|
2020-01-12 23:49:02 +03:00
|
|
|
usb = {
|
|
|
|
inherit (config.mobile.usb) idVendor idProduct;
|
|
|
|
};
|
2020-01-12 00:11:05 +03:00
|
|
|
};
|
|
|
|
};
|
2018-07-08 03:22:39 +03:00
|
|
|
};
|
|
|
|
}
|