nix-build -E 'with import <nixpkgs> { crossSystem = { config = "mips-linux-gnu"; }; }; callPackage ./angryoxide/default.nix { }'
Downloading nixpkgs allows you to easily cross-compile Nix packages with
nix build .#pkgsCross.architecture.packageName
Where architecture is the target architecture you are cross-compiling to (like aarch64-multiplatform), and packageName is the package you are building (traceroute in this example).
This will output the package output to ./result which should include your output binary in ./result/bin . This output binary typically dynamically linked, but what if we need to cross-compile AND statically link the output binary?
This gist was created to explore options for working with NixOS in a completely offline environment or inside a network with restricted internet access (such as a corporate LAN with a Proxy).
- I discoverd that the graphical installation ISO had no ability to install offline, so I created this repo which allows creating custom offline installation ISOs using the graphical installer
- Kevin Cox created a similar repo on Gitlab his version focuses more on automatation and uses the minimal install ISO rather than the graphical ISO
- This is another similar project that is less recent: https://github.com/tfc/nixos-offline-installer
- https://determinate.systems/posts/moving-stuff-around-with-nix
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
This gist shows an overlay that can be applied to the Nix Kismet package to enable cross-compiling with pkgsCross. It also provides a modified Kismet packages with the applied changes.
NOTE: This gist is now obselete, issue was resolved with this PR: NixOS/nixpkgs#276038
QEMU is required to emulate some of the tools in the build environment (pkg-config, protoc, protoc-c). On Debian based systems install with: