On other Linux distributions or on macOS, you can install Nix following the [https://nixos.org/manual/nix/stable/installation/installation installation section of the Nix manual].
</div>
<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Nix_commands"></span>
=== Nix commands ===
=== Nix命令 ===
</div>
<div lang="en" dir="ltr" class="mw-content-ltr">
[[Nix (command line utilities)|Nix命令]]在[https://nixos.org/manual/nix/stable/command-ref/command-ref Nix参考手册]中有详细说明,分为主要命令、工具命令和实验性命令。在2.0版本(发布于2018年2月)之前,命令有所不同。
The [[Nix (command line utilities)|Nix commands]] are documented in the [https://nixos.org/manual/nix/stable/command-ref/command-ref Nix reference manual]: main commands, utilities and experimental commands. Prior to version 2.0 (released in February 2018) there have been different commands.
Standalone Nix is configured through <code>nix.conf</code> (usually found in <code>/etc/nix/</code>). Details on the available options are [https://nixos.org/manual/nix/stable/command-ref/conf-file found in the Nix reference manual].
You can also configure Nix using [[Home Manager]], which manages declarative environments for a single user. For system-wide configuration, you can use [https://github.com/numtide/system-manager System Manager] on Linux and [https://github.com/LnL7/nix-darwin nix-darwin] on macOS.
</div>
<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Internals"></span>
== Internals ==
== 内部细节 ==
</div>
<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Nix_store"></span>
=== Nix store ===
=== Nix存储(Nix store) ===
</div>
<div lang="en" dir="ltr" class="mw-content-ltr">
{{Split|reason=Nix存储在概念上足够独立,有必要单独成文。}}
{{Split|reason=The nix store is conceptually separate enough that it warrants a separate article.}}
Packages built by Nix are placed in the read-only ''Nix store'', normally found in <code>/nix/store</code>. Each package is given a unique address specified by a cryptographic hash followed by the package name and version, for example <code>/nix/store/nawl092prjblbhvv16kxxbk6j9gkgcqm-git-2.14.1</code>. These prefixes hash all the inputs to the build process, including the source files, the full dependency tree, compiler flags, etc. This allows Nix to simultaneously install different versions of the same package, and even different builds of the same version, for example variants built with different compilers. When adding, removing or updating a package, nothing is removed from the store; instead, symlinks to these packages are added, removed or changed in ''profiles''.
For information relating to fixing a corrupted Nix store, refer to {{NixOS Manual|name=NixOS Manual: Chapter - Nix Store Corruption|anchor=#sec-nix-store-corruption}}.
In order to construct a coherent user or system environment, Nix symlinks entries of the Nix store into ''profiles''. These are the front-end by which Nix allows rollbacks: since the store is immutable and previous versions of profiles are kept, reverting to an earlier state is simply a matter of change the symlink to a previous profile. To be more precise, Nix symlinks binaries into entries of the Nix store representing the user environments. These user environments are then symlinked into labeled profiles stored in <code>/nix/var/nix/profiles</code>, which are in turn symlinked to the user's <code>~/.nix-profile</code>.
When sandbox builds are enabled, Nix will setup an isolated environment for each build process. It is used to remove further hidden dependencies set by the build environment to improve reproducibility. This includes access to the network during the build outside of <code>fetch*</code> functions and files outside the Nix store. Depending on the operating system access to other resources are blocked as well (ex. inter process communication is isolated on Linux); see [https://nixos.org/nix/manual/#sec-conf-file nix.conf section] in the Nix manual for details.
</div>
<div lang="en" dir="ltr" class="mw-content-ltr">
沙盒化在Linux上默认启用,在macOS上默认禁用。
Sandboxing is enabled by default on Linux, and disabled by default on macOS.
Nixpkgs的拉取请求(pull requests)中,要求在沙盒化启用条件下测试构建(见拉取请求模板中的<code>Tested using sandboxing</code>),因为在[https://nixos.org/hydra/ 官方Hydra构建]中使用了沙盒化。
In pull requests for [https://github.com/NixOS/nixpkgs/ Nixpkgs] people are asked to test builds with sandboxing enabled (see <code>Tested using sandboxing</code> in the pull request template) because in [https://nixos.org/hydra/ official Hydra builds] sandboxing is also used.
To configure Nix for sandboxing, set <code>sandbox = true</code> in <code>/etc/nix/nix.conf</code>; to configure NixOS for sandboxing set <code>nix.useSandbox = true;</code> in <code>configuration.nix</code>. The <code>nix.useSandbox</code> option is <code>true</code> by default since NixOS 17.09.
</div>
<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Alternative_Interpreters"></span>
=== Alternative Interpreters ===
=== 可选的解释器 ===
</div>
<div lang="en" dir="ltr" class="mw-content-ltr">
一项用Rust从零开始重新实现Nix的工作正在进行。
There is an ongoing effort to reimplement Nix, from the ground up, in Rust.
There is also a community-led fork of Nix 2.18 named Lix, focused on correctness, usability, and growth. While it has also ported some components of Nix to Rust, it is not a ground-up rewrite like Tvix.
</div>
<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 122:
Line 79:
</div>
</div>
<div lang="en" dir="ltr" class="mw-content-ltr">
更早的尝试可在riir-nix找到
Earlier attempts can be found on [https://riir-nix.github.io/ riir-nix]
Home Manager为单一用户管理声明式环境,也可用于配置Nix。对于系统级配置,可在Linux上使用System Manager,在macOS上使用nix-darwin。
内部细节
Nix存储(Nix store)
↱︎
This section is a candidate for splitting off into a separate article. Nix存储在概念上足够独立,有必要单独成文。 For more information, consult the related discussion page.