Flakes/ru: Difference between revisions

Golits (talk | contribs)
No edit summary
Golits (talk | contribs)
No edit summary
 
(8 intermediate revisions by the same user not shown)
Line 9: Line 9:
Флейки также поддерживают фиксацию ссылок и версий, которые затем могут быть запрошены и обновлены программно через inputs{{cite manual|nix|command-ref/new-cli/nix3-flake-lock|number=7.5.19|title=nix flake lock}}{{cite manual|nix|command-ref/new-cli/nix3-flake-info|number=7.5.17|title=nix flake info}}. Кроме того, экспериментальная утилита командной строки принимает flake-ссылки для выражений, которые собирают, выполняют и развёртывают пакеты{{Cite manual|nix|command-ref/new-cli/nix|number=8.5.1|title=nix}}.
Флейки также поддерживают фиксацию ссылок и версий, которые затем могут быть запрошены и обновлены программно через inputs{{cite manual|nix|command-ref/new-cli/nix3-flake-lock|number=7.5.19|title=nix flake lock}}{{cite manual|nix|command-ref/new-cli/nix3-flake-info|number=7.5.17|title=nix flake info}}. Кроме того, экспериментальная утилита командной строки принимает flake-ссылки для выражений, которые собирают, выполняют и развёртывают пакеты{{Cite manual|nix|command-ref/new-cli/nix|number=8.5.1|title=nix}}.


<div lang="en" dir="ltr" class="mw-content-ltr">
== Структура flake-файла ==
== Flake file structure ==
В простейшем виде flake-файл содержит описание флейка, набор входных зависимостей (inputs) и выход (output). Вы можете сгенерировать шаблонный flake-файл в любой момент с помощью <code>nix flake init</code>. Это создаст в текущей директории файл <code>flake.nix</code>, содержащий примерно следующее:
Minimally, a flake file contains a description of the flake, a set of input dependencies and an output. You can generate a very basic flake file at any time using nix flake init. This will populate the current directory with a file called flake.nix that will contain something akin to:
{{File|3=<nowiki>{
{{File|3=<nowiki>{
   description = "A very basic flake";
   description = "A very basic flake";
</div>


   <div lang="en" dir="ltr" class="mw-content-ltr">
   inputs = {
inputs = {
     nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
     nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
   };
   };
</div>


   <div lang="en" dir="ltr" class="mw-content-ltr">
   outputs = { self, nixpkgs }: {
outputs = { self, nixpkgs }: {
</div>


     <div lang="en" dir="ltr" class="mw-content-ltr">
     packages.x86_64-linux.hello = nixpkgs.legacyPackages.x86_64-linux.hello;
packages.x86_64-linux.hello = nixpkgs.legacyPackages.x86_64-linux.hello;
</div>


     <div lang="en" dir="ltr" class="mw-content-ltr">
     packages.x86_64-linux.default = self.packages.x86_64-linux.hello;
packages.x86_64-linux.default = self.packages.x86_64-linux.hello;
</div>


   <div lang="en" dir="ltr" class="mw-content-ltr">
   };
};
}</nowiki>|name=flake.nix|lang=nix}}
}</nowiki>|name=flake.nix|lang=nix}}
In the example above, you can see the description, the input specified as a GitHub repository with a specific branch (here <code>nixos/nixpkgs</code> on the <code>nixos-unstable</code> branch), and an output that makes use of the input. The output simply specifies that the flake contains one package for the x86_64 architecture called <code>hello</code>. Even if your flake's output wouldn't use its input (however, in practice, that is highly unlikely), the output still needs to be a Nix function.
В примере выше вы можете видеть описание, вход (input), указанный как репозиторий GitHub с конкретной веткой (здесь <code>nixos/nixpkgs</code> на ветке <code>nixos-unstable</code>), и выход (output), который использует этот input. Output в этом примере просто определяет, что в флейке есть один пакет для архитектуры x86_64 под именем <code>hello</code>. Даже если output вашего флейка не использует его inputs (что на практике маловероятно), output всё равно должен быть Nix-функцией.
{{Note|Flakes require you to specify its outputs for each architecture separately. For more information, read the related section below.}}
{{Note|Флейки требуют явного указания outputs для каждой архитектуры отдельно. Для дополнительной информации смотрите соответствующий раздел ниже.}}
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div class="mw-translate-fuzzy">
=== Nix configuration ===
=== Конфигурация Nix ===
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:
Можно переопределить глобальную конфигурацию Nix, заданную в файле <code>nix.conf</code>, чтобы оценить работу флейка. Это может быть полезно, например, для установки бинарных кэшей, специфичных для проекта, пока глобальная конфигурация останется нетронутой. Flake-файл может содержать атрибут <code>nixConfig</code> с любыми релевантными настройками. Например, чтобы включить бинарный кэш nix-community, можно добавить:
{{File|3=<nowiki>{
{{File|3=<nowiki>{
   ...
   ...
Line 53: Line 41:
       "nix-community.cachix.org-1:...="
       "nix-community.cachix.org-1:...="
     ];
     ];
  }
}</nowiki>|name=flake.nix|lang=nix}}{{Note|Если вы привыкли настраивать Nix через конфигурацию NixOS, эти опции находятся под <code>nix.settings</code>, а не под <code>nix</code>. Например, вы не сможете указать автоматическую оптимизацию хранилища через <code>nix.optimisation.enable</code>.}}
}</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>.}}
</div>
</div>