Compare commits

...

2 Commits

Author SHA1 Message Date
d511a82b0c Add command for flashing postmarketOS 2024-12-27 10:48:04 +01:00
5d7cec46e9 Add scripts for flashing lineage 2024-12-26 20:21:05 +01:00
4 changed files with 81 additions and 15 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@
/flashing/
/debug/
/tools/
/.cache/

View File

@ -4,13 +4,78 @@
pkgs,
...
}: {
devShells.default = pkgs.mkShell {
packages = with pkgs; [
android-tools
(python3.withPackages (pypi: with pypi; [
libfdt
]))
];
};
devShells.default =
let
lineageBuildZipUrl = "https://mirrorbits.lineageos.org/full/a71/20241225/lineage-21.0-20241225-nightly-a71-signed.zip";
lineageBuildZip = pkgs.fetchurl {
url = lineageBuildZipUrl;
hash = "sha256-G+ibXe1crfhFnB2sfSKtI4XDx1qysMj75H7aTJcUUm0=";
};
lineageBuildZipContent = pkgs.fetchzip {
url = lineageBuildZipUrl;
hash = "sha256-nBn26btXmW5u1oYCqucAbk6ixzMxGNapuMofBisv56o=";
stripRoot = false;
};
magiskApk = pkgs.fetchurl {
url = "https://github.com/topjohnwu/Magisk/releases/download/v28.1/Magisk-v28.1.apk";
hash = "sha256-i/0zRrPaWBT4Lv9vGxtf7dCtWF85olcJsj61SqxFaR0=";
};
emptyDtbo = pkgs.runCommand "empty-dtbo" {} ''
mkdir $out
dd if=/dev/zero of=$out/empty_dtbo.img count=1
${pkgs.android-tools}/bin/avbtool add_hash_footer --partition_name dtbo --partition_size 2621440 --image $out/empty_dtbo.img
'';
# rootDir = builtins.toString ./..;
in
pkgs.mkShell {
packages = with pkgs; [
(python3.withPackages (pypi: with pypi; [
libfdt
]))
(writeShellScriptBin "flash-lineage-magisk" ''
rootDir="." # Assume PWD as root for now
lineageBootImg="$rootDir/.cache/lineageos-magisk-boot.img"
if [[ ! -e "$lineageBootImg" ]]; then
echo "Wait for Android to have fully booted and ensure USB debugging is enabled."
read -p "Press enter to continue..."
mkdir -p "$rootDir/.cache"
installedMagisk=$(adb shell pm list packages com.topjohnwu.magisk)
if [[ -z "$installedMagisk" ]]; then
echo "Magisk not found on device. Installing now..."
adb sideload "${magiskApk}"
fi
adb push "${lineageBuildZipContent}/boot.img" "/storage/emulated/0/Download/lineageos-boot.img"
echo "Launching Magisk. Patch the boot image located in the downloads directory."
adb shell monkey -p com.topjohnwu.magisk 1
read -p "Press enter to continue..."
adb shell 'cp /storage/emulated/0/Download/magisk_patched*.img /storage/emulated/0/Download/magisk-boot.img'
sleep 1
adb shell 'rm /storage/emulated/0/Download/magisk_patched*.img'
adb pull "/storage/emulated/0/Download/magisk-boot.img" "$lineageBootImg"
fi
echo "Boot into download mode."
read -p "Press enter to continue..."
heimdall flash --BOOT "$lineageBootImg"
'')
(writeShellScriptBin "flash-lineage" ''
echo "Installing LineageOS..."
adb sideload ${lineageBuildZip}
flash-lineage-magisk
'')
(writeShellScriptBin "flash-postmarketos" ''
echo "Installing postmarketOS..."
heimdall flash \
--no-reboot \
--DTBO ${emptyDtbo}/empty_dtbo.img
pmbootstrap flasher --method heimdall-bootimg --resume flash_kernel
'')
];
};
};
}

View File

@ -20,16 +20,16 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1733759999,
"narHash": "sha256-463SNPWmz46iLzJKRzO3Q2b0Aurff3U1n0nYItxq7jU=",
"owner": "nixos",
"lastModified": 1734991663,
"narHash": "sha256-8T660guvdaOD+2/Cj970bWlQwAyZLKrrbkhYOFcY1YE=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "a73246e2eef4c6ed172979932bc80e1404ba2d56",
"rev": "6c90912761c43e22b6fb000025ab96dd31c971ff",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"owner": "NixOS",
"ref": "nixos-24.11",
"repo": "nixpkgs",
"type": "github"
}

View File

@ -2,7 +2,7 @@
description = "A very basic flake";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
flake-parts.url = "github:hercules-ci/flake-parts";
};