- Sep 2021
- May 2021
The command nix-shell will build the dependencies of the specified derivation, but not the derivation itself. It will then start an interactive shell in which all environment variables defined by the derivation path have been set to their corresponding values, and the script $stdenv/setup has been sourced. This is useful for reproducing the environment of a derivation for development.
QUESTION: What exactly does
nix-shellexecute from the Nix expression (i.e.,
ANSWER: Based on my current understanding, the answer is everything. It calls
$stdenv/setup(see annotation below) to set up the most basic environment variables (TODO: expand on this), and "injects" the most common tools (e.g.,
sed) into it.
source $stdenv/setup genericBuild
pkgs/stdenv/generic/builder.shis a mystery though.
QUESTION: Once dropping into
nix-shell, how do I know what phases to execute by looking at a
ANSWER: As far as I can tell, one can override the phases in their Nix build expression (to build the derivation, see at the bottom), but they won't get executed as only the
$stdenv/setup(see above) will get sourced, and no builders are called that, in return, invoke the phases (again, see above).
So if one is using
to create/hack on a package, the person has to manually invoke the builder or phases (TODO: still fuzzy on this subject)
to set up an environment, then one doesn't even have to worry about builders/phases because we just use
nix-shellto clear the environment and to inject tools that we need for a given task
QUESTION: When dropping into
nix-shell, is this Nix expression (i.e.,
freeswitch/default.nix) executed? Or just parts of it?
ANSWER: As stated above, all of the input Nix expression is evaluated, but no builders and build phases are called; although, nothing prevents one to override the phases, in case they are creating/hacking on a package.
nix-shellwill build the dependencies of the specified derivation, but not the derivation itself.
What is the "derivation" here exactly? I know that it is a build expression, but does that mean the
default.nix(or other Nix expression)
nix-shellis invoked with?
<sup>This statement also seems like a contradiction with how `nix-shell` works (i.e., if one issues `nix-shell -p curl`, then `curl` will be available in that sub-shell), but `-p` acts like a shortcut to as if `curl` had been listed in `buildInputs` so this is not the case.</sup>
ANSWER: I have the feeling my confusion comes from the fact that the term "derivation" is used ambiguously in the manuals, sometimes to mean multiple things (see list below).
TODO: Substantiate this claim, and make sure that it not coming from my misunderstanding certain topics.
Nix build expression (such as
default.nix) whose output is going to become the store derivation itself (see last item at the bottom about the Nix manual's glossary definition)
Had multiple cracks at unambiguously define what a derivation is, and here's a list of these:
What is the purpose of nix-instantiate? What is a store-derivation? (probably the best try yet)
What is a Nix expression in regard to Nix package management? (feels sloppier, but commenter mentions
ATerm, adding the possibility of making it very specific)
Closure vs derivation in the Nix package manager (very short, and will have to be re-written, but adds closures to the mix)
There is now a glossary definition of a derivation in the Nix manual; see this annotation why I find it problematic
QUESTION: What is the difference between
nix-shellinvoked with a Nix expression of
mkShell(or other that achieves the similar effect)?
nix-shelldoes not create a sub-shell, so what does it do? (clarification: so
nix-shellindeed does it; I confused it with
- Mar 2021
- Feb 2021
example: get an environment which is used to build irssi (also see nix-shell) $ nix-build $NIXPKGS --run-env -A irssi example: get a persistent environment which is used to build irssi $ nix-build $NIXPKGS --run-env -A irssi --add-root
nix-build <path> --run-envhas been superseded by
nix-shell. From Nix manual section C.12. Release 1.6 (2013-09-10):
nix-build --run-envhas been renamed to
C.12. Release 1.6 (2013-09-10)In addition to the usual bug fixes, this release has several new features:The command nix-build --run-env has been renamed to nix-shell.
- Jul 2020
The most commonly supported tool for this is kerl. Kerl is a wrapper around downloading, compiling, and loading various Erlang/OTP versions on a single system, and will abstract away most annoying operations.
Or use the Nix package manager's
- Dec 2018