NixOS / nix

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

[regression] `#! nix-shell -p 'callPackage (import ./my_package.nix) {}'` broken in Nix 2.24 #11892

Closed CyberShadow closed 6 days ago

CyberShadow commented 1 week ago

Describe the bug

I used to be able to write a self-contained nix-shell script that referenced a package definition, for example:

#!/usr/bin/env nix-shell
#! nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/bff917a3ed37b1f9e705b5c07210acd295691770.tar.gz
#! nix-shell -p 'callPackage (import ./my_package.nix) {}'

true

In 2.24 and the current Nix master, this fails with:

~/nix-test $ ./test.sh
error:
       … while calling the 'derivationStrict' builtin
         at <nix/derivation-internal.nix>:34:12:
           33|
           34|   strict = derivationStrict drvAttrs;
             |            ^
           35|

       … while evaluating derivation 'shell'
         whose name attribute is located at /nix/store/l3bc30i71qshxa3mdj3dy8dj7zwqkh6s-source/pkgs/stdenv/generic/make-derivation.nix:300:7

       … while evaluating attribute 'buildInputs' of derivation 'shell'
         at /nix/store/l3bc30i71qshxa3mdj3dy8dj7zwqkh6s-source/pkgs/stdenv/generic/make-derivation.nix:347:7:
          346|       depsHostHost                = lib.elemAt (lib.elemAt dependencies 1) 0;
          347|       buildInputs                 = lib.elemAt (lib.elemAt dependencies 1) 1;
             |       ^
          348|       depsTargetTarget            = lib.elemAt (lib.elemAt dependencies 2) 0;

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: path '/home/vladimir/nix-test/{...}@args: with import <nixpkgs> args; (pkgs.runCommandCC or pkgs.runCommand) "shell" { buildInputs = [ (callPackage (import ./my_package.nix) {}) ]; } ""/my_package.nix' does not exist

Nix now seems to try to construct a non-sensical path by concatenating the auto-generated shell expression with /my_package.nix.

nix-env --version output

nix-env (Nix) 2.24.0pre20240706_4c59d6e

Additional context

The regression seems to have been introduced in https://github.com/NixOS/nix/pull/11058.

Priorities

Add :+1: to issues you find important.

nixos-discourse commented 1 week ago

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2024-11-18-nix-team-meeting-minutes-195/56229/1