Describe the bug
Running nix-shell on any nixpkgs checkout (checked on 1d60af77224f25a0c428b21a34463ed1719caa27) fails with the following error on Nix 3.0:
→ nix-shell -A hello
error: --- TypeError -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- nix-shell
at: (84:1) in file: /home/ma27/Projects/nixpkgs/pkgs/top-level/impure.nix
83|
84| import ./. (builtins.removeAttrs args [ "system" "platform" ] // {
| ^
85| inherit config overlays crossSystem crossOverlays;
anonymous function at /home/ma27/Projects/nixpkgs/pkgs/top-level/default.nix:20:1 called with unexpected argument 'inNixShell'
Expected behavior
Getting an open nix-shell.
nix-env --version output
nix-env (Nix) 3.0pre20200829_f156513
Additional context
I didn't have the issue on 2.4pre20200721_ff314f1 and identified 626200713bb3cc844a9feb6af583c9b6b42c6dbc (from #3965) to be the problem. Reverting this commit on top of 77d4758cf2f45a6e999646e292ae563d6f987716 fixes the issue.
The patch 626200713bb3cc844a9feb6af583c9b6b42c6dbc fixes a bug where auto-calling a function a@{ ... }: a is missing all extra-arguments when being called from CLI with nix-instantiate --argstr arg value as the evaluator only added the attributes that were defined in the { ... }-expression.
While this fixes an actual bug, this breaks pkgs/top-level/impure.nix from nixpkgs since this file defines a function with an ellipsis. And all arguments a@{ ... } from this function get passed to pkgs/top-level/default.nix which defines a function without an ellipsis.
Previously everything worked fine since a@{ ... } in impure.nix didn't have the value inNixShell (which gets passed to an expression in a shell.nix since 9d612c393abc3a73590650d24bcfe2ee57792872). Since inNixShel isn't defined in the argument-list of pkgs/top-level/default.nix and inNixShell gets passed to this function, the evaluation with nix-shell is breaking now.
I acknowledge that 626200713bb3cc844a9feb6af583c9b6b42c6dbc fixes an actual bug and shouldn't be reverted. However I'm not so sure what's the best solution for the kind of problem I described in this issue: the easiest fix for nixpkgs would be to remove inNixShell from the attr-set that gets passed to default.nix. However we should document the inNixShell-value at least. Also I'm wondering if we should catch this error and explain that inNixShell is most likely the cause.
cc @edolstra @glittershark
this kinda seems to me like nixpkgs is relying on incorrect behavior in nix. Could we just add an ellipsis to the function in pkgs/top-level/default.nix? that'd be backwards-compatible with current nix and also future-compatible with #3965
@glittershark that's what I've done in https://github.com/NixOS/nixpkgs/pull/97807. I think that we should document this here as well (and probably catch this kind of error just in case other setups are having it as well now) before closing this issue :)
Most helpful comment
this kinda seems to me like nixpkgs is relying on incorrect behavior in nix. Could we just add an ellipsis to the function in
pkgs/top-level/default.nix? that'd be backwards-compatible with current nix and also future-compatible with #3965