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

nix develop: Add --redirect flag to redirect dependencies #4161

Merged
merged 2 commits into from Oct 22, 2020

Conversation

edolstra
Copy link
Member

@edolstra edolstra commented Oct 18, 2020

This is primarily useful if you're hacking simultaneously on a package and one of its dependencies. E.g. if you're hacking on Hydra and Nix, you would start a dev shell for Nix (which installs in e.g. ~/Dev/nix/outputs), and then a dev shell for Hydra as follows:

$ nix develop \
  --redirect .#hydraJobs.build.x86_64-linux.nix ~/Dev/nix/outputs/out \
  --redirect .#hydraJobs.build.x86_64-linux.nix.dev ~/Dev/nix/outputs/dev

(This assumes hydraJobs.build.x86_64-linux has a passthru.nix attribute. You can also use a store path.)

This causes all references in the environment to those store paths to be rewritten to ~/Dev/nix/outputs/{out,dev}. Note: don't forget to run fixupPhase in the first shell, otherwise pkgconfig files are not in the correct location. Note 2: unfortunately, you may need to set LD_LIBRARY_PATH=~/Dev/nix/outputs/out/lib because Nixpkgs' ld-wrapper only adds -rpath entries for -L flags that point to the Nix store.

@viric

@viric
Copy link
Member

viric commented Oct 20, 2020

Oh I'll have to give a try to this! I have yet to grasp flakes fully. I'll go through your blogposts for that.

@viric
Copy link
Member

viric commented Oct 20, 2020

Do you think this will work for a common c++ scenario of, let's say, qpdfview and poppler?

@edolstra
Copy link
Member Author

@viric It should also work without flakes though (e.g. nix develop -f /path/to/nixpkgs poppler). Though I just ran into a bug starting nix develop on qpdfview...

This is primarily useful if you're hacking simultaneously on a package
and one of its dependencies. E.g. if you're hacking on Hydra and Nix,
you would start a dev shell for Nix, and then a dev shell for Hydra as
follows:

  $ nix develop \
    --redirect .#hydraJobs.build.x86_64-linux.nix ~/Dev/nix/outputs/out \
    --redirect .#hydraJobs.build.x86_64-linux.nix.dev ~/Dev/nix/outputs/dev

(This assumes hydraJobs.build.x86_64-linux has a passthru.nix
attribute. You can also use a store path.)

This causes all references in the environment to those store paths to
be rewritten to ~/Dev/nix/outputs/{out,dev}. Note: unfortunately, you
may need to set LD_LIBRARY_PATH=~/Dev/nix/outputs/out/lib because
Nixpkgs' ld-wrapper only adds -rpath entries for -L flags that point
to the Nix store.
@edolstra edolstra merged commit a78582c into NixOS:master Oct 22, 2020
@edolstra edolstra deleted the nix-develop-redirects branch October 22, 2020 11:46
@nixos-discourse
Copy link

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

https://discourse.nixos.org/t/tweag-nix-dev-update-4/9862/1

@tomberek
Copy link
Contributor

Is this supposed to work when the input is not a flake? Or is that a desired feature?

@SeTSeR
Copy link

SeTSeR commented Jun 18, 2022

Can this be used to build some package against host libc? I wanted to build latest librsvg from Nix against libc-2.31 from Ubuntu 20.04. I used this command to start shell:

nix develop nixpkgs/nixos-unstable#librsvg --redirect nixpkgs/nixos-unstable#glibc.dev /usr

However, I got the warning, that this flake is not used by the build environment. Then I tried to write simple program to ensure I build against old libc:

#include <unistd.h>

int main(void) {
    closefrom(3);
    return 0;
}

I expected that this program should not compile as closefrom was introduced in glibc-2.34, but it compiles successfully. Am I missing something? Maybe I should use glibc from older nixpkgs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants