I’m trying to understand some apparently magic behavior of nix-shell. I have following nix expression which relates to a gem file, here with fake name gem_name
:
{ lib, bundlerEnv, ruby }:
bundlerEnv rec {
name = "gem_name-${version}";
version = (import gemset).gem_name.version;
inherit ruby;
# expects Gemfile, Gemfile.lock and gemset.nix in the same directory
gemdir = ./.;
}
gemset.nix
has been generated through bundix
in the recommended way.
-
nix-shell
man page says it accepts a file with a nix expression defining a derivation. In fact, this file is not a derivation, but a function which if called with proper arguments defines a derivation. Reading at--arg
argument documentation I have deduced thatnix-shell
has some kind of autocall behavior when the expression defines a function. How does it exactly work in this case, where--arg
is not even provided? I haven’t found any documentation about it. -
If I run
nix-shell
I get an error:
error: undefined variable 'gemset' at /my/path/default.nix:6:21
However, if I run nix-shell -p <any_package>
, for example, nix-shell -p hello
it works. Reading at the docs, -p
just makes a package available in the shell. However, it seems that it also makes the import
to work.
- Which is the difference between
nix-shell -p package
andnix-shell -A attribute
? Isn’t-A
also used to load a package via its attribute?
Thanks for any insight