Learned a neat #Nix trick: You can easily cross-compile all programs in Nixpkgs (as long as they support the target platform)!
-
Learned a neat #Nix trick: You can easily cross-compile all programs in Nixpkgs (as long as they support the target platform)!
So instead of `nix build nixpkgs#ripgrep`, to build ripgrep for Windows, you can use:
nix build nixpkgs#pkgsCross.mingwW64.ripgrep
Other example targets are:
- "aarch64-multiplatform" (AMD64)
- "gnu32" (i686)
- "riscv64" (64-bit RISC-V)
- "musl64" (x86_64, using musl instead of glibc)Many more are defined in this file: https://github.com/NixOS/nixpkgs/blob/master/lib/systems/examples.nix
-
G gustavinobevilacqua@mastodon.cisti.org shared this topic on
-
You can also build 32-bit programs more directly:
nix build nixpkgs#pkgsi686Linux.ripgrep
You can also produce a static executable for your current platform:
nix build nixpkgs#pkgsStatic.ripgrep
And best of all – you can combine those! Here's a 32-bit static binary (which happened to be the thing I need right now for my tiny Linux in the browser project):
nix build nixpkgs#pkgsi686Linux.pkgsStatic.ripgrep