Nix shells offer an easy way to cross-compile source code without having to install a bunch of tool chains on your system. The shell will pull everything it needs to setup the build environment, and will keep it cached until you run garbage colleciotn.
gcc_armv7-a.nix is a simple example configured to create a build environment for gcc with an ARMv7-a target. I can cross-compile my rev_shell.c code with:
nix-shell --run '$CC rev_shell.c -o rev_shell_armv7a' gcc_armv7-a.nix
Checking the output binary with:
readelf -a rev_shell_armv7a
I see:
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: ARM
...
Tag_CPU_name: "7-A"
Tag_CPU_arch: v7
Looks good. That was easy. What about something trickier. Let's grab a custom toolchain and build for MIPS and MIPSEL soft-float.
nix-shell --run '$CC rev_shell.c -o rev_shell_mips_muslsf' musl-mips-sf.nix
Checking the output
Class: ELF32
Data: 2's complement, big endian
Machine: MIPS R3000
...
File Attributes
Tag_GNU_MIPS_ABI_FP: Soft float
Great, this is the exact same for mipsel, just replacing mips with mipsel.