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:
commit
abd360b206
@ -43,6 +43,9 @@
|
||||
|
||||
# This device adds skip_initramfs to cmdline for normal boots
|
||||
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";
|
||||
gadgetfs.functions = {
|
||||
|
@ -1,6 +1,8 @@
|
||||
{ config, pkgs, lib, modules, baseModules, ... }:
|
||||
|
||||
let
|
||||
inherit (lib) optionalString;
|
||||
|
||||
# In the future, this pattern should be extracted.
|
||||
# We're basically subclassing the main config, just like nesting does in
|
||||
# NixOS (<nixpkgs/modules/system/activation/top-level.nix>)
|
||||
@ -15,6 +17,22 @@ let
|
||||
}];
|
||||
}).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_name = device_config.name;
|
||||
enabled = config.mobile.system.type == "android";
|
||||
@ -32,11 +50,30 @@ let
|
||||
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}" {} ''
|
||||
mkdir -p $out
|
||||
ln -s ${rootfs}/${rootfs.filename} $out/system.img
|
||||
ln -s ${android-bootimg} $out/boot.img
|
||||
ln -s ${android-recovery} $out/recovery.img
|
||||
cp -v ${rootfs}/${rootfs.filename} $out/system.img
|
||||
cp -v ${android-bootimg} $out/boot.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
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user