Nix (package manager)/zh: Difference between revisions

FuzzyBot (talk | contribs)
m FuzzyBot moved page Nix package manager/zh to Nix (package manager)/zh without leaving a redirect: Part of translatable page "Nix package manager"
FuzzyBot (talk | contribs)
Updating to match new version of source page
Line 1: Line 1:
Nix是一个包管理器和构建系统, 解析用 [[Nix Expression Language|Nix表达式语言]] (惰性求值的纯函数式语言) 指定的可再现的构建指令. Nix表达式是纯函数<ref>计算过程中,值不可改变. 当函数的输入不变时,函数总是输出相同的结果. </ref>, 接受依赖作为参数,并为包产生一个指定了可再现的构建环境的 ''[[Derivations|derivation]]'' . Nix把构建的结果存储在由完整依赖树的哈希值指定的唯一地址中, 创建了一个不可变的包存储 (即[[#Nix store|nix存储]]), 这使得原子升级, 回滚, 以及不同版本的包的同时安装成为可能, 从根本上消除了[https://en.wikipedia.org/wiki/Dependency_hell 依赖地狱].  
<languages/>
<div class="mw-translate-fuzzy">
Nix是一个包管理器和构建系统, 解析用 [[Nix Expression Language|Nix表达式语言]] (惰性求值的纯函数式语言) 指定的可再现的构建指令. Nix表达式是纯函数<ref>计算过程中,值不可改变. 当函数的输入不变时,函数总是输出相同的结果. </ref>, 接受依赖作为参数,并为包产生一个指定了可再现的构建环境的 ''[[Derivations|derivation]]'' . Nix把构建的结果存储在由完整依赖树的哈希值指定的唯一地址中, 创建了一个不可变的包存储 (即[[#Nix store|nix存储]]), 这使得原子升级, 回滚, 以及不同版本的包的同时安装成为可能, 从根本上消除了[https://en.wikipedia.org/wiki/Dependency_hell 依赖地狱].
</div>


<span id="Usage"></span>
<span id="Usage"></span>
== 用法 ==
== 用法 ==


<div class="mw-translate-fuzzy">
=== 安装 ===
=== 安装 ===
NixOS: 当你在安装NixOS时, Nix就已经安装好了.
NixOS: 当你在安装NixOS时, Nix就已经安装好了.
</div>


<div class="mw-translate-fuzzy">
如果你想在另一个Linux发行版或一台Mac电脑上使用Nix, 你可以进行独立安装: [https://nixos.org/manual/nix/stable/installation/installation Nix手册的安装部分]讲述了从二进制文件或源代码的独立的Nix安装过程
如果你想在另一个Linux发行版或一台Mac电脑上使用Nix, 你可以进行独立安装: [https://nixos.org/manual/nix/stable/installation/installation Nix手册的安装部分]讲述了从二进制文件或源代码的独立的Nix安装过程
</div>


<span id="Nix_commands"></span>
<span id="Nix_commands"></span>
=== Nix命令 ===
=== Nix命令 ===


<div class="mw-translate-fuzzy">
[[Nix command|Nix命令]]被记录在[https://nixos.org/manual/nix/stable/command-ref/command-ref Nix参考手册]: 主要命令, 工具命令和实验性命令. 在2.0版本(于2018年2月发布)之前, 命令有所不同.
[[Nix command|Nix命令]]被记录在[https://nixos.org/manual/nix/stable/command-ref/command-ref Nix参考手册]: 主要命令, 工具命令和实验性命令. 在2.0版本(于2018年2月发布)之前, 命令有所不同.
</div>


<div class="mw-translate-fuzzy">
=== 配置 ===
=== 配置 ===
在NixOS上, Nix通过[https://search.nixos.org/options?query=nix. <code>nix</code> 选项]进行配置.  
在NixOS上, Nix通过[https://search.nixos.org/options?query=nix. <code>nix</code> 选项]进行配置.
</div>


独立的Nix的配置需要通过<code>nix.conf</code> (通常位于 <code>/etc/nix/</code>), 它定义了一系列和求值,构建,垃圾回收,沙盒,以及用户权限的设置. 这些可用选项的细节可在[https://nixos.org/manual/nix/stable/command-ref/conf-file Nix参考手册]中找到.  
<div class="mw-translate-fuzzy">
独立的Nix的配置需要通过<code>nix.conf</code> (通常位于 <code>/etc/nix/</code>), 它定义了一系列和求值,构建,垃圾回收,沙盒,以及用户权限的设置. 这些可用选项的细节可在[https://nixos.org/manual/nix/stable/command-ref/conf-file Nix参考手册]中找到.
</div>


单用户可使用 [[Home Manager]] 进一步配置对声明式环境的管理. 对于Linux上的系统级配置, 你可以使用 System Manager. 对于macOS上的系统级配置, nix-darwin 是更佳的解决方案.
<div class="mw-translate-fuzzy">
单用户可使用 [[Home Manager]] 进一步配置对声明式环境的管理. 对于Linux上的系统级配置, 你可以使用 System Manager. 对于macOS上的系统级配置, nix-darwin 是更佳的解决方案.
</div>


<span id="Internals"></span>
<span id="Internals"></span>
Line 27: Line 42:
=== Nix store(Nix存储库) ===
=== Nix store(Nix存储库) ===


由Nix构建的包被放在只读的''Nix存储库'', 通常位于<code>/nix/store</code>. 每个包会被赋予一个由加密hash值指定的独一无二的地址, 该地址位于包的名称和版本之后, 例如<code>/nix/store/nawl092prjblbhvv16kxxbk6j9gkgcqm-git-2.14.1</code>. 这些前缀的哈希处理使用到了对构建过程的所有输入, 包括源文件, 完整依赖关系树, 编译器标志, 等等. 这让Nix可以同时安装同一个包的不同版本, 甚至同一版本的不同构建, 比如由不同的编译器构建的变体. 当添加, 移除, 或者更新一个包时, 什么都没有从Nix存储库中被移除; 作为替代,指向这些包的符号链接在''profile''中被添加, 移除或者修改.
<div lang="en" dir="ltr" class="mw-content-ltr">
{{Split|reason=The nix store is conceptually separate enough that it warrants a separate article.}}
</div>
 
<div lang="en" dir="ltr" class="mw-content-ltr">
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''.
</div>
 
<div lang="en" dir="ltr" class="mw-content-ltr">
==== Cleaning the Nix store ====
</div>
 
<div lang="en" dir="ltr" class="mw-content-ltr">
For information relating to cleaning the Nix store, refer to {{NixOS Manual|name=NixOS Manual: Chapter - Cleaning the Nix Store|anchor=#sec-nix-gc}}.
</div>
 
<div lang="en" dir="ltr" class="mw-content-ltr">
==== Nix store corruption ====
</div>
 
<div lang="en" dir="ltr" class="mw-content-ltr">
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}}.
</div>
 
<div lang="en" dir="ltr" class="mw-content-ltr">
==== Valid Nix store names ====
</div>
 
<div lang="en" dir="ltr" class="mw-content-ltr">
{{main|Valid Nix store path names}}
</div>


<span id="Profiles"></span>
<span id="Profiles"></span>