!ayCRiZriCVtuCUpeLp:nixos.org

Nix Cross Compiling

577 Members
127 Servers

Load older messages


SenderMessageTime
31 Dec 2024
@fshp:matrix.orgMaxim Moseychuk

Hi, Happy New Year!

Using pkgs.pkgsCross, I can compile a package from nixpkgs for another platform. For example:

# nix-build '<nixpkgs>' -A pkgs.pkgsCross.aarch64-multiplatform.hello

I have a local repository with a package. For example, let’s say it’s a simple hello world.

default.nix:

{ pkgs ? import <nixpkgs> { } }:

{
    myhello = pkgs.callPackage ./pkgs/myhello { };
}

However, I can't build it the same way:

# nix-build -A pkgs.pkgsCross.aarch64-multiplatform.myhello          
error: attribute 'pkgs' in selection path 'pkgs.pkgsCross.aarch64-multiplatform.myhello' not found

I can change pkgs.callPackage in default.nix to pkgs.pkgsCross.aarch64-multiplatform.callPackage. Then the package builds:

# nix-build -A myhello
this derivation will be built:
  /nix/store/3mbcklrdg4dc90qg47fvakv6zv9gwqm2-myhello-1.0-aarch64-unknown-linux-gnu.drv
...

How can I properly test cross-compilation without adding the repository via a channel or flake?
I’d like to test building for different platforms without modifying nix files, as if the package were part of nixpkgs.

09:05:36
@fshp:matrix.orgMaxim Moseychuk *

Hi, Happy New Year!

Using pkgs.pkgsCross, I can compile a package from nixpkgs for another platform. For example:

# nix-build '<nixpkgs>' -A pkgs.pkgsCross.aarch64-multiplatform.hello

I have a local repository with a package. For example, let’s say it’s a simple hello world.

default.nix:

{ pkgs ? import <nixpkgs> { } }:

{
    myhello = pkgs.callPackage ./pkgs/myhello { };
}

However, I can't build it the same way:

# nix-build -A pkgs.pkgsCross.aarch64-multiplatform.myhello          
error: attribute 'pkgs' in selection path 'pkgs.pkgsCross.aarch64-multiplatform.myhello' not found

I can change pkgs.callPackage in default.nix to pkgs.pkgsCross.aarch64-multiplatform.callPackage. Then the package builds:

# nix-build -A myhello
this derivation will be built:
  /nix/store/3mbcklrdg4dc90qg47fvakv6zv9gwqm2-myhello-1.0-aarch64-unknown-linux-gnu.drv
...

How can I properly test cross-compilation without adding the repository via a channel or flake?
I’d like to test building for different platforms without modifying nix files, as if the package were part of nixpkgs.

09:06:44
@k900:0upti.meK900 You can do something like nix-build --expr "(import <nixpkgs> {}).pkgsCross.aarch64-multiplatform.callPackage ./pkgs/myhello {}" 09:06:47
@fshp:matrix.orgMaxim MoseychukThank you very much! But what is the difference between a local file and nixpkgs? How does nix know that a package with a prefix should be cross-compiled? I looked in the nixpkgs repository, but I didn't understand how pkgsCross works, since the packages are declared in one place. Apparently, it's not just the package name, but something generated automatically.09:14:43
@k900:0upti.meK900 pkgsCross is basically another instance of nixpkgs 09:15:32
@k900:0upti.meK900Created with the right configuration to be cross-compiled09:15:44
@k900:0upti.meK900The difference between a local file and nixpkgs is that pkgsCross knows nothing about your local file 09:16:08
@k900:0upti.meK900And neither does nixpkgs for that matter 09:16:14
@k900:0upti.meK900Nix itself knows absolutely nothing about any of it09:17:22
@k900:0upti.meK900Nixpkgs is just one big attrset that it pulls from without understanding its structure in any real way 09:17:41
@fshp:matrix.orgMaxim Moseychuk

If pkgsCross is another instance of nixpkgs, I tried passing it as an explicit parameter, and it worked.

# nix-build --arg pkgs "(import <nixpkgs> {}).pkgsCross.aarch64-multiplatform" -A myhello
09:33:26
@getchoo:matrix.orggetchoo changed their profile picture.12:38:42
@siraben:matrix.orgsiraben left the room.14:51:15
1 Jan 2025
@mjolnir:nixos.orgmjolnirchanged room power levels.14:26:28
@wegank:matrix.org@wegank:matrix.org left the room.20:00:23
@jopejoe1:matrix.orgjopejoe1 (4094@epvpn) changed their display name from jopejoe1 [4094] to jopejoe1.23:29:54
2 Jan 2025
@rhelmot:matrix.orgrhelmotalright chat I think we are almost out of dogshit edge cases before I can resume reviews on the rustc stuff09:09:31
@rhelmot:matrix.orgrhelmotthis last case comes from being on freebsd and compiling... get ready for it...09:09:45
@rhelmot:matrix.orgrhelmotpkgsCross.aarch64-multiplatform.pkgsLLVM.buildPackages.rustc09:09:59
@k900:0upti.meK900One day we'll get to Qt6 cross09:10:15
@k900:0upti.meK900And then to KF609:10:17
@k900:0upti.meK900And then we'll have to figure out corrosion on cross09:10:23
@k900:0upti.meK900And I am not looking forward to that day09:10:28
@rhelmot:matrix.orgrhelmot the problem for the thing I posted seems to be related to clang being multi-target now. we tell rustc configureFlags that --set=target.aarch64-unknown-linux-gnu.linker=/nix/store/6bjs7ai2ai14fdx6kvrfgdfhc16a19md-aarch64-unknown-linux-gnu-clang-wrapper-19.1.6/bin/aarch64-unknown-linux-gnu-clang which is correct but it doesn't pass any flags indicating what linker to use, so it just uses un-prefixed ld which is NOT multi-target and so the compile fails 09:13:52
@rhelmot:matrix.orgrhelmotld is gnu binutils here09:14:44
@rhelmot:matrix.orgrhelmotis this even a legal configuration?09:14:52
@rhelmot:matrix.orgrhelmotI can't remember why I set up the freebsd stdenv to be clang + gnu binutils but it's been working until now...09:16:15
3 Jan 2025
@elikoga:matrix.orgelikoga changed their display name from elikoga (@38c3 📞488{0,1,9}) to elikoga.10:28:12
@sananatheskenana:matrix.orglzcunt joined the room.15:05:59
@9hp71n:matrix.orgghpzin joined the room.15:25:00

Show newer messages


Back to Room ListRoom Version: 6