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 eval --derivation ignores the --derivation flag #5910

Open
lilyball opened this issue Jan 13, 2022 · 2 comments
Open

nix eval --derivation ignores the --derivation flag #5910

lilyball opened this issue Jan 13, 2022 · 2 comments
Labels

Comments

@lilyball
Copy link
Member

Describe the bug

If I run nix eval with an installable that evaluates to a derivation, passing the --derivation flag does nothing. I expected it to evaluate to the derivation path (with or without the --raw flag). If I'm evaluating a single derivation I can add .drvPath myself (if I can remember to do so), but I always forget. And if I'm evaluating to some other structure that contains nested derivations that makes it much harder.

Steps To Reproduce

  1. nix eval --raw --derivation nixpkgs#hello
  2. nix eval --derivation nixpkgs#hello
  3. nix eval --derivation nixpkgs#bat-extras (bat-extras is an attrset that contains derivations; also recurseForDerivations = true but that shouldn't matter here)
  4. nix eval --derivation --expr 42

Expected behavior

(1) should print the same thing as nix eval --raw nixpkgs#hello.drvPath. Instead it prints the same thing as nix eval --raw nixpkgs#hello.

(2) should print some representation of the derivation. This could just be the drvPath (without quotes, this isn't a string), or perhaps do like nix repl and print e.g. «derivation /nix/store/bdxy7dq6l9xxpl2k2jx4sckgn93rhi0v-hello-2.10.drv».

(3) should print the attrset, except every nested derivation should be printed as a derivation instead of evaluated. I consider this a compelling reason to use syntax like «derivation /nix/store/bdxy7dq6l9xxpl2k2jx4sckgn93rhi0v-hello-2.10.drv» instead of bare paths, as that makes it clear what the type here is.

(4) is included because it involves no derivations. It should behave identically to nix eval --expr 42 as a result (as opposed to being an error). This just illustrates that the --derivation flag should serve to modify how derivations are evaluated rather than requiring the installable/expression to be a derivation or set of derivations.

I suppose another way to look at it is the --derivation flag should be roughly equivalent to running some sort of --apply 'x: mapRecursively (value: if isDerivation value then "«derivation ${value.drvPath}»" else value) (running after any actual --apply, and removing the quotes from the «derivation …» output, i.e. do this at the nix eval level instead of literally wrapping Nix code around it).

nix --version output

nix (Nix) 2.5.1

@lilyball lilyball added the bug label Jan 13, 2022
@pwaller
Copy link
Contributor

pwaller commented May 27, 2022

I see this with nix 2.4, and it's confusing.

@andreabedini
Copy link
Contributor

andreabedini commented Jun 16, 2023

I believe this is a duplicate of #7261 (or at least releated).

As of version 2.15.1, nix does not accept eval --derivation anymore.

❯ nix eval --derivation nixpkgs#hello
error: unrecognised flag '--derivation'
Try 'nix --help' for more information.

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

No branches or pull requests

3 participants