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

Dynamic libraries with dependencies no longer link in nix-shells #214626

Closed
zhaofengli opened this issue Feb 4, 2023 · 3 comments
Closed

Dynamic libraries with dependencies no longer link in nix-shells #214626

zhaofengli opened this issue Feb 4, 2023 · 3 comments
Labels
0.kind: regression Something that worked before working no longer

Comments

@zhaofengli
Copy link
Member

zhaofengli commented Feb 4, 2023

Describe the bug

Since around e394505, dynamic libraries with their own dependencies no longer link in an interactive Nix shell environment. Interestingly, everything works fine in sandboxed builds.

Steps To Reproduce

# repro.nix
# nix-shell --pure repro.nix --run "echo \"int main(){}\">test.c; gcc -lbar test.c"
let
  pkgs = import ./. {};
  foo = pkgs.runCommandCC "libfoo" {} ''
    echo "void foo(){}">foo.c
    mkdir -p $out/lib
    gcc -shared -o $out/lib/libfoo.so foo.c
  '';
  bar = pkgs.runCommandCC "libbar" {
    buildInputs = [ foo ];
  } ''
    echo "void foo(); void bar(){ foo(); }">bar.c
    mkdir -p $out/lib
    gcc -shared -o $out/lib/libbar.so -lfoo bar.c
  '';
in pkgs.runCommandCC "repro" {
  buildInputs = [ bar ];
} ''
  echo "int main(){}">test.c
  gcc -o $out -lbar test.c
''

Everything works fine when built in a sandbox:

nix-build repro.nix

However, in a nix-shell it longer links (since around e394505):

$ nix-shell --pure repro.nix --run "echo \"int main(){}\">test.c; gcc -lbar test.c"
/nix/store/r2b9k28c6aghczpqfvh71y9xavm7rr68-binutils-2.39/bin/ld: warning: libfoo.so, needed by /nix/store/p3g8b38ivxsr6kyv5dd7dr5c83kq2dj8-libbar/lib/libbar.so, not found (try using -rpath or -rpath-link)
/nix/store/r2b9k28c6aghczpqfvh71y9xavm7rr68-binutils-2.39/bin/ld: /nix/store/p3g8b38ivxsr6kyv5dd7dr5c83kq2dj8-libbar/lib/libbar.so: undefined reference to `foo'
collect2: error: ld returned 1 exit status

Return to ea692c2 and everything works fine again:

$ git checkout ea692c2ad1afd6384e171eabef4f0887d2b882d3
Previous HEAD position was e3945057be4 Merge pull request #213671 from Luflosi/update/python3Packages.humanize
HEAD is now at ea692c2ad1a Merge pull request #213718 from r-ryantm/auto-update/komga

$ nix-shell --pure repro.nix --run "echo \"int main(){}\">test.c; gcc -lbar test.c"

This seems to affect any dynamic library with their own dependencies, like openssl, nix, and folly.

Expected behavior

Dynamic linking in a nix-shell should just work.

Additional context

The regression occurred between ea692c2 and e394505.

@winterqt
Copy link
Member

winterqt commented Feb 5, 2023

This was fixed by #213185, keeping this open until -next is merged.

@christoph-cullmann
Copy link
Contributor

Thanks for fixing this, just got hit by that, too, for my KDE dev env.

@winterqt winterqt pinned this issue Feb 9, 2023
@winterqt
Copy link
Member

The fix has hit master, going to keep this pinned for a bit, though.

In case anyone comes across this: update your Nixpkgs.

@wegank wegank unpinned this issue Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: regression Something that worked before working no longer
Projects
None yet
Development

No branches or pull requests

3 participants