Do I fundamentally have a misunderstanding of how these commands should work? or, is there something else going on? And is there a way I can have these commands behave as expected?
As meantioned in the discord earlier today, it doesn’t really make sense on the first glance, though on the second it might be related to the different ways how nix-env and the rest of the nix ecosystem treat channels.
Can you please share the output of each of these commands?
This supports my claim of the different behaviour between nix-env and the rest of the nix-world.
nix-env looks in ~/.nix-defexpr and only there, unless -f is provided.
Though the rest of the world uses NIX_PATH to resolve. They will look up in /nix/var/nix/profiles/per-user/root/channels first, and if they find a folder nixpgs there, they will not search further.
So your roots channels “win” when you do nix-shell, while nix-env doesn’t consider them.
Try nix-shell -I nixpkgs=/Users/glenn/.nix-defexpr/channels/nixpkgs -p "ruby_3_1" --run "which ruby" to enforce usage of the users channel.
Alternatively you should be able to do nix-env -f '<nixpkgs>' -qaP 'ruby.*' to actually search the channels of root, as -f '<nixpkgs>' enforces NIX_PATH resolution.
The rails version mismatch is probably because of the channel mismatches as well, and versions would congruent if usage of same channel locations is enforced.
Oh my… seems crazy to me… but, you are correct, that invocation of nix-shell does install the correct version of ruby. Thanks again, that was very enlightening.