1
1
mirror of https://github.com/NixOS/mobile-nixos.git synced 2024-12-15 11:03:37 +03:00
mobile-nixos/modules/adb.nix
2019-10-28 19:11:01 +01:00

52 lines
1.2 KiB
Nix

{ config, lib, pkgs, ... }:
with lib;
with import ./initrd-order.nix;
{
options.mobile.adbd = {
enable = mkOption {
type = types.bool;
default = config.mobile.system.type == "android";
description = ''
Enables adbd on the device.
'';
};
};
config = lib.mkIf config.mobile.adbd.enable {
assertions = [
{ assertion = config.mobile.system.type == "android";
message = "adb is only available on Android";
}
{ assertion = config.mobile.boot.stage-1.usb.enable;
message = "adb requires mobile.boot.stage-1.usb.enable = true";
}
];
mobile.boot.stage-1 = {
usb.features = [ "ffs" ];
init = lib.mkOrder AFTER_DEVICE_INIT ''
(
mkdir -p /dev/usb-ffs/adb
mount -t functionfs adb /dev/usb-ffs/adb/
sleep 0.1
adbd &
)
'';
extraUtils = with pkgs; [{
package = adbd;
extraCommand = ''cp -fpv "${glibc.out}"/lib/libnss_files.so.* "$out"/lib/'';
}];
};
boot.postBootCommands = ''
# Restart adbd early during stage-2
${pkgs.procps}/bin/pkill -x adbd
${pkgs.adbd}/bin/adbd &
'';
};
}