NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.05k stars 14.09k forks source link

Build failure: pkgsCross.mingwW64.pkgsStatic.stdenv #281596

Open yshui opened 9 months ago

yshui commented 9 months ago

Steps To Reproduce

Steps to reproduce the behavior:

  1. build pkgsCross.mingwW64.pkgsStatic.stdenv

Build log

error: builder for '/nix/store/v1ycfkiivjszsl8qagsw2v86r81amwxs-mingw-w64-static-x86_64-w64-windows-gnu-10.0.0-headers.drv' failed with exit code 1;
       last 10 log lines:
       > checking for x86_64-w64-windows-gnu-strip... no
       > checking for strip... no
       > checking for a race-free mkdir -p... /nix/store/khndnv11g1rmzhzymm1s5dw7l2ld45bc-coreutils-9.4/bin/mkdir -p
       > checking for gawk... gawk
       > checking whether make sets $(MAKE)... yes
       > checking whether make supports nested variables... yes
       > checking whether to enable maintainer-specific portions of Makefiles... no
       > checking build system type... x86_64-unknown-linux-gnu
       > checking host system type... Invalid configuration 'x86_64-w64-windows-gnu': Kernel 'windows' not known to work with OS 'gnu'.
       > configure: error: /nix/store/9vafkkic27k7m4934fpawl6yip3a6k4h-bash-5.2-p21/bin/bash ./build-aux/config.sub x86_64-w64-windows-gnu failed

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.6.10-zen1, NixOS, 24.05 (Uakari), 24.05.20240115.c3e128f`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.1`
 - channels(root): `"nixos"`
 - channels(user): `"nixgl, nixpkgs"`
 - nixpkgs: `/nix/store/11zbgb8j7wnnccbbjcq0q556h28g7p4r-source`

Add a :+1: reaction to issues you find important.

yshui commented 9 months ago

pkgsCross.mingwW64.pkgsStatic.stdenv.targetPlatform.config is "x86_64-w64-windows-gnu" for some reason, unlike pkgsCross.mingwW64.stdenv.targetPlatform.config which is "x86_64-w64-mingw32" as expected.

wegank commented 9 months ago

https://github.com/NixOS/nixpkgs/blob/2fba629f59f3de8cf773ad5fcac782e62a934faa/pkgs/top-level/stage.nix#L265-L278

The Windows case doesn't seem to be covered here, since for MinGW-w64, config doesn't use the result from lib.systems.parse.tripleFromSystem pkgsCross.mingwW64.stdenv.hostPlatform.parsed, which is "x86_64-w64-windows-gnu". Instead, we have

https://github.com/NixOS/nixpkgs/blob/cefcf19e1c6d4255b2aede5535d04064f6917e9b/lib/systems/examples.nix#L311-L316

So I guess stdenv.hostPlatform.{config,libc} should be passed to crossSystem conditionally.

Frontear commented 1 month ago

Bump, this issue is quite unfortunate when attempting to build static apps through nix.

aforemny commented 3 weeks ago

I was able to build a static windows (mingwW64) executable with 34cefd7dea46e02932c2413ae7068574d0352ce9. I think this closes the issue? Thanks @wolfgangwalther! :heart:

edit: It seems #303849 is not merged yet. So I'm just leaving this information here.

tiagolobocastro commented 1 day ago

Hi, is there any possible work around for this? (just facing this now after upgrading from 22.11 to 24.05)

aforemny commented 19 hours ago

Hi, is there any possible work around for this? (just facing this now after upgrading from 22.11 to 24.05)

The work-around is to "properly" instantiate cross compilation.

Compare the following on nixos-24.05 at dc2e0028d274394f73653c7c90cc63edbb696be1.

❯ nix-build '<nixpkgs>' -A pkgsCross.mingwW64.pkgsStatic.stdenv
[..]
checking host system type... Invalid configuration 'x86_64-w64-windows-gnu': Kernel 'windows' not known to work with OS 'gnu'.
configure: error: /nix/store/516kai7nl5dxr792c0nzq0jp8m4zvxpi-bash-5.2p32/bin/bash ./build-aux/config.sub x86_64-w64-windows-gnu failed
error: builder for '/nix/store/j8yx9qfk3yyfq2p5w7k0lmg2xkbypfkr-mingw_w64-headers-static-11.0.1.drv' failed with exit code 1;

vs

❯ nix-build --expr '(import <nixpkgs> { crossSystem = { config = "x86_64-w64-mingw32"; isStatic = true; }; }).stdenv'
/nix/store/m77b2dla2w3k8cx4ggjdmm2j8nldy6j6-stdenv-linux

The problem is not that static mingw64 cross-compilation is broken. The problem is that pkgsCross and pkgsStatic cannot be arbitrarily combined.

wolfgangwalther commented 18 hours ago

The work-around is to "properly" instantiate cross compilation.

Whether that's "proper" or not... is a question of it's own. For example for linux, pkgsStatic will use musl. If you just do isStatic = true that way, it will not be musl, right? But a lot of nixpkgs is assuming Linux + Static = musl.

So imho, there is too much knowledge / dependency in nixpkgs about pkgsStatic already to say it's not correct to use it.

Also.. is it really the composition that is broken? What about the following?

nix-build --expr '(import <nixpkgs> { crossSystem = { config = "x86_64-w64-mingw32"; }; }).pkgsStatic.stdenv'

Yup, broken as well.