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

Print path names built by nix build #1647

Closed
wants to merge 1 commit into from
Closed

Conversation

layus
Copy link
Member

@layus layus commented Oct 30, 2017

When building with nix build --no-link, there is otherwise no way to know the store path that was built.

@bhipple
Copy link
Contributor

bhipple commented Jun 11, 2018

I'm not sure why this PR was never merged. Just forgotten maybe? Or is there any objection?

In the meantime, for users who would like to continue using the otherwise nicer nix 2.0 commands, it's possible to get the best of both worlds by forking nix with an overlay:

$ cat ~/.config/nixpkgs/overlays/01-patches.nix
self: super: {
  nix = super.nix.overrideAttrs(_: {
    patches = [
      (super.fetchpatch {
        # Show build output with `nix build`. https://github.com/NixOS/nix/pull/1647
        url = "https://github.com/NixOS/nix/commit/d02e12f366a02acf34b458eb7530baf2bdc2d251.patch";
        sha256 = "1vbpnnb8mmrkqpmhb92cm9v44y711cqbyfhrbfdhxf643ayz1ngl";
      })
    ];
  });
}

Then nix build shows the built output!

$ nix-build '<nixpkgs>' -A nix                                                                
/nix/store/p2c6a8v6ww80h57gvclsdq4f1hzywmsi-nix-2.0.4

$(/nix/store/p2c6a8v6ww80h57gvclsdq4f1hzywmsi-nix-2.0.4/bin/nix build src.vim)/bin/vim --help | head -1
VIM - Vi IMproved 8.1 (2018 May 17, compiled Jan  1 1970 00:00:01)

@mpickering
Copy link

Any updates on this patch?

@bobvanderlinden
Copy link
Member

I need this :( I don't like spraying result links everywhere for temporary builds.

@bobvanderlinden
Copy link
Member

@shlevy @copumpkin Could you have a look?

@edolstra
Copy link
Member

I feel that the nix command should not print things on stdout unless explicitly asked for. We should add a nix build --json flag for machine-readable output.

@bobvanderlinden
Copy link
Member

--json would be really nice to have, but I think most people want to use nix build in combination with bash for temporary builds. With only --json, jq would be required to use nix build ad-hoc in bash. Though I get that it probably shouldn't output anything by default.

What about --output-path?

@layus
Copy link
Member Author

layus commented Aug 10, 2018

Should we setup a poll for the community ?

  1. Should nix build print the path by default ?
  2. Should nix build create ./result by default ?

or do we have to discuss further options ?
This may be a good question for @NixOS/nix-core :-)

@edolstra
Copy link
Member

  1. is a good question, since polluting the current directory is even worse than polluting stdout :-) So maybe --out-link should be required to create a result symlink.

@bhipple
Copy link
Contributor

bhipple commented Aug 10, 2018

Removing the directory pollution would be nice -- particularly when you run a bunch of builds and get result, result-1, result-2, ..., result-n in your dir.

Regarding the stdout, I'd say it's generally in line with most unix tools that they produce stdout, which makes it easy and convenient to pipe them to other commands in the shell. <cmd> | grep is a lot easier and more familiar than <cmd --json> | jq 'query' | grep. Usually if tools want to avoid spending stuff to stdout they have a --quiet or a --silent option.

@bobvanderlinden
Copy link
Member

Just to note I still find it interesting that the stdout solution is essentially a less reliable one (due to the GC). However, it is oh-so-convenient I must say. nix-shell and nix run have the right approach in the sense that while the shell/command is running, the GC cannot destroy the built paths.

For development I often do things like:

find $(nix build my-package-under-development --no-link)

or:

find $(nix-build crossPkgs.aarch64-generic.my-package-under-development --no-link)/bin | while read file; do file $file; done

I think it's fine there is a (almost non-existent) possibility that these commands fails due to the GC interferring. If there is a good 'best of both worlds' solution, I'm all ears :D

@spinus
Copy link
Member

spinus commented Aug 25, 2018

@edolstra There was pretty good suggestion from @ElvishJerricco to use something -o - which is explicit.

@ElvishJerricco
Copy link
Contributor

I consider that suggestion a compromise :P I'd much rather have output on stdout by default. I don't consider it pollution since it's just providing the result in a unix-y way

@bobvanderlinden
Copy link
Member

I don't think changing defaults is a viable way to go. There will be resistance to merge, because existing scripts will break. Maybe this is OK for Nix 2.0?

@ElvishJerricco
Copy link
Contributor

@bobvanderlinden The surface area for breakage caused by going from no output to some output seems small to me. Considering the Nix 2.0 commands are pretty explicitly marked experimental, I think this is ok.

@bobvanderlinden
Copy link
Member

Ah, yes, that seems fine. I thought removing the result symlink as well.

@mkenigs
Copy link
Contributor

mkenigs commented Nov 17, 2020

Think this should be closed by #4182?

@edolstra edolstra closed this Nov 17, 2020
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.