Skip to content

Instantly share code, notes, and snippets.

@Nadrieril
Last active March 17, 2024 08:03
Show Gist options
  • Star 24 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save Nadrieril/d006c0d9784ba7eff0b092796d78eb2a to your computer and use it in GitHub Desktop.
Save Nadrieril/d006c0d9784ba7eff0b092796d78eb2a to your computer and use it in GitHub Desktop.
Building LineageOS on NixOS
# I used this shell.nix to build LineageOS 13.0 for my maguro (Samsung Galaxy Nexus GSM) phone
# The build instructions for normal Linuxes are here: https://wiki.lineageos.org/devices/maguro/build
# For NixOS, follow those instructions but skip anything related to installing packages
# Detailed instructions:
# cd into an empty directory of your choice
# copy this file there
# in nix-shell:
# $ repo init -u https://github.com/LineageOS/android.git -b cm-13.0
# $ repo sync
# $ source build/envsetup.sh
# $ breakfast maguro
# Get proprietary blobs (see https://wiki.lineageos.org/devices/maguro/build#extract-proprietary-blobs)
# (I actually used blobs from https://github.com/TheMuppets, following https://forum.xda-developers.com/showpost.php?s=a6ee98b07b1b0a2f4004b902a65d9dcd&p=76981184&postcount=4)
# $ ccache -M 50G (see https://wiki.lineageos.org/devices/maguro/build#turn-on-caching-to-speed-up-build)
# $ croot
# $ brunch maguro
# $ cd $OUT
# The built ROM is named something like lineage-13.0-20180730-UNOFFICIAL-maguro.zip
# You can flash it onto your device as usual, see e.g. https://wiki.lineageos.org/devices/maguro/install for maguro
# Voilà ! It Just Works™ (at least it did for me)
# Warning: the hardened NixOS kernel disables 32 bit emulation, which made me run into multiple "Exec format error" errors.
# To fix, use the default kernel, or enable "IA32_EMULATION y" in the kernel config.
let
# nixpkgs-unstable does not have jdk7 anymore. I used the nixos-18.03 channel
pkgs = import <nixpkgs> {};
# Inspired from https://nixos.wiki/wiki/Android#Building_Android_on_NixOS
# I had to add several packages to make it work for me
fhs = pkgs.buildFHSUserEnv {
name = "android-env";
targetPkgs = pkgs: with pkgs; [
androidenv.platformTools
bc
binutils
bison
ccache
curl
flex
gcc
git
gitRepo
gnumake
gnupg
gperf
imagemagick
jdk7
libxml2
lz4
lzop
m4
maven # Needed for LineageOS 13.0
nettools
openssl
perl
pngcrush
procps
python2
rsync
schedtool
SDL
squashfsTools
unzip
utillinux
wxGTK30
xml2
zip
];
multiPkgs = pkgs: with pkgs; [
zlib
ncurses5
libcxx
readline
];
runScript = "bash";
profile = ''
export USE_CCACHE=1
export ANDROID_JAVA_HOME=${pkgs.jdk7.home}
# Building involves a phase of unzipping large files into a temporary directory
export TMPDIR=/tmp
'';
};
in pkgs.stdenv.mkDerivation {
name = "android-env-shell";
nativeBuildInputs = [ fhs ];
shellHook = "exec android-env";
}
@Arian04
Copy link

Arian04 commented Jan 31, 2024

ily <3

@Nadrieril
Copy link
Author

I hope this still works after 6 years 🙈

@Arian04
Copy link

Arian04 commented Jan 31, 2024

im fixing it up a bit but between this file and the super helpful nixos wiki link you included, I think i'll be able to make it work for my needs pretty quick

@Nadrieril
Copy link
Author

amazing

@Arian04
Copy link

Arian04 commented Mar 17, 2024

kinda forgot about this tbh but i just remembered to fork your gist with my changes for LineageOS 21 on redfin. leaving this comment here for anyone who finds this gist so they hopefully don't have to duplicate my efforts. Link here: https://gist.github.com/Arian04/bea169c987d46a7f51c63a68bc117472

to anyone reading (idk if it ever will) but if that link ever doesn't work then just check my profile's gists.

@Nadrieril
Copy link
Author

Tyvm!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment