Nix (package manager)/zh: Difference between revisions
No edit summary Tags: Mobile edit Mobile web edit |
Created page with "Category:Pedias Category:Nix Category:Incomplete Category:Software" |
||
(15 intermediate revisions by the same user not shown) | |||
Line 15: | Line 15: | ||
=== Nix 命令 === | === Nix 命令 === | ||
[[Nix (command line utilities)|Nix 命令]]在[https://nixos.org/manual/nix/stable/command-ref/command-ref Nix 参考手册]中有详细记录:主要命令,工具命令和实验性命令。在 2.0 版本(于 2018 年 2 月发布)之前,命令有所不同。 | [[Nix (command line utilities)|Nix 命令]]在 [https://nixos.org/manual/nix/stable/command-ref/command-ref Nix 参考手册]中有详细记录:主要命令,工具命令和实验性命令。在 2.0 版本(于 2018 年 2 月发布)之前,命令有所不同。 | ||
=== 配置 === | === 配置 === | ||
Line 29: | Line 29: | ||
=== Nix store === | === Nix store === | ||
{{Split|reason=nix store 在概念上有足够的独立性,值得单独成文。}} | |||
{{Split|reason= | |||
由 Nix 构建的软件包会被放置在只读的 ''Nix store'' 中,通常位于 <code>/nix/store</code>。每个软件包都会被赋予一个唯一的地址,该地址由加密哈希值、软件包名称和版本组成,例如 <code>/nix/store/nawl092prjblbhvv16kxxbk6j9gkgcqm-git-2.14.1</code>。这些前缀对构建过程中的所有输入进行哈希,包括源文件、完整的依赖树、编译器参数等。这使得 Nix 能够同时安装同一软件包的不同版本,甚至是同一版本的不同构建(例如使用不同编译器构建的变体)。在添加、移除或更新软件包时,存储中的内容不会被删除;相反,''profiles'' 中指向这些软件包的符号链接会被添加、移除或更改。 | |||
< | <span id="Cleaning_the_Nix_store"></span> | ||
==== | ==== 清理 Nix store ==== | ||
有关清理 Nix store 的信息,请参阅 {{NixOS Manual|name=NixOS 手册:章节 - 清理 Nix 存储|anchor=#sec-nix-gc}}。 | |||
< | <span id="Nix_store_corruption"></span> | ||
==== Nix store | ==== Nix store 损坏 ==== | ||
有关修复 Nix store 损坏的信息,请参阅 {{NixOS Manual|name=NixOS 手册:章节 - Nix store 损坏|anchor=#sec-nix-store-corruption}}。 | |||
< | <span id="Valid_Nix_store_names"></span> | ||
==== | ==== 有效的 Nix store 名称 ==== | ||
{{main|Valid Nix store path names}} | {{main|Valid Nix store path names}} | ||
=== Profiles === | === Profiles === | ||
為了構建一個一致的用戶和系統 | 為了構建一個一致的用戶和系統環境,Nix 會將 Nix store 中的條目符號連結到 ''profiles'' 中。這是 Nix 實現回滾的前端:由於 store 是不可變的且保留先前版本的 profile,將系統還原到先前的狀態只需簡單地將符號連結更改為先前的 profile。更精確地說,Nix 將二進位檔符號連結到 Nix store 中代表用戶環境的條目中。這些用戶環境隨後被符號連結到儲存在 <code>/nix/var/nix/profiles</code> 中被標注的 profile,而它們則進一步符號連結到使用者的 <code>~/.nix-profile</code>。 | ||
<span id="Sandboxing"></span> | <span id="Sandboxing"></span> | ||
=== 沙盒 | === 沙盒 === | ||
当启用沙盒构建时,Nix 会为每个构建过程设置一个隔离的环境。这样可以去除构建环境中额外的隐藏依赖,以提高可复现性。这包括在构建过程中禁止访问 <code>fetch*</code> 函数之外的网络,以及禁止访问 Nix store 之外的文件。根据操作系统的不同,对其他资源的访问也会被阻止(例如在 Linux 上进程间通信会被隔离);详细信息请参阅 Nix 手册中的 [https://nixos.org/nix/manual/#sec-conf-file nix.conf 章节]。 | 当启用沙盒构建时,Nix 会为每个构建过程设置一个隔离的环境。这样可以去除构建环境中额外的隐藏依赖,以提高可复现性。这包括在构建过程中禁止访问 <code>fetch*</code> 函数之外的网络,以及禁止访问 Nix store 之外的文件。根据操作系统的不同,对其他资源的访问也会被阻止(例如在 Linux 上进程间通信会被隔离);详细信息请参阅 Nix 手册中的 [https://nixos.org/nix/manual/#sec-conf-file nix.conf 章节]。 | ||
沙盒在 Linux 上預設是開啟的,在 macOS 上則否。 | |||
在 [https://github.com/NixOS/nixpkgs/ Nixpkgs] 的提取請求 (pull request) 中,請開啟沙盒模式進行測試(請見提取請求模版中的 <code>Tested using sandboxing</code>),因為在 [https://nixos.org/hydra/ 官方 Hydra 構建]中,沙盒會被使用。 | |||
要为 Nix 配置沙盒,请在 <code>/etc/nix/nix.conf</code> 中设置 <code>sandbox = true</code>;要为 NixOS 配置沙盒,请在 <code>configuration.nix</code> 中设置 <code>nix.useSandbox = true;</code>。自 NixOS 17.09 起,<code>nix.useSandbox</code> 选项默认为 <code>true</code>。 | |||
</ | |||
<span id="Alternative_Interpreters"></span> | <span id="Alternative_Interpreters"></span> | ||
Line 90: | Line 73: | ||
* [https://lix.systems/ lix] | * [https://lix.systems/ lix] | ||
早期尝试可以在 [https://riir-nix.github.io/ riir-nix] 找到 | 早期的尝试可以在 [https://riir-nix.github.io/ riir-nix] 找到。 | ||
== 备注 == | |||
<references /> | <references /> | ||
[[Category:Pedias]] | [[Category:Pedias]] | ||
[[Category:Nix]] | [[Category:Nix]] | ||
[[Category:Incomplete]] | [[Category:Incomplete]] | ||
[[Category:Software]] | [[Category:Software]] | ||