Flakes/zh: Difference between revisions
Created page with "* [https://xeiaso.net/blog/nix-flakes-1-2022-02-21 Nix Flakes:一个简要介绍] (Xe Iaso, 2022)" |
No edit summary |
||
(15 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
{{Cleanup}} | {{Cleanup}} | ||
'''Nix | '''Nix flakes''' 是 [[Nix]] 2.4 版本中首次引入的一项[[Experimental Nix features|实验性功能]]{{Cite manual|nix|development/experimental-features|number=13.8|title=Experimental Features|subsection=xp-feature-flakes|subtitle=flakes}}{{Cite manual|nix|release-notes/rl-2.4|number=14.27|title=Release 2.4 (2021-11-01)}},旨在解决 Nix 生态系统许多领域的改进问题:它们为 Nix 项目提供了一个统一结构、允许固定每个依赖项的特定版本并通过锁文件共享这些依赖项,同时总体上使编写可复现的 Nix 表达式变得更加方便。 | ||
Flake 是一个直接包含 <code>flake.nix</code> 文件的目录,该文件内容遵循一种特定结构。Flakes 引入了一种类似 URL 的语法{{Cite manual|nix|command-ref/new-cli/nix3-flake|number=8.5.17|title=nix flake|subsection=url-like-syntax|subtitle=URL-like syntax}} 来指定远程资源。为了简化这种 URL 语法,Flakes 使用符号标识符注册表{{Cite manual|nix|command-ref/new-cli/nix3-registry|number=8.5.62|title=nix registry}},这允许通过类似 <code>github:NixOS/nixpkgs</code> 的语法直接指定资源。 | Flake 是一个直接包含 <code>flake.nix</code> 文件的目录,该文件内容遵循一种特定结构。Flakes 引入了一种类似 URL 的语法{{Cite manual|nix|command-ref/new-cli/nix3-flake|number=8.5.17|title=nix flake|subsection=url-like-syntax|subtitle=URL-like syntax}} 来指定远程资源。为了简化这种 URL 语法,Flakes 使用符号标识符注册表{{Cite manual|nix|command-ref/new-cli/nix3-registry|number=8.5.62|title=nix registry}},这允许通过类似 <code>github:NixOS/nixpkgs</code> 的语法直接指定资源。 | ||
Line 74: | Line 74: | ||
====Nix 独立程序==== | ====Nix 独立程序==== | ||
{{Note |[https://github.com/DeterminateSystems/nix-installer Determinate Nix 安装程序] 默认启用 Flakes 功能。}} | |||
{{Note | | |||
添加如下内容至 <code>~/.config/nix/nix.conf</code> 或 <code>/etc/nix/nix.conf</code>: | 添加如下内容至 <code>~/.config/nix/nix.conf</code> 或 <code>/etc/nix/nix.conf</code>: | ||
Line 221: | Line 219: | ||
=== 输出规范 === | === 输出规范 === | ||
Nix 包管理器仓库的 [https://github.com/NixOS/nix/blob/master/src/nix/flake-check.md src/nix/flake-check.md] 中对此进行了描述。 | |||
一旦 Inputs 被解析,它们就会与 <code>self</code> 一起传递给函数 <code>outputs</code>,<code>self</code> 是此 flake 在 Store 中的目录。<code>outputs</code> 根据以下规范返回 flake 的输出。 | 一旦 Inputs 被解析,它们就会与 <code>self</code> 一起传递给函数 <code>outputs</code>,<code>self</code> 是此 flake 在 Store 中的目录。<code>outputs</code> 根据以下规范返回 flake 的输出。 | ||
Line 379: | Line 375: | ||
=== 非 Flake 项目中的 Flake 支持 === | === 非 Flake 项目中的 Flake 支持 === | ||
[https://github.com/edolstra/flake-compat flake-compat] 库提供了一个兼容层,允许使用传统 <code>default.nix</code> 和 <code>shell.nix</code> 文件的项目与 Flakes 兼容。更多详情和使用示例,请参阅 [[Flake Compat]] 页面。 | |||
另一个允许在非 flake 项目中使用 Flakes 的项目是 [https://github.com/fricklerhandwerk/flake-inputs flake-inputs]。 | |||
<span id="Accessing_flakes_from_Nix_expressions"></span> | <span id="Accessing_flakes_from_Nix_expressions"></span> | ||
Line 473: | Line 465: | ||
* [https://xeiaso.net/blog/nix-flakes-1-2022-02-21 Nix Flakes:一个简要介绍] (Xe Iaso, 2022) | * [https://xeiaso.net/blog/nix-flakes-1-2022-02-21 Nix Flakes:一个简要介绍] (Xe Iaso, 2022) | ||
* [https://serokell.io/blog/practical-nix-flakes Practical Nix Flakes] (Alexander Bantyev, 2021) - 关于使用 Nix 和 Flakes 的介绍文章。 | |||
* [https://serokell.io/blog/practical-nix-flakes Practical Nix Flakes] (Alexander Bantyev, 2021) - | |||
* [https://www.tweag.io/blog/2020-05-25-flakes/ Nix Flakes, 第一节:介绍和教程] (Eelco Dolstra, 2020) | |||
* [https://www.tweag.io/blog/2020-05-25-flakes/ Nix Flakes, | |||
* [https://www.tweag.io/blog/2020-06-25-eval-cache/ Nix Flakes, 第二节:推导缓存] (Eelco Dolstra, 2020) | |||
* [https://www.tweag.io/blog/2020-06-25-eval-cache/ Nix Flakes, | |||
* [https://www.tweag.io/blog/2020-07-31-nixos-flakes/ Nix Flakes, 第三节:管理 NixOS 系统] (Eelco Dolstra, 2020) | |||
* [https://www.tweag.io/blog/2020-07-31-nixos-flakes/ Nix Flakes, | |||
* [https://www.youtube.com/watch?v=QXUlhnhuRX4&list=PLgknCdxP89RcGPTjngfNR9WmBgvD_xW0l Nix flakes 101: Introduction to nix flakes] (Jörg Thalheim, 2020) YouTube 视频 | |||
* [https://www.youtube.com/watch?v=QXUlhnhuRX4&list=PLgknCdxP89RcGPTjngfNR9WmBgvD_xW0l Nix flakes 101: Introduction to nix flakes] (Jörg Thalheim, 2020) YouTube | |||
< | <span id="Useful_flake_modules"></span> | ||
=== | === Flake 实用模块 === | ||
* [[Flake Utils|flake-utils]]:一个用于简化 Flakes 编写、避免样板代码的库 | |||
* [[Flake Utils|flake-utils]] | |||
* [[Flake Parts|flake-parts]]:帮助编写模块化、结构化 Flakes 的库 | |||
* [[Flake Parts|flake-parts]] | |||
* [[Flake Compat|flake-compat]]:Flakes 兼容层 | |||
* [[Flake Compat|flake-compat]] | |||
* [https://github.com/nix-community/todomvc-nix 构建 Rust 和 Haskell 的 flakes] | |||
* [https://github.com/nix-community/todomvc-nix | |||
{{references}} | {{references}} | ||
[[Category:Software]] | [[Category:Software]] |