NixOS / nix

Nix, the purely functional package manager
https://nixos.org/
GNU Lesser General Public License v2.1
11.59k stars 1.45k forks source link

nix-shell no longer respects NIX_PATH #10246

Open SuperSandro2000 opened 4 months ago

SuperSandro2000 commented 4 months ago

Describe the bug

When running NIX_PATH=nixpkgs=https://github.com/nixos/nixpkgs/archive/nixos-unstable.tar.gz command nix-shell --option nix-path "" -p bash I am only greeted with

error:
       … while calling the 'import' builtin
         at «string»:1:18:
            1| {...}@args: with import <nixpkgs> args; (pkgs.runCommandCC or pkgs.runCommand) "shell" { buildInputs = [ (bash) ]; } ""
             |                  ^

       … while realising the context of a path

       … while calling the 'findFile' builtin
         at «string»:1:25:
            1| {...}@args: with import <nixpkgs> args; (pkgs.runCommandCC or pkgs.runCommand) "shell" { buildInputs = [ (bash) ]; } ""
             |                         ^

       error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I)

but command nix-shell --option nix-path nixpkgs=https://github.com/SuperSandro2000/nixpkgs/archive/nixos-unstable.tar.gz -p bash works as expected

Steps To Reproduce

  1. Run NIX_PATH=nixpkgs=https://github.com/nixos/nixpkgs/archive/nixos-unstable.tar.gz command nix-shell --option nix-path "" -p bash

Expected behavior

It should work as it did with 2.20 or 2.18.

nix-env --version output nix-env (Nix) 2.21.0

Additional context

Add any other context about the problem here.

Priorities

Add :+1: to issues you find important.

thufschmitt commented 4 months ago

Did it use to work?

This looks like the broken semantics “documented” in https://github.com/NixOS/nix/pull/9066

(not saying it's not an issue, just clarifying whether this is the same old bug or a real regression)

SuperSandro2000 commented 4 months ago

Did it use to work?

As soon as I switch back to 2.20 or 2.18 by changing nix.package it starts to work again.

thufschmitt commented 4 months ago

Weird, I can reproduce that for every Nix version >= 2.4 (2.3 works, but that's just because it doesn't have the nix-path setting)

nasrally commented 2 months ago

I see identical behavior on 2.18.1.

NIX_PATH is completely ignored by nix-shell yet it is present in the environment variables, I can see it in /proc/PID/environ, defining the nix-path setting in either /etc/nix/nix.conf (through NixOS), $HOME/.config/nix/nix.conf (through HM) or --option nix-path nixpkgs=... DOES WORK.

Maybe important context that makes this unrelated — it started doing that after I disabled channels on NixOS with nix.channel.enable = false (because I want complete flakification)

con-f-use commented 1 month ago

Maybe important context that makes this unrelated — it started doing that after I disabled channels on NixOS with nix.channel.enable = false (because I want complete flakification)

Same with me. @nasrally , do you have any workaround, except nix-shell -I nixpkgs=...?