Skip to content

Instantly share code, notes, and snippets.

@Arian04
Forked from Nadrieril/shell.nix
Last active July 24, 2025 16:55
Show Gist options
  • Save Arian04/bea169c987d46a7f51c63a68bc117472 to your computer and use it in GitHub Desktop.
Save Arian04/bea169c987d46a7f51c63a68bc117472 to your computer and use it in GitHub Desktop.
Building LineageOS on NixOS
# I used this shell.nix to build LineageOS 21.0 for redfin (Google Pixel 5)
#
# IMPORANT NOTE: I had to use a pure shell for my builds to work, i.e: `nix-shell --pure` rather than `nix-shell`
#
# The build instructions are here: https://wiki.lineageos.org/devices/redfin/build
#
# Warning (from forked gist, was added August 1st 2018):
# 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.
#
# Created using:
# https://gist.github.com/Nadrieril/d006c0d9784ba7eff0b092796d78eb2a
# https://nixos.wiki/wiki/Android#Building_Android_on_NixOS
{pkgs ? import <nixpkgs> {}}: let
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 = "zsh"; # personal preference, you could set this to bash instead if you want
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
'';
};
in
pkgs.stdenv.mkDerivation {
name = "android-env-shell";
nativeBuildInputs = [fhs];
shellHook = "exec android-env";
}
@JohnRTitor
Copy link

JohnRTitor commented Apr 3, 2024

Thanks for making this script! One thing to note though,

runScript = "zsh";

Can be changed to $SHELL I think, which would utilise user's default shell.

@Arian04
Copy link
Author

Arian04 commented Apr 4, 2024

Your comment just made me realize I forgot to include an important note! I tried using this shell impurely and the builds kept failing until I used the pure version. So even if $SHELL works, I wouldn't wanna include it because the user specifically has to add their shell package to the list.

I'll add the note about using it as a pure shell though, thanks for the reminder lol

edit: in order to make this more generic, I probably should've set it to bash when I uploaded it, but the only reason I didn't is because I didn't test it with Bash. I probably should though.

@JohnRTitor
Copy link

Tested with bash, does work without a hitch.

@drishal
Copy link

drishal commented May 30, 2024

add yaml-cpp as well, some kernels might need yaml.h

@Arian04
Copy link
Author

Arian04 commented May 31, 2024

add yaml-cpp as well, some kernels might need yaml.h

thanks, good to know! I just updated the gist. did it on my phone in the browser though so hopefully the formatting isnt all messed up.

@jmir1
Copy link

jmir1 commented Oct 19, 2024

tysm

@nishithkhanna
Copy link

I tried this and am facing this issue when building beryllium on nixos. Any idea how to solve it? Am using nixpkgs unstable if it helps

@JohnRTitor @drishal @jmir1 @Arian04 any clue?

ld.lld: error: cannot open crtbeginS.o: No such file or directory
ld.lld: error: unable to find library -lgcc
ld.lld: error: unable to find library -lgcc
ld.lld: error: cannot open crtendS.o: No such file or directory
clang: error: linker command failed with exit code 1 (use -v to see invocation)

@N0m4n904
Copy link

I tried this and am facing this issue when building beryllium on nixos. Any idea how to solve it? Am using nixpkgs unstable if it helps

@JohnRTitor @drishal @jmir1 @Arian04 any clue?

ld.lld: error: cannot open crtbeginS.o: No such file or directory
ld.lld: error: unable to find library -lgcc
ld.lld: error: unable to find library -lgcc
ld.lld: error: cannot open crtendS.o: No such file or directory
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I am facing the same issue when trying to build guacamole on nixos. Did you find a fix for it?

@Arian04
Copy link
Author

Arian04 commented Jul 22, 2025

@nishithkhanna @N0m4n904

sorry for the late response. I've made a handful of changes to the file since the last edit. Some of which are to add glibc_multi to multiPkgs and set multiArch = true for buildFHSEnv. Again I made a decent amount of changes, so I'm not sure these are the ones that fix that, but it's worth a try. I'll probably upload all my changes sometime soon-ish, so if those don't work, you could try my exact setup.

@nishithkhanna
Copy link

@N0m4n904 you need to add gcc.cc package. That would make the build work. I didn't try it recently as I don't have server anymore. But you can give that a try. This package is listed in robotnix in here

@N0m4n904
Copy link

@N0m4n904 you need to add gcc.cc package. That would make the build work. I didn't try it recently as I don't have server anymore. But you can give that a try. This package is listed in robotnix in here

Thanks, that was the missing package. It works now

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