Underappreciated nixpkgs feature: Instead of building in the normal minimal sandbox environment, just say runInLinuxImage
to install a different Linux distro in a temporary VM, install some of that distro's packages, and run the build there! nixpkgs even packages 19 other releases from four other distros to be used with this feature:
Distro | Architecture | |
---|---|---|
x86_64 | i386 | |
Debian | 10.13-buster 11.6-bullseye |
10.13-buster 11.6-bullseye |
Ubuntu | 14.04-trusty 16.04-xenial 18.04-bionic 20.04-focal 22.04-jammy |
14.04-trusty 16.04-xenial 18.04-bionic 20.04-focal 22.04-jammy |
Fedora | 26 27 |
|
Centos | 6 7 |
6 |
I was having trouble cross-compiling an embedded ARM executable from a x86_64 machine while working with the Raspberry Pi Pico SDK—their build instructions just weren't working. Their build instructions "assume you are using Raspberry Pi OS running on a Raspberry Pi 4, or an equivalent Debian-based Linux distribution running on another platform." I thought it was going to be a chore to set up and use a VM for this, but it was this easy to just say "Nah, build it in Debian," with the list of Debian packages they said to install:
let foo = { lib, stdenv, ... }: stdenv.mkDerivation { pname = "foo"; version = ...; ... + diskImage = pkgs.vmTools.diskImageFuns.debian11x86_64 { + extraPackages = [ + "build-essential" + "cmake" + "gcc-arm-none-eabi" + "libnewlib-arm-none-eabi" + "libstdc++-arm-none-eabi-newlib" + ]; + }; + diskImageFormat = "qcow2"; } -in pkgs.callPackage foo { } +in pkgs.vmTools.runInLinuxImage (pkgs.callPackage foo { })