Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
yshui opened this issue Jan 17, 2024 · 10 comments · May be fixed by #303849
Open

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

yshui opened this issue Jan 17, 2024 · 10 comments · May be fixed by #303849
Labels
0.kind: build failure A package fails to build 6.topic: cross-compilation Building packages on a different platform than they will be used on 6.topic: static

Comments

@yshui
Copy link
Contributor

yshui commented Jan 17, 2024

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 👍 reaction to issues you find important.

@yshui yshui added the 0.kind: build failure A package fails to build label Jan 17, 2024
@yshui
Copy link
Contributor Author

yshui commented Jan 17, 2024

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
Copy link
Member

wegank commented Jan 18, 2024

pkgsStatic = nixpkgsFun ({
overlays = [ (self': super': {
pkgsStatic = super';
})] ++ overlays;
crossSystem = {
isStatic = true;
parsed =
if stdenv.isLinux
then makeMuslParsedPlatform stdenv.hostPlatform.parsed
else stdenv.hostPlatform.parsed;
} // lib.optionalAttrs (stdenv.hostPlatform.system == "powerpc64-linux") {
gcc.abi = "elfv2";
};
});

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

# 64 bit mingw-w64
mingwW64 = {
# That's the triplet they use in the mingw-w64 docs.
config = "x86_64-w64-mingw32";
libc = "msvcrt"; # This distinguishes the mingw (non posix) toolchain
};

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

@wolfgangwalther wolfgangwalther linked a pull request Apr 13, 2024 that will close this issue
13 tasks
@Frontear
Copy link
Member

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

wolfgangwalther added a commit to wolfgangwalther/nixpkgs that referenced this issue Sep 25, 2024
This makes combinations work, where pkgsStatic is used on another
package set, for example:

- Keeps pkgsCross.mingwW64.pkgsStatic.stdenv.hostPlatform.config at
"x86_64-w64-mingw32"
- Keeps pkgsLLVM.pkgsStatic.stdenv.hostPlatform.useLLVM at "true"

Makes pkgsCross.mingwW64.pkgsStatic.stdenv build. Not sure whether it
actually builds static executables already, though.

Resolves NixOS#281596
@aforemny
Copy link
Contributor

aforemny commented Oct 14, 2024

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

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

@FliegendeWurst FliegendeWurst added 6.topic: cross-compilation Building packages on a different platform than they will be used on 6.topic: static labels Oct 14, 2024
@tiagolobocastro
Copy link
Contributor

tiagolobocastro commented Nov 5, 2024

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

@aforemny
Copy link
Contributor

aforemny commented Nov 6, 2024

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

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
Copy link
Contributor

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.

@tiagolobocastro
Copy link
Contributor

What is the difference between
pkgsCross.mingwW64.pkgsStatic.stdenv.targetPlatform.config
and
pkgsStatic.pkgsCross.mingwW64.stdenv.targetPlatform.config
?
It seems the later does yield x86_64-w64-mingw32

@wolfgangwalther
Copy link
Contributor

It seems the later does yield x86_64-w64-mingw32

It does - but it's not static anymore. pkgsCross resets everything , so the pkgsStatic information is lost.

Semantically it would mean something else than the first line. The second line would be: "Use a statically compiled build system to cross-compile to dynamically linked mingw".

@tiagolobocastro
Copy link
Contributor

I see, that makes sense.
Interestingly pkgsStatic.pkgsCross.mingwW64.pkgsStatic.stdenv.targetPlatform.config does yield x86_64-w64-mingw32.

wolfgangwalther added a commit to wolfgangwalther/nixpkgs that referenced this issue Dec 15, 2024
The various pkgsXYZ top-level package sets did not pass localSystem /
crossSystem to lower levels, so far. This change propagates original
arguments to lower levels, which include the overrides made by an upper
package sets.

There is an extensive test-suite to test various combinations of package
sets in pkgs/test/top-level. There are a few basic promises made:

- Package sets must be idempotent. pkgsMusl.pkgsMusl === pkgsMusl.

- Once pkgsCross is used any subsequent package sets should affect the
  **host platform** and not the build platform. Examples:
  - pkgsMusl.pkgsCross.gnu64 is a cross compilation from musl to glibc
  - pkgsCross.gnu64.pkgsMusl is a cross compilation to musl

- Modifications from an earlier layer should not be lost, unless
  explicitly overwritten. Examples:
  - pkgsStatic.pkgsMusl should still be static.
  - pkgsStatic.pkgsCross.gnu64 should be static, but with glibc instead of
    musl.

Exceptions / TODOs:
- pkgsExtraHardening is currently not idempotent, because it applies the
  same flags over and over again.

Supersedes NixOS#136549
Resolves NixOS#114510
Resolves NixOS#212494
Resolves NixOS#281596
wolfgangwalther added a commit to wolfgangwalther/nixpkgs that referenced this issue Dec 16, 2024
The various pkgsXYZ top-level package sets did not pass localSystem /
crossSystem to lower levels, so far. This change propagates original
arguments to lower levels, which include the overrides made by an upper
package sets.

There is an extensive test-suite to test various combinations of package
sets in pkgs/test/top-level. There are a few basic promises made:

- Package sets must be idempotent. pkgsMusl.pkgsMusl === pkgsMusl.

- Once pkgsCross is used any subsequent package sets should affect the
  **host platform** and not the build platform. Examples:
  - pkgsMusl.pkgsCross.gnu64 is a cross compilation from musl to glibc
  - pkgsCross.gnu64.pkgsMusl is a cross compilation to musl

- Modifications from an earlier layer should not be lost, unless
  explicitly overwritten. Examples:
  - pkgsStatic.pkgsMusl should still be static.
  - pkgsStatic.pkgsCross.gnu64 should be static, but with glibc instead of
    musl.

Exceptions / TODOs:
- pkgsExtraHardening is currently not idempotent, because it applies the
  same flags over and over again.

Supersedes NixOS#136549
Resolves NixOS#114510
Resolves NixOS#212494
Resolves NixOS#281596
wolfgangwalther added a commit to wolfgangwalther/nixpkgs that referenced this issue Dec 21, 2024
The various pkgsXYZ top-level package sets did not pass localSystem /
crossSystem to lower levels, so far. This change propagates original
arguments to lower levels, which include the overrides made by an upper
package sets.

There is an extensive test-suite to test various combinations of package
sets in pkgs/test/top-level. There are a few basic promises made:

- Package sets must be idempotent. pkgsMusl.pkgsMusl === pkgsMusl.

- Once pkgsCross is used any subsequent package sets should affect the
  **host platform** and not the build platform. Examples:
  - pkgsMusl.pkgsCross.gnu64 is a cross compilation from musl to glibc
  - pkgsCross.gnu64.pkgsMusl is a cross compilation to musl

- Modifications from an earlier layer should not be lost, unless
  explicitly overwritten. Examples:
  - pkgsStatic.pkgsMusl should still be static.
  - pkgsStatic.pkgsCross.gnu64 should be static, but with glibc instead of
    musl.

Exceptions / TODOs:
- pkgsExtraHardening is currently not idempotent, because it applies the
  same flags over and over again.

Supersedes NixOS#136549
Resolves NixOS#114510
Resolves NixOS#212494
Resolves NixOS#281596
wolfgangwalther added a commit to wolfgangwalther/nixpkgs that referenced this issue Dec 21, 2024
The various pkgsXYZ top-level package sets did not pass localSystem /
crossSystem to lower levels, so far. This change propagates original
arguments to lower levels, which include the overrides made by an upper
package sets.

There is an extensive test-suite to test various combinations of package
sets in pkgs/test/top-level. There are a few basic promises made:

- Package sets must be idempotent. pkgsMusl.pkgsMusl === pkgsMusl.

- Once pkgsCross is used any subsequent package sets should affect the
  **host platform** and not the build platform. Examples:
  - pkgsMusl.pkgsCross.aarch64-multiplatform is a cross compilation from
musl to glibc/aarch64
  - pkgsCross.aarch64-multiplatform.pkgsMusl is a cross compilation to
musl/aarch64

- Modifications from an earlier layer should not be lost, unless
  explicitly overwritten. Examples:
  - pkgsStatic.pkgsMusl should still be static.
  - pkgsStatic.pkgsCross.gnu64 should be static, but with glibc instead
of
    musl.

Exceptions / TODOs:
- pkgsExtraHardening is currently not idempotent, because it applies the
  same flags over and over again.

Supersedes NixOS#136549
Resolves NixOS#114510
Resolves NixOS#212494
Resolves NixOS#281596
wolfgangwalther added a commit to wolfgangwalther/nixpkgs that referenced this issue Dec 21, 2024
The various pkgsXYZ top-level package sets did not pass localSystem /
crossSystem to lower levels, so far. This change propagates original
arguments to lower levels, which include the overrides made by an upper
package sets.

There is an extensive test-suite to test various combinations of package
sets in pkgs/test/top-level. There are a few basic promises made:

- Package sets must be idempotent. pkgsMusl.pkgsMusl === pkgsMusl.

- Once pkgsCross is used any subsequent package sets should affect the
  **host platform** and not the build platform. Examples:
  - pkgsMusl.pkgsCross.aarch64-multiplatform is a cross compilation from
musl to glibc/aarch64
  - pkgsCross.aarch64-multiplatform.pkgsMusl is a cross compilation to
musl/aarch64

- Modifications from an earlier layer should not be lost, unless
  explicitly overwritten. Examples:
  - pkgsStatic.pkgsMusl should still be static.
  - pkgsStatic.pkgsCross.gnu64 should be static, but with glibc instead
of musl.

Exceptions / TODOs:
- pkgsExtraHardening is currently not idempotent, because it applies the
  same flags over and over again.

Supersedes NixOS#136549
Resolves NixOS#114510
Resolves NixOS#212494
Resolves NixOS#281596
wolfgangwalther added a commit to wolfgangwalther/nixpkgs that referenced this issue Dec 21, 2024
The various pkgsXYZ top-level package sets did not pass localSystem /
crossSystem to lower levels, so far. This change propagates original
arguments to lower levels, which include the overrides made by an upper
package sets.

There is an extensive test-suite to test various combinations of package
sets in pkgs/test/top-level. There are a few basic promises made:

- Package sets must be idempotent. pkgsMusl.pkgsMusl === pkgsMusl.

- Once pkgsCross is used any subsequent package sets should affect the
  **host platform** and not the build platform. Examples:
  - pkgsMusl.pkgsCross.aarch64-multiplatform is a cross compilation from
musl to glibc/aarch64
  - pkgsCross.aarch64-multiplatform.pkgsMusl is a cross compilation to
musl/aarch64

- Modifications from an earlier layer should not be lost, unless
  explicitly overwritten. Examples:
  - pkgsStatic.pkgsMusl should still be static.
  - pkgsStatic.pkgsCross.gnu64 should be static, but with glibc instead
of musl.

Exceptions / TODOs:
- pkgsExtraHardening is currently not idempotent, because it applies the
  same flags over and over again.

Supersedes NixOS#136549
Resolves NixOS#114510
Resolves NixOS#212494
Resolves NixOS#281596
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: build failure A package fails to build 6.topic: cross-compilation Building packages on a different platform than they will be used on 6.topic: static
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants