306 lines
11 KiB
Nix
306 lines
11 KiB
Nix
{ inputs, ... }:
|
|
{
|
|
perSystem = {
|
|
config,
|
|
pkgs,
|
|
...
|
|
}: {
|
|
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 ./..;
|
|
rootDir = "."; # Assume PWD as root for now
|
|
|
|
android-toolchain = pkgs.fetchGit {
|
|
url = "";
|
|
rev = "main";
|
|
};
|
|
android-fhs = pkgs.buildFHSUserEnv {
|
|
name = "android-env";
|
|
targetPkgs = pkgs: with pkgs; [
|
|
android-tools
|
|
libxcrypt-legacy # libcrypt.so.1
|
|
freetype # libfreetype.so.6
|
|
fontconfig # java NPE: "sun.awt.FontConfiguration.head" is null
|
|
yaml-cpp # necessary for some kernels according to a comment on the gist
|
|
|
|
# Some of the packages here are probably unecessary but I don't wanna figure out which
|
|
bc
|
|
binutils
|
|
bison
|
|
ccache
|
|
curl
|
|
flex
|
|
gcc
|
|
git
|
|
git-repo
|
|
git-lfs
|
|
gnumake
|
|
gnupg
|
|
gperf
|
|
imagemagick
|
|
jdk11
|
|
elfutils
|
|
libxml2
|
|
libxslt
|
|
lz4
|
|
lzop
|
|
m4
|
|
nettools
|
|
openssl.dev
|
|
perl
|
|
pngcrush
|
|
procps
|
|
python3
|
|
rsync
|
|
schedtool
|
|
SDL
|
|
squashfsTools
|
|
unzip
|
|
util-linux
|
|
xml2
|
|
zip
|
|
|
|
# only necessary if you wanna use `runScript = "zsh";` below
|
|
zsh
|
|
];
|
|
multiPkgs = pkgs: with pkgs; [
|
|
zlib
|
|
ncurses5
|
|
libcxx
|
|
readline
|
|
|
|
libgcc # crtbeginS.o
|
|
iconv # ??? - i put this here and by the time i went back to remove unecessary packages i forgot why
|
|
iconv.dev # sys/types.h
|
|
];
|
|
runScript = "bash";
|
|
profile = ''
|
|
export ALLOW_NINJA_ENV=true
|
|
export USE_CCACHE=1
|
|
export CCACHE_EXEC=/usr/bin/ccache
|
|
export ANDROID_JAVA_HOME=${pkgs.jdk11.home}
|
|
# Building involves a phase of unzipping large files into a temporary directory
|
|
export TMPDIR=/tmp
|
|
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${pkgs.ncurses5}/lib
|
|
'';
|
|
};
|
|
# android-fhs-shell = pkgs.stdenv.mkDerivation {
|
|
# name = "android-env-shell";
|
|
# nativeBuildInputs = [
|
|
# android-fhs
|
|
# ];
|
|
# shellHook = "exec android-env";
|
|
# dontUnpack = true;
|
|
# };
|
|
in
|
|
pkgs.mkShell {
|
|
packages = with pkgs; [
|
|
(python3.withPackages (pypi: with pypi; [
|
|
libfdt
|
|
]))
|
|
android-fhs
|
|
|
|
(writeShellScriptBin "flash-lineage-magisk" ''
|
|
rootDir="${rootDir}"
|
|
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
|
|
# does not work for some reason
|
|
# pmbootstrap flasher --method heimdall-bootimg --resume flash_kernel
|
|
'')
|
|
(writeShellScriptBin "init-repositories" ''
|
|
rootDir="${rootDir}"
|
|
mkdir -p "$rootDir/.repos"
|
|
[[ -d "$rootDir/.repos/mainline-kernel" ]] || git clone git@github.com:WiiPlayer2/linux-sm7150.git "$rootDir/.repos/mainline-kernel"
|
|
[[ -d "$rootDir/.repos/android-kernel" ]] || git clone ssh://git@git.web.home.dark-link.info:2222/a71-pmos/android-kernel-a71.git "$rootDir/.repos/android-kernel"
|
|
'')
|
|
(writeScriptBin "build-and-flash-kernel" ''
|
|
#!/usr/bin/env bash
|
|
rootDir="${rootDir}"
|
|
pushd $rootDir/.repos/mainline-kernel
|
|
|
|
source $(pmbootstrap-envkernel) && \
|
|
( [[ -e ".output/.config" ]] || make defconfig sm7150.config ) && \
|
|
make -j$(nproc) && \
|
|
pmbootstrap build --envkernel linux-postmarketos-qcom-sm7150 && \
|
|
pmbootstrap flasher --method fastboot flash_kernel && \
|
|
fastboot reboot
|
|
|
|
popd
|
|
'')
|
|
(writeShellScriptBin "open-pmaports" "code ~/.local/var/pmbootstrap/cache_git/pmaports")
|
|
(writeShellScriptBin "build-device-package" "pmbootstrap build --force device-samsung-a715f")
|
|
(writeShellScriptBin "install-sdcard" ''
|
|
pmbootstrap install --password pw --sdcard $(realpath /dev/disk/by-id/usb-Generic-_USB3.0_CRW_-SD_201506301013-0\:1) --zap
|
|
'')
|
|
(writeShellScriptBin "build-firmware-package" "pmbootstrap build --force firmware-samsung-a715f")
|
|
(writeShellScriptBin "enable-usb-internet" ''
|
|
sudo sysctl net.ipv4.ip_forward=1
|
|
sudo iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
|
|
sudo iptables -A FORWARD -s 172.16.42.0/24 -j ACCEPT
|
|
sudo iptables -A POSTROUTING -t nat -j MASQUERADE -s 172.16.42.0/24
|
|
sudo iptables-save
|
|
'')
|
|
];
|
|
};
|
|
|
|
# https://nixos.wiki/wiki/Cross_Compiling
|
|
android =
|
|
let
|
|
outputFolder = ".out";
|
|
in
|
|
(pkgs.buildFHSUserEnv {
|
|
name = "android-fhs";
|
|
multiPkgs = pkgs: with pkgs; [
|
|
pkgsCross.aarch64-multiplatform.buildPackages.gcc
|
|
bc
|
|
openssl
|
|
openssl.dev
|
|
python3
|
|
|
|
android-tools
|
|
libxcrypt-legacy # libcrypt.so.1
|
|
freetype # libfreetype.so.6
|
|
fontconfig # java NPE: "sun.awt.FontConfiguration.head" is null
|
|
yaml-cpp # necessary for some kernels according to a comment on the gist
|
|
|
|
# Some of the packages here are probably unecessary but I don't wanna figure out which
|
|
bc
|
|
binutils
|
|
bison
|
|
ccache
|
|
curl
|
|
flex
|
|
gcc
|
|
git
|
|
git-repo
|
|
git-lfs
|
|
gnumake
|
|
gnupg
|
|
gperf
|
|
imagemagick
|
|
jdk11
|
|
elfutils
|
|
libxml2
|
|
libxslt
|
|
lz4
|
|
lzop
|
|
m4
|
|
nettools
|
|
openssl.dev
|
|
perl
|
|
pngcrush
|
|
procps
|
|
python3
|
|
rsync
|
|
schedtool
|
|
SDL
|
|
squashfsTools
|
|
unzip
|
|
util-linux
|
|
xml2
|
|
zip
|
|
|
|
zlib
|
|
ncurses5
|
|
ncurses5.dev
|
|
libcxx
|
|
readline
|
|
|
|
libgcc # crtbeginS.o
|
|
iconv # ??? - i put this here and by the time i went back to remove unecessary packages i forgot why
|
|
iconv.dev # sys/types.h
|
|
|
|
(writeShellScriptBin "clean-kernel" ''
|
|
pushd .repos/android-kernel
|
|
|
|
mkdir -p "${outputFolder}"
|
|
make O="${outputFolder}" clean
|
|
make O="${outputFolder}" mrproper
|
|
|
|
popd
|
|
'')
|
|
(writeShellScriptBin "build-kernel" ''
|
|
pushd .repos/android-kernel
|
|
|
|
mkdir -p "${outputFolder}"
|
|
make O="${outputFolder}" a71_eur_open_defconfig
|
|
make O="${outputFolder}" -j$(nproc --all)
|
|
|
|
popd
|
|
'')
|
|
(writeShellScriptBin "configure-kernel" ''
|
|
pushd .repos/android-kernel
|
|
|
|
mkdir -p "${outputFolder}"
|
|
make O="${outputFolder}" menuconfig
|
|
|
|
popd
|
|
'')
|
|
];
|
|
profile = ''
|
|
export CROSS_COMPILE=aarch64-unknown-linux-gnu-
|
|
export ARCH=arm64
|
|
export SUBARCH=arm64
|
|
'';
|
|
}).env;
|
|
};
|
|
};
|
|
}
|