mherzl
mherzl

Reputation: 6220

What is the "active Nix expression"?

I notice that descriptions of various nixos commands refer to something called the "active Nix expression". For example, the man page for nix-env includes:

   --file / -f path
       Specifies the Nix expression (designated below as the active Nix expression) used by the --install, --upgrade, and --query
       --available operations to obtain derivations. The default is ~/.nix-defexpr.

What is this "active Nix expression"? Where is it defined? Is it simply what is written in /etc/nixos/configuration.nix ordinarily or instead what was defined by nix-shell otherwise?

Upvotes: 2

Views: 189

Answers (1)

Charles Duffy
Charles Duffy

Reputation: 295696

This is the file from which the Nix expression in which any attribute specified with -A is evaluated. (Absent -A, that content is expected to directly be a derivation).

Let's say you have a mydir/default.nix file that evaluates to an attrset with keys foo, bar, and baz, each of which maps to a derivation as a value.

In this case, running nix-env -f mydir -iA foo will load mydir/default.nix, evaluate foo in the context of that loaded code, run any associated build steps, and add that software to your active environment.

Upvotes: 4

Related Questions