1
1
mirror of https://github.com/NixOS/mobile-nixos.git synced 2024-12-15 19:23:01 +03:00

Merge pull request #87 from samueldr-wip/feature/installer-script

Add installer script to android device output
This commit is contained in:
Samuel Dionne-Riel 2020-03-02 14:03:21 -05:00 committed by GitHub
commit abd360b206
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 3 deletions

View File

@ -43,6 +43,9 @@
# This device adds skip_initramfs to cmdline for normal boots # This device adds skip_initramfs to cmdline for normal boots
boot_as_recovery = true; boot_as_recovery = true;
# Though this device has "boot_as_recovery", it still has a classic
# recovery partition for recovery. Go figure.
has_recovery_partition = true;
vendor_partition = "/dev/disk/by-partlabel/vendor"; vendor_partition = "/dev/disk/by-partlabel/vendor";
gadgetfs.functions = { gadgetfs.functions = {

View File

@ -1,6 +1,8 @@
{ config, pkgs, lib, modules, baseModules, ... }: { config, pkgs, lib, modules, baseModules, ... }:
let let
inherit (lib) optionalString;
# In the future, this pattern should be extracted. # In the future, this pattern should be extracted.
# We're basically subclassing the main config, just like nesting does in # We're basically subclassing the main config, just like nesting does in
# NixOS (<nixpkgs/modules/system/activation/top-level.nix>) # NixOS (<nixpkgs/modules/system/activation/top-level.nix>)
@ -15,6 +17,22 @@ let
}]; }];
}).config; }).config;
withRecovery = let
inherit (device_config) info;
withBootAsRecovery = if info ? boot_as_recovery then info.boot_as_recovery else false;
in
# As defined... Some devices will have a discrete recovery partition even
# if the system is "boot as recovery".
if info ? has_recovery_partition
then info.has_recovery_partition
# Defaults: with 'boot as recovery' → no recovery ; without 'boot as recovery' → with recovery
else !withBootAsRecovery
;
withAB = let inherit (device_config) info; in
if info ? ab_partitions then info.ab_partitions else false
;
device_config = config.mobile.device; device_config = config.mobile.device;
device_name = device_config.name; device_name = device_config.name;
enabled = config.mobile.system.type == "android"; enabled = config.mobile.system.type == "android";
@ -32,11 +50,30 @@ let
initrd = config.system.build.initrd; initrd = config.system.build.initrd;
}; };
# Note:
# The flash scripts, by design, are not using nix-provided paths for
# either of fastboot or the outputs.
# This is because this output should have no refs. A simple tarball of this
# output should be usable even on systems without Nix.
# TODO: Embed device-specific fastboot instructions as `echo` in the script.
android-device = pkgs.runCommandNoCC "android-device-${device_name}" {} '' android-device = pkgs.runCommandNoCC "android-device-${device_name}" {} ''
mkdir -p $out mkdir -p $out
ln -s ${rootfs}/${rootfs.filename} $out/system.img cp -v ${rootfs}/${rootfs.filename} $out/system.img
ln -s ${android-bootimg} $out/boot.img cp -v ${android-bootimg} $out/boot.img
ln -s ${android-recovery} $out/recovery.img ${optionalString withRecovery ''
cp -v ${android-recovery} $out/recovery.img
''}
cat > $out/flash-critical.sh <<'EOF'
#!/usr/bin/env bash
dir="$(cd "$(dirname "''${BASH_SOURCE[0]}")"; echo "$PWD")"
PS4=" $ "
set -x
fastboot flash ${optionalString withAB "--slot=all"} boot "$dir"/boot.img
${optionalString withRecovery ''
fastboot flash ${optionalString withAB "--slot=all"} recovery "$dir"/recovery.img
''}
EOF
chmod +x $out/flash-critical.sh
''; '';
in in
{ {