2018-07-08 03:22:39 +03:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
2020-05-24 09:39:52 +03:00
|
|
|
inherit (config.mobile.usb) gadgetfs;
|
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
|
|
|
|
{
|
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
2020-01-14 02:15:13 +03:00
|
|
|
mode = mkOption {
|
|
|
|
type = types.nullOr (types.enum [ "android_usb" "gadgetfs" ]);
|
|
|
|
default = null;
|
|
|
|
description = ''
|
|
|
|
The USB gadget implementation the device uses.
|
|
|
|
'';
|
|
|
|
};
|
2020-05-24 09:39:52 +03:00
|
|
|
gadgetfs.functions = mkOption {
|
|
|
|
type = types.attrs;
|
|
|
|
description = ''
|
|
|
|
Mapping of logical gadgetfs functions to their implementation names.
|
|
|
|
'';
|
|
|
|
};
|
2020-01-12 23:49:02 +03:00
|
|
|
};
|
2018-07-08 03:22:39 +03:00
|
|
|
|
2020-01-25 00:11:58 +03:00
|
|
|
config = lib.mkIf (config.mobile.usb.mode != null && cfg.usb.enable) {
|
2020-01-12 00:11:05 +03:00
|
|
|
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-14 02:15:13 +03:00
|
|
|
mobile.boot.stage-1 = lib.mkIf (cfg.usb.enable && (config.mobile.usb.mode != null)) {
|
2020-01-12 00:11:05 +03:00
|
|
|
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-05-24 09:39:52 +03:00
|
|
|
boot.usb.functions = mkIf (config.mobile.usb.mode == "gadgetfs") (builtins.listToAttrs (
|
|
|
|
builtins.map (feature: { name = feature; value = gadgetfs.functions."${feature}"; }) cfg.usb.features
|
2020-01-13 22:55:47 +03:00
|
|
|
));
|
2020-01-12 23:49:02 +03:00
|
|
|
usb = {
|
2020-01-14 02:15:13 +03:00
|
|
|
inherit (config.mobile.usb) idVendor idProduct mode;
|
2020-01-12 23:49:02 +03:00
|
|
|
};
|
2020-01-12 00:11:05 +03:00
|
|
|
};
|
|
|
|
};
|
2018-07-08 03:22:39 +03:00
|
|
|
};
|
|
|
|
}
|