mirror of
https://github.com/NixOS/nix.git
synced 2025-10-24 03:13:24 +08:00
This is needed to avoid this https://github.com/mesonbuild/meson/issues/13774 when we go back to making our subproject directory `src`.
2.5 KiB
2.5 KiB
Default Nix expression
The source for the Nix expressions used by nix-env by default:
~/.nix-defexpr$XDG_STATE_HOME/nix/defexprifuse-xdg-base-directoriesis set totrue.
It is loaded as follows:
- If the default expression is a file, it is loaded as a Nix expression.
- If the default expression is a directory containing a
default.nixfile, thatdefault.nixfile is loaded as a Nix expression. - If the default expression is a directory without a
default.nixfile, then its contents (both files and subdirectories) are loaded as Nix expressions. The expressions are combined into a single attribute set, each expression under an attribute with the same name as the original file or subdirectory. Subdirectories without adefault.nixfile are traversed recursively in search of more Nix expressions, but the names of these intermediate directories are not added to the attribute paths of the default Nix expression.
Then, the resulting expression is interpreted like this:
- If the expression is an attribute set, it is used as the default Nix expression.
- If the expression is a function, an empty set is passed as argument and the return value is used as the default Nix expression.
Example
If the default expression contains two files,
foo.nixandbar.nix, then the default Nix expression will be equivalent to{ foo = import ~/.nix-defexpr/foo.nix; bar = import ~/.nix-defexpr/bar.nix; }
The file manifest.nix is always ignored.
The command nix-channel places a symlink to the current user's channels in this directory, the user channel link.
This makes all subscribed channels available as attributes in the default expression.
User channel link
A symlink that ensures that nix-env can find the current user's channels:
~/.nix-defexpr/channels$XDG_STATE_HOME/defexpr/channelsifuse-xdg-base-directoriesis set totrue.
This symlink points to:
$XDG_STATE_HOME/profiles/channelsfor regular users$NIX_STATE_DIR/profiles/per-user/root/channelsforroot
In a multi-user installation, you may also have ~/.nix-defexpr/channels_root, which links to the channels of the root user.