Skip to content

A set of nix packages (derivations) to build Android boot.img and AnyKernel installation zip files for given kernel source code.

License

Notifications You must be signed in to change notification settings

AndroidAppsUsedByMyself/nix-kernelsu-builder

 
 

Repository files navigation

Nix-based KernelSU Android Boot Image Builder

A set of nix packages (derivations) to build Android boot.img and AnyKernel installation zip files for given kernel source code.

Packages

Currently I build boot images for 3 devices:

  • .#amazon-fire-hd-karnak: Amazon Fire HD 8 2018. Kernel compiles, but KernelSU doesn't work for lack of 32-bit userland app.
  • .#moto-rtwo-lineageos-21: Motorola Edge+ 2023, unofficial LineageOS 21. Working perfectly.
  • .#oneplus-8t-blu-spark: OnePlus 8T, Blu_spark kernel for LineageOS 21. Working perfectly.
  • .#moto-pstar-lineageos-22.0: Motorola Edge 20 pro, LineageOS 22. Not Working perfectly.

How to add my own device

See kernels.nix for definitions of pipelines (builds for different devices).

Each kernel definition takes these arguments:

  • arch: Kernel architecture, usually arm64.
  • anyKernelVariant: Variant of AnyKernel used during packaging. Can have two values:
  • clangVersion: Version of clang used in kernel build.
    • Can be set to any version present in nixpkgs. Currently the value can be 8 to 17.
    • If set to latest, will use the latest clang in nixpkgs. Recommended.
    • If set to null or "gcc", uses Google's GCC 4.9 toolchain instead.
    • If set to "custom", will use the customGoogleClang or clangPrebuilt.
    • If set to "gki", will use gkiVersion (under development)
  • customGoogleClang: Google Clang.
    • CLANG_VERSION: Version of Google Clang to be used in kernel build.
    • CLANG_BRANCH: Branch of Google Clang to be used in kernel build.
    • CLANG_SHA256: SHA256 of Google Clang which you choose.
  • clangPrebuilt: The clang used in kernel build if clangVersion == custom.
  • enableKernelSU: Whether to apply KernelSU patch.
  • kernelConfig: Additional kernel config to be applied during build.
  • kernelDefconfigs: List of kernel config files applied during build.
    • Older kernels usually have a single _defconfig file. Newer devices may have several.
    • If you're building for a open source third party ROM, check the android_device_[Codename of your device] repo and android_device_[Codename of your device]_common repo, take a look at the BoardConfig.mk and BoardConfigCommon.mk, and take note of all config files in TARGET_KERNEL_CONFIG variable.
    • If you do not have access to such repos, you will need to do some guesswork.
  • kernelImageName: Generated kernel image name at end of compilation process. Usually Image. If you are unsure, again check the BoardConfig.mk or BoardConfigCommon.mk, and look for BOARD_KERNEL_IMAGE_NAME.
  • kernelMakeFlags: Additional make flags passed to kernel build process. Can be used to ignore some compiler warnings.
  • kernelPatches: List of patch files to be applied to kernel.
  • kernelSrc: Source code of the kernel. Can be supplied with fetchgit, fetchGitHub or alike, or provided with nvfetcher, which is already set up in this repo.
  • oemBootImg: Optional, a working boot image for your device, either from official OS or a third party OS (like LineageOS). If this is provided, a boot.img will be generated, which can be directly flashed onto your device.

Use as Flake.parts module

If you want to build Android kernels in your own flake, you can import this repo as a Flake.parts module:

{
  inputs = {
    flake-parts.url = "github:hercules-ci/flake-parts";
    nix-kernelsu-builder.url = "github:xddxdd/nix-kernelsu-builder";
  };
  outputs =
    { flake-parts, ... }@inputs:
    flake-parts.lib.mkFlake { inherit inputs; } {
      imports = [
        inputs.nix-kernelsu-builder.flakeModules.default
      ];
      systems = [ "x86_64-linux" ];
      perSystem =
        { pkgs, ... }:
        {
          kernelsu = {
            # Add your own kernel definition here
            example-kernel = {
              anyKernelVariant = "osm0sis";
              enableKernelSU = false;
              kernelDefconfigs = [ "lineageos_karnak_defconfig" ];
              kernelImageName = "Image.gz-dtb";
              kernelMakeFlags = [
                "KCFLAGS=\"-w\""
                "KCPPFLAGS=\"-w\""
              ];
              kernelSrc = path/to/kernel/source;
              oemBootImg = boot/amazon-fire-hd-karnak.img;
            };
          };
        };
    };
}

License

GPLv3.

About

A set of nix packages (derivations) to build Android boot.img and AnyKernel installation zip files for given kernel source code.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Nix 100.0%