From 8b0f5ca6ff81f675614a07385e0aace9e66a1cdb Mon Sep 17 00:00:00 2001 From: DataEraserC <102341238+DataEraserC@users.noreply.github.com> Date: Sat, 9 Dec 2023 01:26:15 +0800 Subject: [PATCH] Refactor --- flake/android_builder_fhs_shell/Build.sh | 49 ++++++++ flake/android_builder_fhs_shell/Download.sh | 12 ++ flake/android_builder_fhs_shell/flake.lock | 27 +++++ flake/android_builder_fhs_shell/flake.nix | 128 ++++++++++++++++++++ mariadb.nix => nix-shell/mariadb.nix | 0 python.nix => nix-shell/python.nix | 0 6 files changed, 216 insertions(+) create mode 100644 flake/android_builder_fhs_shell/Build.sh create mode 100644 flake/android_builder_fhs_shell/Download.sh create mode 100644 flake/android_builder_fhs_shell/flake.lock create mode 100644 flake/android_builder_fhs_shell/flake.nix rename mariadb.nix => nix-shell/mariadb.nix (100%) rename python.nix => nix-shell/python.nix (100%) diff --git a/flake/android_builder_fhs_shell/Build.sh b/flake/android_builder_fhs_shell/Build.sh new file mode 100644 index 0000000..0a6b267 --- /dev/null +++ b/flake/android_builder_fhs_shell/Build.sh @@ -0,0 +1,49 @@ +export DEV_DIR=$(dirname "$(readlink -f "$0")") +cd $DEV_DIR || yes +export PATH=$DEV_DIR/toolchains/clang-aosp/bin:$PATH +export GCC_32=CROSS_COMPILE_ARM32=$DEV_DIR/toolchains/gcc-32/bin/arm-linux-androideabi- +export GCC_64=CROSS_COMPILE=$DEV_DIR/toolchains/gcc-64/bin/aarch64-linux-android- +export KERNEL_SOURCE=https://github.com/Nobooooody/android_kernel_motorola_sm8250 +export KERNEL_SOURCE_BRANCH=0warning0error_lineage-20 +export KERNEL_CONFIG=vendor/lineageos_pstar_lxc_docker_defconfig +export KERNEL_IMAGE_NAME=Image +export ARCH=arm64 +export EXTRA_CMDS="LD=ld.lld LOCALVERSION=-test_kernel" + +# Clang +## Custom +export USE_CUSTOM_CLANG=false +export CUSTOM_CLANG_SOURCE= +export CUSTOM_CLANG_BRANCH= + +### if your set USE CUSTOM CLANG to false than DO NOT CHANGE CUSTOM CMDS +export CUSTOM_CMDS="CLANG_TRIPLE=aarch64-linux-gnu-" + +## AOSP +export CLANG_BRANCH=android13-release +export CLANG_VERSION=r450784d + +# GCC +export ENABLE_GCC_ARM64=true +export ENABLE_GCC_ARM32=false + +# KernelSU flags +export ENABLE_KERNELSU=true +export KERNELSU_TAG=main + +# Configuration +export DISABLE_CC_WERROR=false +export ADD_KPROBES_CONFIG=true +export ADD_OVERLAYFS_CONFIG=false + +# Ccache +export ENABLE_CCACHE=true + +# DTBO image +export NEED_DTBO=false + +# Build boot images +export BUILD_BOOT_IMG=true +export SOURCE_BOOT_IMAGE=https://mirrorbits.lineageos.org/full/pstar/20230530/boot.img +make -j$(nproc --all) CC=clang O=out ARCH=$ARCH $EXTRA_CMDS $CUSTOM_CMDS $GCC_64 $GCC_32 $KERNEL_CONFIG +make -j$(nproc --all) CC=clang O=out ARCH=$ARCH $EXTRA_CMDS $CUSTOM_CMDS $GCC_64 $GCC_32 diff --git a/flake/android_builder_fhs_shell/Download.sh b/flake/android_builder_fhs_shell/Download.sh new file mode 100644 index 0000000..231b782 --- /dev/null +++ b/flake/android_builder_fhs_shell/Download.sh @@ -0,0 +1,12 @@ +mkdir toolchains +cd toolchains +wget https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86/+archive/refs/heads/android13-release/clang-r450784d.tar.gz +mkdir clang-aosp +tar -C clang-aosp/ -zxvf clang-r450784d.tar.gz +mkdir gcc-64 +wget -O gcc-aarch64.tar.gz https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/+archive/refs/tags/android-13.0.0_r0.102.tar.gz +tar -C gcc-64/ -zxvf gcc-aarch64.tar.gz +mkdir gcc-32 +wget -O gcc-arm.tar.gz https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/+archive/refs/tags/android-13.0.0_r0.102.tar.gz +tar -C gcc-32/ -zxvf gcc-arm.tar.gz +git clone https://android.googlesource.com/platform/system/tools/mkbootimg tools -b master-kernel-build-2022 --depth=1 \ No newline at end of file diff --git a/flake/android_builder_fhs_shell/flake.lock b/flake/android_builder_fhs_shell/flake.lock new file mode 100644 index 0000000..26fed68 --- /dev/null +++ b/flake/android_builder_fhs_shell/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1701282334, + "narHash": "sha256-MxCVrXY6v4QmfTwIysjjaX0XUhqBbxTWWB4HXtDYsdk=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "057f9aecfb71c4437d2b27d3323df7f93c010b7e", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "23.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake/android_builder_fhs_shell/flake.nix b/flake/android_builder_fhs_shell/flake.nix new file mode 100644 index 0000000..a24c16c --- /dev/null +++ b/flake/android_builder_fhs_shell/flake.nix @@ -0,0 +1,128 @@ +{ + description = "My-Android build environment"; + nixConfig.bash-prompt = "[nix(Android_Builder)] "; + inputs = {nixpkgs.url = "github:nixos/nixpkgs/23.11";}; + + outputs = { + self, + nixpkgs, + } @ inputs: let + system = "x86_64-linux"; + pkgs = + import nixpkgs + { + inherit system; + config = { + permittedInsecurePackages = ["python-2.7.18.7"]; + }; + }; + in { + devShells.${system}.default = let + android_builder_fhs_env = pkgs.buildFHSUserEnv { + name = "android-env"; + targetPkgs = pkgs: + with pkgs; [ + bc + git + gitRepo + gnupg + python2 + curl + procps + openssl + gnumake + nettools + # For nixos < 19.03, use `androidenv.platformTools` + androidenv.androidPkgs_9_0.platform-tools + jdk + schedtool + util-linux + m4 + gperf + perl + libxml2 + zip + unzip + bison + flex + lzop + python3 + ]; + multiPkgs = pkgs: + with pkgs; [ + zlib + ncurses + ]; + runScript = "bash"; + profile = '' + export FHS=1 + export ALLOW_NINJA_ENV=true + export USE_CCACHE=1 + export ANDROID_JAVA_HOME=${pkgs.jdk.home} + # export LD_LIBRARY_PATH=/usr/lib:/usr/lib32 + + export DEV_DIR=/home/nixos/Development + export SOURCE_DIR=/home/nixos/Documents/code/android_kernel_motorola_sm8250 + cd $DEV_DIR || yes + export PATH=$DEV_DIR/toolchains/clang-aosp/bin:$PATH + export GCC_32=CROSS_COMPILE_ARM32=$DEV_DIR/toolchains/gcc-32/bin/arm-linux-androideabi- + export GCC_64=CROSS_COMPILE=$DEV_DIR/toolchains/gcc-64/bin/aarch64-linux-android- + export KERNEL_SOURCE=https://github.com/Nobooooody/android_kernel_motorola_sm8250 + export KERNEL_SOURCE_BRANCH=0warning0error_lineage-20 + export KERNEL_CONFIG=vendor/lineageos_pstar_lxc_docker_defconfig + export KERNEL_IMAGE_NAME=Image + export ARCH=arm64 + export EXTRA_CMDS="LD=ld.lld LOCALVERSION=-test_kernel" + + # Clang + ## Custom + export USE_CUSTOM_CLANG=false + export CUSTOM_CLANG_SOURCE= + export CUSTOM_CLANG_BRANCH= + + ### if your set USE CUSTOM CLANG to false than DO NOT CHANGE CUSTOM CMDS + export CUSTOM_CMDS="CLANG_TRIPLE=aarch64-linux-gnu-" + + ## AOSP + export CLANG_BRANCH=android13-release + export CLANG_VERSION=r450784d + + # GCC + export ENABLE_GCC_ARM64=true + export ENABLE_GCC_ARM32=false + + # KernelSU flags + export ENABLE_KERNELSU=true + export KERNELSU_TAG=main + + # Configuration + export DISABLE_CC_WERROR=false + export ADD_KPROBES_CONFIG=true + export ADD_OVERLAYFS_CONFIG=false + + # Ccache + export ENABLE_CCACHE=true + + # DTBO image + export NEED_DTBO=false + + # Build boot images + export BUILD_BOOT_IMG=true + + cd $SOURCE_DIR || yes + ''; + extraOutputsToInstall = ["dev"]; + }; + in + pkgs.mkShell { + name = "My-Android build environment"; + buildInputs = [ + android_builder_fhs_env + ]; + shellHook = '' + echo "Welcome in $name" + exec android-env + ''; + }; + }; +} diff --git a/mariadb.nix b/nix-shell/mariadb.nix similarity index 100% rename from mariadb.nix rename to nix-shell/mariadb.nix diff --git a/python.nix b/nix-shell/python.nix similarity index 100% rename from python.nix rename to nix-shell/python.nix