Describe the issue
Executing file with shebang #!/usr/bin/env nix-shell from a working directory that contains shell.nix file results in error: getting status of '/home/user/marco/polo/shell.nix': No such file or directory
Steps To Reproduce
- Create a new directory called e.g.
~/marco
- Create a new file called
~/marco/shell.nix
- Create a new file in
~/marco/polo/default.nix with content (shebang is important):
#!/usr/bin/env nix-shell
{ pkgs ? import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/360d65e180403b940afcc93d68d5329488af14eb.tar.gz") {} }:
with nixpkgs;
stdenv.mkDerivation {
name = "Polo";
shellHook = ''
printf "\\n%s\\n" "Polo"
'';
}
- Make the
~/marco/polo/default.nix executable and execute it while the working directory is set to ~/marco and expect:
[kreyren@leonid:~/marco]$ ./polo/default.nix
error: getting status of '/home/user/marco/polo/shell.nix': No such file or directory
- Remove the
shell.nix file from ~/marco/shell.nix and notice that the ./polo/default.nix now works
Expected behavior
Successfully execute ./polo/default.nix from working directory that contains shell.nix
Additional context
Relevant Matrix discussion
In #nixos:nixos.org: https://matrix.to/#/!KqkRjyTEzAGRiZFBYT:nixos.org/$r5T9u3PIkI5SoGEB9SKKj9XEdtic36zf3rS5lW_-bh0?via=nixos.org&via=matrix.org&via=nixos.dev
Works with -v argument
Using /usr/bin/env nix-shell -v ./polo/default.nix and/or nix-shell -v ./polo/default.nix is not affected by the presence of shell.nix file in the working directory.
Motivation
Usage of nix to deploy standard environment in complicated monorepositories where the mentioned issue creates a complications like adapting a repository management in https://git.dotya.ml/RiXotStudio/RiXotStudio/src/commit/8e1c76835eec3d41c726eafe02b41487c6c324bb that executes ./20-editors/vscodium/nix/default.nix to provide an environment with standard vscodium which results in
[kreyren@leonid:~/Repositories/RiXotStudio]$ ./20-editors/vscodium/nix/default.nix
error: getting status of '/home/kreyren/Repositories/RiXotStudio/20-editors/vscodium/nix/shell.nix': No such file or directory
and requires additional steps to change directory and checking for the presence of shell.nix file
Metadata
Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.
[kreyren@leonid:~]$ nix-shell -p nix-info --run "nix-info -m"
- system: `"x86_64-linux"`
- host os: `Linux 5.10.64, NixOS, 21.05.3915.95eed9b64ee (Okapi)`
- multi-user?: `yes`
- sandbox: `yes`
- version: `nix-env (Nix) 2.4pre20211006_53e4794`
- channels(root): `"nixos-21.05.3915.95eed9b64ee"`
- channels(kreyren): `"home-manager-21.05, master, nixos-21.05.3915.95eed9b64ee"`
- nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`
Describe the issue
Executing file with shebang
#!/usr/bin/env nix-shellfrom a working directory that containsshell.nixfile results inerror: getting status of '/home/user/marco/polo/shell.nix': No such file or directorySteps To Reproduce
~/marco~/marco/shell.nix~/marco/polo/default.nixwith content (shebang is important):~/marco/polo/default.nixexecutable and execute it while the working directory is set to~/marcoand expect:shell.nixfile from~/marco/shell.nixand notice that the./polo/default.nixnow worksExpected behavior
Successfully execute
./polo/default.nixfrom working directory that containsshell.nixAdditional context
Relevant Matrix discussion
In
#nixos:nixos.org: https://matrix.to/#/!KqkRjyTEzAGRiZFBYT:nixos.org/$r5T9u3PIkI5SoGEB9SKKj9XEdtic36zf3rS5lW_-bh0?via=nixos.org&via=matrix.org&via=nixos.devWorks with
-vargumentUsing
/usr/bin/env nix-shell -v ./polo/default.nixand/ornix-shell -v ./polo/default.nixis not affected by the presence ofshell.nixfile in the working directory.Motivation
Usage of nix to deploy standard environment in complicated monorepositories where the mentioned issue creates a complications like adapting a repository management in https://git.dotya.ml/RiXotStudio/RiXotStudio/src/commit/8e1c76835eec3d41c726eafe02b41487c6c324bb that executes
./20-editors/vscodium/nix/default.nixto provide an environment with standard vscodium which results inand requires additional steps to change directory and checking for the presence of
shell.nixfileMetadata
Please run
nix-shell -p nix-info --run "nix-info -m"and paste the result.