lix/tests
Maximilian Bosch 98946e2d9c
nix-shell: restore backwards-compat with old nixpkgs
Basically an attempt to resume fixing #5543 for a breakage introduced
earlier[1]. Basically, when evaluating an older `nixpkgs` with
`nix-shell` the following error occurs:

    λ ma27 [~] → nix-shell -I nixpkgs=channel:nixos-18.03 -p nix
    error: anonymous function at /nix/store/zakqwc529rb6xcj8pwixjsxscvlx9fbi-source/pkgs/top-level/default.nix:20:1 called with unexpected argument 'inNixShell'

           at /nix/store/zakqwc529rb6xcj8pwixjsxscvlx9fbi-source/pkgs/top-level/impure.nix:82:1:

               81|
               82| import ./. (builtins.removeAttrs args [ "system" "platform" ] // {
                 | ^
               83|   inherit config overlays crossSystem;

This is a problem because one of the main selling points of Nix is that
you can evaluate any old Nix expression and still get the same result
(which also means that it *still evaluates*). In fact we're deprecating,
but not removing a lot of stuff for that reason such as unquoted URLs[2]
or `builtins.toPath`. However this property was essentially thrown away
here.

The change is rather simple: check if `inNixShell` is specified in the
formals of an auto-called function. This means that

    { inNixShell ? false }:
    builtins.trace inNixShell
      (with import <nixpkgs> { }; makeShell { name = "foo"; })

will show `trace: true` while

    args@{ ... }:
    builtins.trace args.inNixShell
      (with import <nixpkgs> { }; makeShell { name = "foo"; })

will throw the following error:

    error: attribute 'inNixShell' missing

This is explicitly needed because the function in
`pkgs/top-level/impure.nix` of e.g. NixOS 18.03 has an ellipsis[3], but
passes the attribute-set on to another lambda with formals that doesn't
have an ellipsis anymore (hence the error from above). This was perhaps
a mistake, but we can't fix it anymore. This also means that there's
AFAICS no proper way to check if the attr-set that's passed to the Nix
code via `EvalState::autoCallFunction` is eventually passed to a lambda
with formals where `inNixShell` is missing.

However, this fix comes with a certain price. Essentially every
`shell.nix` that assumes `inNixShell` to be passed to the formals even
without explicitly specifying it would break with this[4]. However I think
that this is ugly, but preferable:

* Nix 2.3 was declared stable by NixOS up until recently (well, it still
  is as long as 21.11 is alive), so most people might not have even
  noticed that feature.

* We're talking about a way shorter time-span with this change being
  in the wild, so the fallout should be smaller IMHO.

[1] 9d612c393a
[2] https://github.com/NixOS/rfcs/pull/45#issuecomment-488232537
[3] https://github.com/NixOS/nixpkgs/blob/release-18.03/pkgs/top-level/impure.nix#L75
[4] See e.g. the second expression in this commit-message or the changes
    for `tests/ca/nix-shell.sh`.
2022-06-13 23:29:28 +02:00
..
ca
config
lang
plugins
add.sh
bad.tar.xz
bash-profile.sh
big-derivation-attr.nix
binary-cache-build-remote.sh
binary-cache.sh
brotli.sh
build-dry.sh Fix nix build --dry-run with CA derivations 2022-03-17 11:55:19 +01:00
build-hook-ca-fixed.nix
build-hook-ca-floating.nix
build-hook.nix
build-remote-content-addressed-fixed.sh
build-remote-content-addressed-floating.sh
build-remote-input-addressed.sh
build-remote.sh
build.sh
ca-shell.nix nix-shell: restore backwards-compat with old nixpkgs 2022-06-13 23:29:28 +02:00
case-hack.sh
case.nar
check-refs.nix
check-refs.sh
check-reqs.nix
check-reqs.sh Restore old (dis)allowedRequisites behaviour for self-references 2018-10-27 15:41:53 +02:00
check.nix
check.sh
common.sh.in tests/lang: Distinguish crashes from expected failures 2022-05-02 15:12:50 +02:00
compression-levels.sh
compute-levels.sh
config.nix.in
config.sh
db-migration.sh
dependencies.builder0.sh
dependencies.nix
dependencies.sh
describe-stores.sh
dummy
dump-db.sh
eval-store.sh
eval.nix
eval.sh
export-graph.nix
export-graph.sh
export.sh
failing.nix
fetchClosure.sh
fetchGit.sh
fetchGitRefs.sh
fetchGitSubmodules.sh
fetchMercurial.sh
fetchPath.sh
fetchTree-file.sh Typo 2022-06-02 21:21:10 +02:00
fetchurl.sh
filter-source.nix
filter-source.sh
fixed.builder1.sh
fixed.builder2.sh
fixed.nix
fixed.sh
flake-bundler.sh
flake-local-settings.sh
flake-searching.sh
flakes-run.sh
flakes.sh
fmt.sh Fix 'nix fmt' test 2022-04-19 21:47:13 +02:00
fmt.simple.sh
function-trace.sh
gc-auto.sh
gc-concurrent.builder.sh
gc-concurrent.nix
gc-concurrent.sh
gc-concurrent2.builder.sh
gc-non-blocking.sh
gc-runtime.nix
gc-runtime.sh
gc.sh
github-flakes.nix
hash-check.nix
hash.sh
import-derivation.nix
import-derivation.sh
impure-derivations.nix
impure-derivations.sh
init.sh
install-darwin.sh docs+test: fix remaining installer downloads without -L (#4006) 2020-09-12 22:08:40 +02:00
lang.sh
linux-sandbox.sh
local-store.sh
local.mk
logging.sh
misc.sh Change error position formatting 2021-01-21 11:02:09 +01:00
multiple-outputs.nix
multiple-outputs.sh
nar-access.nix
nar-access.sh
nix-build-examples.nix
nix-build.sh
nix-channel.sh
nix-copy-closure.nix
nix-copy-ssh.sh Fix test failures when $TMPDIR changes 2019-06-15 16:36:33 +02:00
nix-profile.sh
nix-shell.sh nix-shell: restore backwards-compat with old nixpkgs 2022-06-13 23:29:28 +02:00
nix_path.sh
nss-preload.nix
optimise-store.sh
parallel.builder.sh
parallel.nix
parallel.sh
pass-as-file.sh
path.nix
placeholders.sh Fix test failures when $TMPDIR changes 2019-06-15 16:36:33 +02:00
plugins.sh
post-hook.sh
pure-eval.nix
pure-eval.sh Properly return false on builtins.pathExists /someNonAllowedPath 2021-12-23 10:49:33 +01:00
push-to-store.sh
readfile-context.builder.sh
readfile-context.nix
readfile-context.sh
recursive.sh
referrers.sh
remote-builds.nix
remote-store.sh
repair.sh Make --repair-path also repair corrupt optimised links 2022-01-11 11:57:45 +01:00
repl.sh
restricted.nix Add pure evaluation mode 2018-01-16 19:23:18 +01:00
restricted.sh nix: Add --expr flag 2019-11-27 00:05:30 +01:00
search.nix tests: test nix search behavior 2018-02-25 16:40:05 -06:00
search.sh Use grep -c instead of grep|wc -l in some nix search tests 2022-06-07 18:25:59 +02:00
secure-drv-outputs.nix
secure-drv-outputs.sh
selfref-gc.sh
setuid.nix
shell-hello.nix
shell.nix
shell.sh
shell.shebang.rb
shell.shebang.sh
signing.sh
simple-failing.nix
simple.builder.sh
simple.nix
simple.sh
sourcehut-flakes.nix fix sourcehut brach/tag resolving regression 2022-06-11 16:52:20 -03:00
ssh-relay.sh
store-ping.sh
structured-attrs-shell.nix
structured-attrs.nix
structured-attrs.sh
substitute-with-invalid-ca.sh Check the CA hash when importing stuff in the local store 2021-06-01 15:09:24 +02:00
suggestions.sh
tarball.sh
timeout.nix
timeout.sh
undefined-variable.nix
user-envs.builder.sh
user-envs.nix
user-envs.sh
why-depends.sh
zstd.sh