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 build: print built derivation paths (cachix support/nix-build compatibility) #2622

Closed
wants to merge 1 commit into from

Conversation

Mic92
Copy link
Member

@Mic92 Mic92 commented Jan 10, 2019

Getting the build path name after a build is a common use case
not supported by nix build yet.
This is for example used in shell scripts like this: $(nix-build)/foo
Cachix even built a business model around it: nix-build | cachix

I have tested that locally and run the tests.
Some tests seem to fail without a sandbox but not due to my change as far as I can tell.

Getting the build path name after a build is a common use case
not supported by nix build yet.
This is for example used in shell scripts like this: $(nix-build)/foo
Cachix even built a business model around it: nix-build | cachix
Copy link

@makefu makefu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested the patch, looks like exactly what i am missing right now with nix build:

$ nix build nixUnstable nix -f '<nixpkgs>' --no-link    
/nix/store/8ag4fs10ph11y1m9lar3y0spwjwbd9dp-nix-2.2pre6526_9f99d624
/nix/store/6kf0zrv27k47z47d315p51p1q8s7bdvj-nix-2.1.3

@Mic92 Mic92 changed the title nix build: print build derivations (cachix support/nix-build compatibility) nix build: print built derivation paths (cachix support/nix-build compatibility) Jan 18, 2019
@mickours
Copy link
Contributor

Ping! Any chance this will be merged at some point?

@Mic92
Copy link
Member Author

Mic92 commented Jul 26, 2019

I try to remind @edolstra next Thursday.

@Mic92
Copy link
Member Author

Mic92 commented Jan 24, 2020

ping @edolstra

@edolstra
Copy link
Member

I think it would be better to add a --json flag to nix build for output intended to be consumed by other tools.

@Mic92
Copy link
Member Author

Mic92 commented Jan 25, 2020

I think a --json flag is orthogonal to this feature and also a lot harder to consume in shell scripts than having the path.

@domenkozar
Copy link
Member

domenkozar commented Apr 9, 2020

Would be really nice to get this one in.

I think getting output of what one wanted to build is useful and it's already consumable as it's newline separated.

A somewhat different approach with similar goal is at #2423

@domenkozar
Copy link
Member

Oh there's three PRs, also #1647

@edolstra
Copy link
Member

edolstra commented Apr 9, 2020

I don't think the new CLI should copy every ad hoc misfeature of the old user interface.

@dasJ
Copy link
Member

dasJ commented May 24, 2020

How is getting the result of a build a misfeature?
Using nix build --no-link means I'll have to query the drv I just built for the out path instead of just getting the result.

Edit: I found this incredibly ugly workaround: nix build -L --no-link $drv && nix show-derivation $drv | jq -r 'values[].outputs.out.path'

@domenkozar
Copy link
Member

domenkozar commented May 28, 2020

@edolstra it would be interesting to hear why it's a misfeature.

I feel --json is orthogonal as it's about choosing what output format is picked.

I'm guessing that it's because it prints store paths by default?

Maybe there would be a flag to print final store paths (newline delimited) with something like nix build --report (and then nix-build --report --json for the JSON format).

@Mic92 Mic92 closed this Jul 17, 2020
@domenkozar
Copy link
Member

Quite sad to see this closed.

@Mic92
Copy link
Member Author

Mic92 commented Jul 18, 2020

Indeed. It would have been nice to have this to build flakes with cachix.

@adrian-gierakowski
Copy link

May I ask what was the reason for closing this?

@Mic92
Copy link
Member Author

Mic92 commented Jul 27, 2020

It was reject by upstream.

@adrian-gierakowski
Copy link

Right, but what was the reason behind the rejection? Is there an alternative proposal? Thanks!

@Mic92
Copy link
Member Author

Mic92 commented Jul 27, 2020

Apparently json output. Which does not solve my use case so. I cannot do $(nix build --json).

@adrian-gierakowski
Copy link

That’s a shame.

@domenkozar
Copy link
Member

@edolstra is there any reason not to add this under a flag? This would be complimentary to the build hook, except that people can work with outputs via shell piping instead of the complicated setup.

@fzakaria
Copy link
Contributor

Throwing this here from #1930 as a stop-gap although also disappointed to see the option of having the OUTPUT printed is gone.
It was very useful for scripting.

nbuild() {
  nix build --no-link "$@"
  nix path-info "$@"
}

@mvnetbiz
Copy link

mvnetbiz commented Jul 3, 2021

It looks like jq is about 900kb on top of Nix, and its obviously more complicated for the simple case, but this doesn't seem too bad.

$ nix build nixos#hello --json | jq -r 'map(.outputs.out) | first'
/nix/store/jmmw0d3nmklwafcwylvrjb9v69wrbcxf-hello-2.10

I think cachix or other tools that commonly use this feature should handle json output automatically or with a flag, which would make it simpler to handle multiple-output derivations as well, although currently not all outputs are printed in --json? This looks like separate bug to me.

$ nix build nixos#jq --json | jq
[
  {
    "drvPath": "/nix/store/v8yam49crkivirdr3na81p8zr8mv27p9-jq-1.6.drv",
    "outputs": {
      "bin": "/nix/store/w6n9d6wvkhr68xi47n7i2dw1hkhfwhx0-jq-1.6-bin"
    }
  }
]

This produces the links "result result-bin result-dev result-doc result-lib result-man" but none are printed in the output.

@samuela
Copy link
Member

samuela commented Apr 7, 2024

Bummed to not see this being implemented, and not get to understand the reasoning behind the rejection. Here's my workaround:

❯ nix build .# --json | jq --raw-output ".[0].outputs.out"                            
/nix/store/dnjsv3xrhb9gajhq7vr55zikcla8q97a-sshenanigans-0.1.0

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

10 participants