How to debug nix-channel --update failures

Hello everyone,

I am new to Nix and coming from the Gentoo world. For experimentation purposes I have created myself a small Alpine Linux based chroot environment and installed nix in a single-user mode, created the nixbld group and a few users and assigned them to the group, etc.

I have added a new channel using the nix-channel --add https://nixos.org/channels/nixpkgs-unstable nixpkgs command as a root user and I can run the nix-channel --list command just fine and getting back:

# nix-channel --list
nixpkgs https://nixos.org/channels/nixpkgs-unstable

However, when I am trying to perform nix-channel --update command it is failing with:

# nix-channel --update
unpacking channels...
error: executing '/usr/bin/nix-env': No such file or directory
error: program '/usr/bin/nix-env' failed with exit code 1

I have tried running the same command with increased verbosity, but that brings no additional useful information:

# nix-channel --update -vvv
acquiring write lock on '/nix/var/nix/temproots/34603'
using cache entry '{"name":"nixpkgs-unstable","type":"file","url":"https://nixos.org/channels/nixpkgs-unstable"}' -> '{"etag":"\"77f0c601cd8dc83026b799e0c86ee9b3\"","url":"https://releases.nixos.org/nixpkgs/nixpkgs-22.11pre391829.65fae659e31"}', '/nix/store/w8qy12xkz4dqh3lqv67l3xz97f6k0p58-nixpkgs-unstable'
using cache entry '{"name":"nixexprs.tar.xz","type":"file","url":"https://releases.nixos.org/nixpkgs/nixpkgs-22.11pre391829.65fae659e31/nixexprs.tar.xz"}' -> '{"etag":"\"7d10991d92af6e553c96dfa3feaa1bfb\"","url":"https://releases.nixos.org/nixpkgs/nixpkgs-22.11pre391829.65fae659e31/nixexprs.tar.xz"}', '/nix/store/ihlb46hffng5n3c2hz3ji9nwch3jshf1-nixexprs.tar.xz'
unpacking channels...
error: executing '/usr/bin/nix-env': No such file or directory
error: program '/usr/bin/nix-env' failed with exit code 1

How do I debug myself out of this problem? I am specifically looking for ways to get more information out of this failure, instead of trying various workarounds so that I can self-serve in the future and not just solve this one problem at hand (in other words: teach me to fish please, instead of giving me a fish!).

Any ideas are highly appreciated!

Do you have a nix-env? what does which nix-env say?

Hey @sullyj3!

I do have nix-env, indeed. I should have specified that before, sorry.

# which nix-env 
/usr/bin/nix-env
# nix-env --version
nix-env (Nix) 2.9.2

and just to make sure both nix-env and nix-channel have a consistent version:

# nix-channel --version
nix-channel (Nix) 2.9.2

The answer to this question was provided on Stack Overflow and TL;DR is that Nix uses setns() call that escapes the chroot environment and tries to call nix-env binary from the running host system, which is obviously not there.