Flakes/zh: Difference between revisions

Weijia (talk | contribs)
Created page with "=== 另见 ==="
Weijia (talk | contribs)
No edit summary
 
(24 intermediate revisions by the same user not shown)
Line 3: Line 3:
{{Cleanup}}
{{Cleanup}}


'''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 表达式变得更加方便。
'''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 独立程序====


<div lang="en" dir="ltr" class="mw-content-ltr">
{{Note |[https://github.com/DeterminateSystems/nix-installer Determinate Nix 安装程序] 默认启用 Flakes 功能。}}
{{Note | The  [https://github.com/DeterminateSystems/nix-installer Determinate Nix Installer] enables flakes by default.}}
</div>


添加如下内容至 <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:
=== 输出规范 ===
=== 输出规范 ===


<div lang="en" dir="ltr" class="mw-content-ltr">
Nix 包管理器仓库的 [https://github.com/NixOS/nix/blob/master/src/nix/flake-check.md src/nix/flake-check.md] 中对此进行了描述。
This is described in the nix package manager [https://github.com/NixOS/nix/blob/master/src/nix/flake-check.md src/nix/flake-check.md].
</div>


一旦 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 支持 ===


<div lang="en" dir="ltr" class="mw-content-ltr">
[https://github.com/edolstra/flake-compat flake-compat] 库提供了一个兼容层,允许使用传统 <code>default.nix</code> <code>shell.nix</code> 文件的项目与 Flakes 兼容。更多详情和使用示例,请参阅 [[Flake Compat]] 页面。
The [https://github.com/edolstra/flake-compat flake-compat] library provides a compatibility layer that allows projects using traditional <code>default.nix</code> and <code>shell.nix</code> files to operate with flakes. For more details and usage examples, see the [[Flake Compat]] page.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
另一个允许在非 flake 项目中使用 Flakes 的项目是 [https://github.com/fricklerhandwerk/flake-inputs flake-inputs]
Another project that allows consuming flakes from non-flake projects is [https://github.com/fricklerhandwerk/flake-inputs flake-inputs].
</div>


<span id="Accessing_flakes_from_Nix_expressions"></span>
<span id="Accessing_flakes_from_Nix_expressions"></span>
Line 453: Line 445:
=== 另见 ===
=== 另见 ===


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Official_sources"></span>
=== Official sources ===
=== 官方来源 ===
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
* [https://nix.dev/concepts/flakes Flakes] - nix.dev
* [https://nix.dev/concepts/flakes Flakes] - nix.dev
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
* [https://nixos.org/manual/nix/unstable/command-ref/new-cli/nix3-flake.html Nix flake 命令参考手册] - 关于 Flakes 及其各部分的更多附加细节。
* [https://nixos.org/manual/nix/unstable/command-ref/new-cli/nix3-flake.html Nix flake command reference manual] - Many additional details about flakes, and their parts.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
* [https://github.com/NixOS/nix/blob/master/src/nix/flake.md 更详细地描述 Flakes Inputs 的规范]
* [https://github.com/NixOS/nix/blob/master/src/nix/flake.md spec describing flake inputs in more detail]
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
* [https://github.com/NixOS/rfcs/pull/49 RFC 49] (2019) - 原始 Flakes 规范
* [https://github.com/NixOS/rfcs/pull/49 RFC 49] (2019) - Original flakes specification
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Guides"></span>
=== Guides ===
=== 指南 ===
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
* [https://jade.fyi/blog/flakes-arent-real/ Flakes 幻象,亦非洪水猛兽] (Jade Lovelace, 2024)
* [https://jade.fyi/blog/flakes-arent-real/ Flakes aren't real and can't hurt you] (Jade Lovelace, 2024)
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
* [https://github.com/ryan4yin/nixos-and-flakes-book NixOS & Flakes Book](Ryan4yin, 2023) - 🛠️ ❤️ 一本非官方的 NixOS & Flakes 新手入门书籍。
* [https://github.com/ryan4yin/nixos-and-flakes-book NixOS & Flakes Book](Ryan4yin, 2023) - 🛠️ ❤️ An unofficial NixOS & Flakes book for beginners.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
* [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: an Introduction] (Xe Iaso, 2022)
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
* [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) - Intro article on working with Nix and Flakes
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
* [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, Part 1: An introduction and tutorial] (Eelco Dolstra, 2020)
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
* [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, Part 2: Evaluation caching] (Eelco Dolstra, 2020)
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
* [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, Part 3: Managing NixOS systems] (Eelco Dolstra, 2020)
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
* [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 video
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Useful_flake_modules"></span>
=== Useful flake modules ===
=== Flake 实用模块 ===  
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
* [[Flake Utils|flake-utils]]:一个用于简化 Flakes 编写、避免样板代码的库
* [[Flake Utils|flake-utils]]: Library to avoid some boiler-code when writing flakes
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
* [[Flake Parts|flake-parts]]:帮助编写模块化、结构化 Flakes 的库
* [[Flake Parts|flake-parts]]: Library to help write modular and organized flakes
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
* [[Flake Compat|flake-compat]]:Flakes 兼容层
* [[Flake Compat|flake-compat]]: A compatibility layer for flakes
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
* [https://github.com/nix-community/todomvc-nix 构建 Rust Haskell flakes]
* [https://github.com/nix-community/todomvc-nix building Rust and Haskell flakes]
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
{{references}}
{{references}}
</div>


[[Category:Software]]
[[Category:Software]]