Skip to content

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

@vkryachko

Description

@vkryachko

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`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions