on some derivations, the nix flakes cli and the repl do no agree. #314

Open
opened 2024-05-14 09:58:07 +00:00 by mangoiv · 5 comments

Describe the bug

I have encountered some issues recently where the flake cli and the repl do not agree on what is a derivation. I have not found the reason for this yet,

nix-repl> packages.x86_64-linux.type     

nix-repl> :lf . 
Added 22 variables.

nix-repl> packages.x86_64-linux 
{
  assets = «derivation /nix/store/dxxggrprdlwl10qpxy1s86md8wdn5v6r-assets.drv»;
  haskell-note = «derivation /nix/store/hjzxmyvwgrzyhnvj7l59azdxp3dc264x-haskell-note-0.1.0.0.drv»;
  haskell-note-cli = «derivation /nix/store/4y4q7qacnjm8s0spxcl7shpjr2223zmb-haskell-note-cli.drv»;
  haskell-note-server = «derivation /nix/store/dk2yx7sipplv9z582f7gh9y1h6b2mm26-haskell-note-server.drv»;
}

nix-repl> :b packages.x86_64-linux.haskell-note

This derivation produced the following outputs:
  out -> /nix/store/wpfd7d4lffxvf94c2cpm411av7rvs21q-haskell-note-0.1.0.0

nix-repl> 
haskell-note on  main via λ 9.6.5 via ❄️  impure (haskell-note-env) took 1m51s 
λ nix build .#haskell-note
error: flake output attribute 'packages.x86_64-linux.haskell-note' is not a derivation or path

Steps To Reproduce

one possibly way of reproducing is to

nix build git+https://git.mangoiv.com/mangoiv/haskell-note#haskell-note

Expected behavior

nix build should work here.

nix --version output

nix (Lix, like Nix) 2.90.0-beta.1

Additional context

## Describe the bug I have encountered some issues recently where the flake cli and the repl do not agree on what is a derivation. I have not found the reason for this yet, ``` nix-repl> packages.x86_64-linux.type nix-repl> :lf . Added 22 variables. nix-repl> packages.x86_64-linux { assets = «derivation /nix/store/dxxggrprdlwl10qpxy1s86md8wdn5v6r-assets.drv»; haskell-note = «derivation /nix/store/hjzxmyvwgrzyhnvj7l59azdxp3dc264x-haskell-note-0.1.0.0.drv»; haskell-note-cli = «derivation /nix/store/4y4q7qacnjm8s0spxcl7shpjr2223zmb-haskell-note-cli.drv»; haskell-note-server = «derivation /nix/store/dk2yx7sipplv9z582f7gh9y1h6b2mm26-haskell-note-server.drv»; } nix-repl> :b packages.x86_64-linux.haskell-note This derivation produced the following outputs: out -> /nix/store/wpfd7d4lffxvf94c2cpm411av7rvs21q-haskell-note-0.1.0.0 nix-repl> haskell-note on  main via λ 9.6.5 via ❄️ impure (haskell-note-env) took 1m51s λ nix build .#haskell-note error: flake output attribute 'packages.x86_64-linux.haskell-note' is not a derivation or path ``` ## Steps To Reproduce one possibly way of reproducing is to ``` nix build git+https://git.mangoiv.com/mangoiv/haskell-note#haskell-note ``` ## Expected behavior `nix build` should work here. ## `nix --version` output ``` nix (Lix, like Nix) 2.90.0-beta.1 ``` ## Additional context
mangoiv added the
bug
label 2024-05-14 09:58:07 +00:00
Owner

So, this is actually a flake thing. Almost everything except flakes that accepts a derivation will also accept a list or attrset of derivations (nix-shell and nix develop are the notable exceptions).

Flakes, however, are very strict and require that anything that expects a derivation to be exactly one derivation, and not anything else. In fact, not only can you not build an attrset or list of derivations, but it is considered a flake schema error to have any attribute in outputs.packages.${system} that is not a single derivation (this is why legacyPackages exists — it doesn't have that requirement, and allows arbitrary types and nested package sets, though as you'll see below this is only at the schema level, and flake-mode building still has the same requirement).

For some examples:

$ nix build --impure -E 'with import <nixpkgs> { }; [ gcc clang ]' # Fine
$ nix build --impure -E 'with import <nixpkgs> { }; qt6Packages' # Package set with a bunch of derivations. Fine.
$ nix shell --impure -E 'with import <nixpkgs> { }; qt6Packages' # Also fine. Will put *all* of those in your shell.
$ nix build 'nixpkgs#qt6Packages'
error: flake output attribute 'legacyPackages.x86_64-linux.qt6Packages' is not a derivation or path

So, basically, this is flakes having terrible UX by design, rather than a bug per se. But perhaps it is a flake design flaw we should fix in some way

So, this is actually a flake thing. Almost everything *except* flakes that accepts a derivation will also accept a list or attrset of derivations (`nix-shell` and `nix develop` are the notable exceptions). Flakes, however, are very strict and require that anything that expects a derivation to be exactly *one* derivation, and not anything else. In fact, not only can you not *build* an attrset or list of derivations, but it is considered a flake schema *error* to have *any* attribute in `outputs.packages.${system}` that is not a single derivation (this is why `legacyPackages` exists — it doesn't have that requirement, and allows arbitrary types and nested package sets, though as you'll see below this is only at the schema level, and flake-mode building still has the same requirement). For some examples: ```bash $ nix build --impure -E 'with import <nixpkgs> { }; [ gcc clang ]' # Fine $ nix build --impure -E 'with import <nixpkgs> { }; qt6Packages' # Package set with a bunch of derivations. Fine. $ nix shell --impure -E 'with import <nixpkgs> { }; qt6Packages' # Also fine. Will put *all* of those in your shell. $ nix build 'nixpkgs#qt6Packages' error: flake output attribute 'legacyPackages.x86_64-linux.qt6Packages' is not a derivation or path ``` So, basically, this is flakes having terrible UX by design, rather than a bug per se. But perhaps it is a flake design flaw we should fix in some way
qyriad added
ux
Area/flakes
and removed
bug
labels 2024-05-14 20:13:45 +00:00
Owner

…Actually wait, I couldn't reproduce this with that flake — has anything changed in it since you opened this issue?

$ nix -Lv run 'git+https://git.lix.systems/lix-project/lix?ref=refs/tags/2.90-beta.1' -- build -Lv 'git+https://git.mangoiv.com/mangoiv/haskell-note#haskell-note' --print-out-paths
do you want to allow configuration setting 'allow-import-from-derivation' to be set to 'true' (y/N)? y
do you want to permanently mark this value as trusted (y/N)? n
/nix/store/5y2cfdd228348zx567qrrc09lw1bcl0v-haskell-note-0.1.0.0
…Actually wait, I couldn't reproduce this with that flake — has anything changed in it since you opened this issue? ```bash $ nix -Lv run 'git+https://git.lix.systems/lix-project/lix?ref=refs/tags/2.90-beta.1' -- build -Lv 'git+https://git.mangoiv.com/mangoiv/haskell-note#haskell-note' --print-out-paths do you want to allow configuration setting 'allow-import-from-derivation' to be set to 'true' (y/N)? y do you want to permanently mark this value as trusted (y/N)? n /nix/store/5y2cfdd228348zx567qrrc09lw1bcl0v-haskell-note-0.1.0.0 ```
Author

i don't think I changed anything but I can't reproduce anymore, either, I think nix is gaslighting me again.

i don't think I changed anything but I can't reproduce anymore, either, I think nix is gaslighting me again.
Author

I must have changed something, let me dig

I must have changed something, let me dig
Author

nope, cannot reproduce, even with commits far before opening this PR; I hope this doesn't have to do anything with local checkout vs git url.

nope, cannot reproduce, even with commits far before opening this PR; I hope this doesn't have to do anything with local checkout vs git url.
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: lix-project/lix#314
No description provided.