Jump to content

Translations:Flakes/191/zh: Difference between revisions

From NixOS Wiki
Weijia (talk | contribs)
Created page with "=== Nix 配置 === 为了推导 flake,您可以覆盖 <code>nix.conf</code> 文件中设置的全局 Nix 配置。例如,这可用于设置特定项目的二进制缓存源,同时保持全局配置不变。Flake 文件中可包含一个 nixConfig 属性,并在其中设置相关配置。例如,启用 nix-community 二进制缓存可以通过以下方式实现: {{File|3=<nowiki>{ ... nixConfig = { extra-substituters = [ "https://nix-community.cach..."
 
(No difference)

Latest revision as of 19:24, 28 August 2025

Message definition (Flakes)
=== Nix configuration ===
It is possible to override the global Nix configuration set in your <code>nix.conf</code> file for the purposes of evaluating a flake. This can be useful, for example, for setting up binary caches specific to certain projects, while keeping the global configuration untouched. The flake file can contain a nixConfig attribute with any relevant configuration settings supplied. For example, enabling the nix-community binary cache would be achieved by:
{{File|3=<nowiki>{
  ...
  nixConfig = {
   extra-substituters = [
     "https://nix-community.cachix.org"
   ];
   extra-trusted-public-keys = [
     "nix-community.cachix.org-1:...="
   ];
  }
}</nowiki>|name=flake.nix|lang=nix}}{{Note|If you are used to configuring your Nix settings via the NixOS configuration, these options are under <code>nix.settings</code> and not <code>nix</code>. For example, you cannot specify the automatic storage optimisation under <code>nix.optimisation.enable</code>.}}

Nix 配置

为了推导 flake,您可以覆盖 nix.conf 文件中设置的全局 Nix 配置。例如,这可用于设置特定项目的二进制缓存源,同时保持全局配置不变。Flake 文件中可包含一个 nixConfig 属性,并在其中设置相关配置。例如,启用 nix-community 二进制缓存可以通过以下方式实现:

❄︎ flake.nix
{
  ...
  nixConfig = {
    extra-substituters = [
      "https://nix-community.cachix.org"
    ];
    extra-trusted-public-keys = [
      "nix-community.cachix.org-1:...="
    ];
  }
}
Note: 如果您习惯通过 NixOS 配置来设置 Nix 配置,则这些选项位于 nix.settings 下,而不是 nix 下。例如,您无法在 nix.optimization.enable 下指定自动存储优化。