Skip to content

Instantly share code, notes, and snippets.

@pete3n
pete3n / README.md
Last active November 2, 2024 12:54
Cross-build a local package file

Cross-build a local package file

nix-build -E 'with import <nixpkgs> { crossSystem = { config = "mips-linux-gnu"; }; }; callPackage ./angryoxide/default.nix { }'
@pete3n
pete3n / README.md
Last active May 22, 2024 13:05
Out-of-tree NXP WiFi kernel module Nix build derivation

Out of tree NXP WiFi Kernel module

Build with

nix-build -E 'with import <nixpkgs> {}; callPackage ./build_nxp_wifi_kmod.nix {}'
@pete3n
pete3n / README.md
Last active August 29, 2024 23:43
Nixpkgs build custom architecture (musl soft float ABI)

Nixpkgs custom build targets

Nixpkgs provides pkgsCross with pre-defined targets that can be used for cross-compiling. We can view available targets with:

nix build nixpkgs#pkgsCross. <tab>

And then build for the target with a command like:

nix build nixpkgs#pkgsCross.aarch64-multiplatform.hello 
@pete3n
pete3n / README.md
Created January 27, 2024 20:38
Statically linking cross-compiled Nix packages

Combining staticPkgs with crossPkgs

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?

@pete3n
pete3n / README.md
Last active November 3, 2024 00:14
NixOS Offline Options

NixOS in Offline and Restrictive Networks

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).

Offline Installation

Netboot/Pixieboot

@pete3n
pete3n / README.md
Last active January 6, 2024 23:00
Cross-compile source code with Nix Shells

Cross Compiling With Nix Shells

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.

A Simple Example With GCC

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
@pete3n
pete3n / README.md
Last active December 23, 2023 19:56
Nix Kismet cross-compile aarch64 on x86_64

Cross-compile Nix Kismet package for aarch64-linux on x86_64-linux

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

Cross-compile build tool emulation

QEMU is required to emulate some of the tools in the build environment (pkg-config, protoc, protoc-c). On Debian based systems install with: