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

stdenv: assertion '(final).hasSharedLibraries' failed #244045

Closed
vkryachko opened this issue Jul 17, 2023 · 4 comments · Fixed by #244118
Closed

stdenv: assertion '(final).hasSharedLibraries' failed #244045

vkryachko opened this issue Jul 17, 2023 · 4 comments · Fixed by #244118

Comments

@vkryachko
Copy link

Describe the bug

Nix fails to build nix on nixpkgs master.

Steps To Reproduce

Steps to reproduce the behavior:

  1. on unstable channel
  2. nix-channel --update
  3. This works: nix-build -E 'with import <nixpkgs> {}; nix'
  4. This fails: nix-build -E 'with import <nixpkgs> {}; let unused = {whatever.extensions =[];}; in nix' --show-trace
  5. Assertion failure:
error: assertion '(final).hasSharedLibraries' failed

       at /nix/store/v63vjk8lz2fsj52qkfgbbw1mbgplcdmc-nixpkgs/nixpkgs/lib/systems/default.nix:89:25:

           88|       extensions = rec {
           89|         sharedLibrary = assert final.hasSharedLibraries;
             |                         ^
           90|           /**/ if final.isDarwin  then ".dylib"

Expected behavior

Both invocations should succeed as they are isomorphic, i.e. 4. has an unused let binding that causes nix to fail.

Additional context

Looks like this PR may have introduced the assert that causes the problem #238154 , commit

After some investigation a colleague pointed out that the issue may have to do with the instability of attrset comparison due to laziness in nix, comparison happens here

pkgsBuildTarget =
if args.stdenv.targetPlatform == args.stdenv.hostPlatform
then pkgsBuildHost
else assert args.stdenv.hostPlatform == args.stdenv.buildPlatform; thisStage;

and looks like invocation in 4. somehow cause a different evaluation order of attrset attribute comparison:

  • if isStatic is compared first we don't see the assert
  • If extensions compares first we stumble on the assert and fail.
nix-repl> pkgs.stdenv.hostPlatform.extensions
{ executable = ""; library = ".so"; sharedLibrary = ".so"; staticLibrary = ".a"; }

nix-repl> pkgsStatic.stdenv.hostPlatform.extensions
{ executable = ""; library = ".a"; sharedLibrary = «error: error: assertion '(final).hasSharedLibraries' failed

       at /nix/store/v63vjk8lz2fsj52qkfgbbw1mbgplcdmc-nixpkgs/nixpkgs/lib/systems/default.nix:89:25:

           88|       extensions = rec {
           89|         sharedLibrary = assert final.hasSharedLibraries;
             |                         ^
           90|           /**/ if final.isDarwin  then ".dylib"»; staticLibrary = ".a"; }

Notify maintainers

@amjoseph-nixpkgs who added the assert that fails
@edolstra @lovesegfault @Artturin nix package maintainers

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.1.25-1rodete1-amd64`
 - multi-user?: `yes`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.16.1`
 - channels(root): `"nixpkgs"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixpkgs`
@trofi
Copy link
Contributor

trofi commented Jul 17, 2023

With something like NixOS/nix#8711 we can deterministically crash the eval:

$ NIX_VALIDATE_EVAL_NONDETERMINISM=1 nix-instantiate -E 'with import <nixpkgs> {}; nix'
error:
...
       error: assertion '(final).hasSharedLibraries' failed

@Artturin
Copy link
Member

Same issue in NixOS/nix#8701

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/nix-language-evaluation-bug/30582/2

@ghost
Copy link

ghost commented Jul 18, 2023

This was my fault.

The fix is: #244118

Unfortunately we can't provide useful error messages when people use sub-attributes of {host,target,build}Platform, because it is expected that you can compare two *Platform attrsets using ==, which will force the throw "error message".

We should probably move anything fallible (like extensions.sharedLibrary) out of these *Platform attrsets, so we can provide useful error messages instead of just returning null.

@ghost ghost closed this as completed in #244118 Jul 20, 2023
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants