Flakes/ru: Difference between revisions
Created page with "== Трюки для разработки ==" |
No edit summary |
||
(71 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
<languages /> | <languages /> | ||
< | {{Cleanup}} | ||
==== | |||
</ | '''Nix Flakes''' (Флейки Nix) — это [[Experimental Nix features|экспериментальная функция]], впервые представленная в релизе [[Nix]] 2.4{{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-проектов, позволяя фиксировать конкретные версии каждой зависимости, делиться этими зависимостями с помощью lock-файлов и в целом делать запись репродуцируемых Nix-выражений более удобной. | ||
Флейк — это каталог, который содержит файл Nix с именем <code>flake.nix</code>, который следует очень конкретной структуре. Флейки вводят похожий на 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}} для указания удалённых ресурсов. Чтобы упростить синтаксис, флейки используют реестр символических идентификаторов{{Cite manual|nix|command-ref/new-cli/nix3-registry|number=8.5.62|title=nix registry}}, что позволяет напрямую ссылаться на ресурсы в следующей форме: <code>github:NixOS/nixpkgs</code>. | |||
Флейки также поддерживают фиксацию ссылок и версий, которые затем могут быть запрошены и обновлены программно через 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}}. | |||
== Структура flake-файла == | |||
В простейшем виде flake-файл содержит описание флейка, набор входных зависимостей (inputs) и выход (output). Вы можете сгенерировать шаблонный flake-файл в любой момент с помощью <code>nix flake init</code>. Это создаст в текущей директории файл <code>flake.nix</code>, содержащий примерно следующее: | |||
{{File|3=<nowiki>{ | |||
description = "A very basic flake"; | |||
inputs = { | |||
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; | |||
}; | |||
outputs = { self, nixpkgs }: { | |||
packages.x86_64-linux.hello = nixpkgs.legacyPackages.x86_64-linux.hello; | |||
packages.x86_64-linux.default = self.packages.x86_64-linux.hello; | |||
< | }; | ||
}</nowiki>|name=flake.nix|lang=nix}} | |||
В примере выше вы можете видеть описание, вход (input), указанный как репозиторий GitHub с конкретной веткой (здесь <code>nixos/nixpkgs</code> на ветке <code>nixos-unstable</code>), и выход (output), который использует этот input. Output в этом примере просто определяет, что в флейке есть один пакет для архитектуры x86_64 под именем <code>hello</code>. Даже если output вашего флейка не использует его inputs (что на практике маловероятно), output всё равно должен быть Nix-функцией. | |||
{{Note|Флейки требуют явного указания outputs для каждой архитектуры отдельно. Для дополнительной информации смотрите соответствующий раздел ниже.}} | |||
<div | <div class="mw-translate-fuzzy"> | ||
=== Конфигурация Nix === | |||
Можно переопределить глобальную конфигурацию Nix, заданную в файле <code>nix.conf</code>, чтобы оценить работу флейка. Это может быть полезно, например, для установки бинарных кэшей, специфичных для проекта, пока глобальная конфигурация останется нетронутой. Flake-файл может содержать атрибут <code>nixConfig</code> с любыми релевантными настройками. Например, чтобы включить бинарный кэш nix-community, можно добавить: | |||
{{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|Если вы привыкли настраивать Nix через конфигурацию NixOS, эти опции находятся под <code>nix.settings</code>, а не под <code>nix</code>. Например, вы не сможете указать автоматическую оптимизацию хранилища через <code>nix.optimisation.enable</code>.}} | |||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
== Setup == | |||
</div> | </div> | ||
< | <span id="Enabling_flakes_temporarily"></span> | ||
==== | <div class="mw-translate-fuzzy"> | ||
==== Временно включить поддержку Flakes ==== | |||
</div> | </div> | ||
<div | <div class="mw-translate-fuzzy"> | ||
При использовании любой команды <code>nix</code> добавьте следующие параметры командной строки: | |||
</div> | </div> | ||
<syntaxhighlight lang="shell"> | <syntaxhighlight lang="shell"> | ||
--experimental-features 'nix-command flakes' | --experimental-features 'nix-command flakes' | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
=== | === Enabling flakes permanently === | ||
</div> | </div> | ||
< | <span id="NixOS"></span> | ||
<div class="mw-translate-fuzzy"> | |||
====Включить flakes на постоянной основе в NixOS==== | |||
</div> | </div> | ||
Добавьте следующее в [[Overview_of_the_NixOS_Linux_distribution#Declarative_Configuration system configuration |Конфигурацию NixOS]]: | |||
<syntaxHighlight lang=nix> | <syntaxHighlight lang=nix> | ||
Line 59: | Line 74: | ||
</syntaxHighlight> | </syntaxHighlight> | ||
< | <span id="Home_Manager"></span> | ||
===== | <div class="mw-translate-fuzzy"> | ||
===== В других Дистрибутивах, с Home-Manager ===== | |||
</div> | </div> | ||
<div | <div class="mw-translate-fuzzy"> | ||
Добавьте следующее в свою конфигурацию Home-Manager: | |||
</div> | </div> | ||
Line 70: | Line 86: | ||
nix.settings.experimental-features = [ "nix-command" "flakes" ]; | nix.settings.experimental-features = [ "nix-command" "flakes" ]; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<span id="Nix_standalone"></span> | |||
<div class="mw-translate-fuzzy"> | |||
=====Другие Дистрибутивы, без Home-Manager===== | |||
</div> | |||
{{Note | [https://github.com/DeterminateSystems/nix-installer Детерминированный Установщик Nix (Determinate Nix Installer)] включает Flakes по умолчанию.}} | |||
Добавьте следующее в <code>~/.config/nix/nix.conf</code> или <code>/etc/nix/nix.conf</code>: | |||
<syntaxHighlight lang=text> | |||
experimental-features = nix-command flakes | |||
</syntaxHighlight> | |||
<span id="Usage"></span> | |||
<div class="mw-translate-fuzzy"> | |||
=== Основное Использование Flake === | |||
</div> | |||
<div class="mw-translate-fuzzy"> | |||
{{Warning | Так как содержимое файлов Flake скопировано в общедоступную папку хранилища Nix, не храните никаких незашифрованных секретов в файлах Flake. Вам следует использовать [[Comparison of secret managing schemes|схемы управления секретами]].}} | |||
</div> | |||
<div class="mw-translate-fuzzy"> | |||
Для флейков в репозиториях git, только файлы из рабочего дерева (Working tree) будут скопированы в хранилище | |||
</div> | |||
<div class="mw-translate-fuzzy"> | |||
Поэтому если вы используете git для ваших флейков, не забывайте применять <code>git add</code> ко всем файлам репозитория, после того как вы их создаёте | |||
</div> | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
=== | === The nix flakes command === | ||
{{Main|Nix (command)}} | |||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
{{ | The {{ic|nix flake}} subcommand is described in {{Nix Manual|name=command reference page of the Nix manual|anchor=command-ref/new-cli/nix3-flake}}. | ||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
This flake produces a single flake output <code>packages</code>. And within that, <code>x86_64-linux</code> is a system-specifc attribute set. And within that, two package [[derivations]] <code>default</code> and <code>hello</code>. You can find outputs with the {{Nix Manual|name=show command|anchor=command-ref/new-cli/nix3-flake-show}} of a flake as shown below: | |||
</div> | </div> | ||
< | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
<syntaxhighlight lang="console"> | |||
</ | $ nix flake show | ||
└───packages | |||
└───x86_64-linux | |||
├───default: package 'hello-2.12.2' | |||
└───hello: package 'hello-2.12.2' | |||
</syntaxhighlight> | |||
</div> | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
=== | ==== Development shells ==== | ||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
A <code>devShell</code> is a Nix-provided [[Development_environment_with_nix-shell#nix develop|development environment]] defined within a flake. It lets you declare a reproducible shell environment with the tools, libraries, and environment variables you need for the development of a specific project. This is flake equivalent to defining a <code>nix-shell</code>. | |||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
==== | <syntaxhighlight lang="nix"> | ||
{ | |||
description = "Example flake with a devShell"; | |||
</div> | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> | |||
inputs.nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; | |||
</div> | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> | |||
outputs = { self, nixpkgs}: | |||
let | |||
system = "x86_64-linux"; | |||
pkgs = import nixpkgs { inherit system; }; | |||
in { | |||
devShells.x86_64-linux.default = pkgs.mkShell { | |||
buildInputs = with pkgs; [ | |||
hello | |||
]; | |||
shellHook = '' | |||
echo "Welcome to the devShell!" | |||
''; | |||
}; | |||
}; | |||
} | |||
</syntaxhighlight> | |||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
To enter the development shell environment: | |||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
= | <syntaxhighlight lang="console"> | ||
$ nix develop | |||
</syntaxhighlight> | |||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
{{note|You don’t need to define a devShell to enter a development shell using nix develop. | |||
If no devShell is defined, nix develop will drop you into an environment containing the default build dependencies of the flake (if any).}} | |||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
==== Build specific attributes in a flake repository ==== | |||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
Running <code>nix build</code> will look in the <code>legacyPackages</code> and <code>packages</code> output attributes for the corresponding [[derivation]] and then your system architecture and build the default output. If you want to specify a build attribute in a flake repository, you can run <code>nix build .#<attr></code>. In the example above, if you wanted to build the <code>packages.x86_64-linux.hello</code> attribute, run: | |||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
= | <syntaxHighlight lang=console> | ||
$ nix build .#hello | |||
</syntaxHighlight> | |||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
Likewise, you can specify an attribute with the run command: <code>nix run .#hello</code> and the develop command: <code>nix develop .#hello</code>. | |||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
Line 143: | Line 221: | ||
</div> | </div> | ||
* <code>description</code> это строка описывающая flake. | |||
* <code>description</code> | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
Line 156: | Line 232: | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
* <code>nixConfig</code> is an attribute set of values which reflect the [https://nixos.org/manual/nix/stable/command-ref/conf-file.html values given to nix.conf]. This can extend the normal behavior of a user's nix experience by adding flake-specific configuration, such as a binary cache. | * <code>nixConfig</code> is an attribute set of values which reflect the [https://nixos.org/manual/nix/stable/command-ref/conf-file.html values given to nix.conf]. This can extend the normal behavior of a user's nix experience by adding flake-specific configuration, such as a [[Binary Cache|binary cache]]. | ||
</div> | </div> | ||
< | <span id="Input_schema"></span> | ||
=== | === Входная схема === | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
Line 176: | Line 251: | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
Nixpkgs can be defined using the following code: | [[Nixpkgs]] can be defined using the following code: | ||
</div> | </div> | ||
<code>inputs.nixpkgs.url = "github:NixOS/nixpkgs/<branch name>";</code> | <code>inputs.nixpkgs.url = "github:NixOS/nixpkgs/<branch name>";</code> | ||
Nixpkgs can alternatively also point to an url cached by the NixOS organization: | |||
<code>inputs.nixpkgs.url = "<nowiki>https://nixos.org/channels/nixpkgs-unstable/nixexprs.tar.xz</nowiki>";</code> | |||
In this example the input would point to the `nixpkgs-unstable` channel. | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
Line 210: | Line 292: | ||
}; | }; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | |||
By default, Git submodules in package <code>src</code>'s won't get copied to the nix store, this may cause the build to fail. Flakes in Git repositories can declare that they need Git submodules to be enabled. Since Nix version [https://discourse.nixos.org/t/nix-2-27-0-released/62003 2.27], you can enable submodules by: | |||
</div> | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> | |||
<syntaxhighlight lang="nix"> | |||
inputs.self.submodules = true; | |||
</syntaxhighlight> | |||
</div> | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
Line 223: | Line 315: | ||
</div> | </div> | ||
В которой: | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
Line 296: | Line 386: | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
==== | == Core usage patterns == | ||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
=== Making your evaluations pure === | |||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
Nix flakes are evaluated in a pure evaluation mode, meaning that access to the external environment is restricted to ensure reproducibility. To maintain purity when working with flakes, consider the following: | |||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
* {{Nixpkgs Manual|name=fetchurl|anchor=#sec-pkgs-fetchers-fetchurl-inputs}} and {{Nixpkgs Manual|name=fetchzip|anchor=#sec-pkgs-fetchers-fetchzip-inputs}} require a <code>sha256</code> argument to be considered pure. | |||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
* <code>builtins.currentSystem</code> is non-hermetic and impure as it reflects the host system performing the evauluation. This can usually be avoided by passing the system (i.e., x86_64-linux) explicitly to derivations requiring it. | |||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
* <code>builtins.getEnv</code> is also impure. Avoid reading from environment variables and likewise, do not reference files outside of the flake's directory. | |||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
=== Defining a flake for multiple architectures === | |||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
Flakes force you to specify a program for each supported architecture. An example below shows how to write a flake that targets multiple architectures. | |||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
{ | { | ||
description = "A flake targeting multiple architectures"; | |||
</div> | </div> | ||
< | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
{ | inputs = { | ||
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; | |||
}; | }; | ||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
== | outputs = { self, nixpkgs }: let | ||
systems = [ "x86_64-linux" "aarch64-linux" ]; | |||
forAllSystems = f: builtins.listToAttrs (map (system: { | |||
name = system; | |||
value = f system; | |||
{ | }) systems); | ||
in { | |||
packages = forAllSystems (system: let | |||
pkgs = nixpkgs.legacyPackages.${system}; | |||
in { | |||
hello = pkgs.hello; | |||
default = pkgs.hello; | |||
}); | |||
}; | }; | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
You can also use third-parties projects like [[Flake Utils|flake-utils]] or [[Flake Parts|flake-parts]] that automatically provide code to avoid this boilerplate. To avoid re-defining the program multiple times, refer to [[Flake Utils#Defining a flake for multiple architectures]] | |||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
== | === Using overlays === | ||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
To use [[Overlays]] with flakes, refer to [[Overlays#In a Nix flake]] page. | |||
</div> | </div> | ||
< | <span id="Enable_unfree_software"></span> | ||
<div class="mw-translate-fuzzy"> | |||
== Включить несвободное ПО == | |||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
To allow for [[Unfree software|unfree software]] in a flake project, you need to explicitly allow it by setting <code>config.allowUnree = true;</code> when importing Nixpkgs. | |||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
{ | { | ||
inputs.nixpkgs.url = "github: | inputs.nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; | ||
outputs = { self, nixpkgs, flake-compat }: | |||
outputs = | let | ||
system = "x86_64-linux"; | |||
pkgs = import nixpkgs { inherit system; config.allowUnfree = true;}; | |||
in { | |||
... | |||
}; | }; | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</div> | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
== NixOS configuration with flakes == | |||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
It is possible to manage a [[NixOS]] system configuration using flakes, gaining the benefits of reproducible, declarative inputs and streamlined updates. | |||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
For details and examples, see [[NixOS system configuration#Defining NixOS as a flake]]. | |||
</div> | </div> | ||
< | <span id="Development_tricks"></span> | ||
== Трюки для разработки == | |||
</ | |||
< | <span id="Automatically_switch_nix_shells_with_direnv"></span> | ||
=== | <div class="mw-translate-fuzzy"> | ||
=== Автоматическое переключение оболочек nix с nix-direnv === | |||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
It is possible to automatically activate different Nix shells when navigating between project directories by using [[Direnv]]. Additional Nix integration with Direnv can be achieved with [https://github.com/nix-community/nix-direnv nix-direnv]. | |||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
== Pushing Flakes to Cachix == | === Pushing Flakes to Cachix === | ||
</div> | </div> | ||
Line 620: | Line 515: | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
=== Flake support in projects without flakes === | |||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
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> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
Another project that allows consuming flakes from non-flake projects is [https://github.com/fricklerhandwerk/flake-inputs flake-inputs]. | |||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
=== Accessing flakes from Nix expressions === | |||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
If you want to access a flake from within a regular Nix expression on a system that has flakes enabled, you can use something like <code>(builtins.getFlake "/path/to/directory").packages.x86_64-linux.default</code>, where 'directory' is the directory that contains your <code>flake.nix</code>. | |||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
=== Efficiently build multiple flake outputs === | |||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
To push ''all'' flake outputs automatically, checkout [https://github.com/srid/devour-flake#usage devour-flake]. | |||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
Line 829: | Line 571: | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
When a git folder exists, flake will only copy files added in git to maximize reproducibility (this way if you forgot to add a local file in your repo, you will directly get an error when you try to compile it). However, for development purpose you may want to create an alternative flake file, for instance containing configuration for your preferred editors as described [https://discourse.nixos.org/t/local-personal-development-tools-with-flakes/22714/8 here]… of course without committing this file since it contains only your own preferred tools. You can do so by doing something like that (say for a file called <code>extra/flake.nix</code>): | When a [[git]] folder exists, flake will only copy files added in git to maximize reproducibility (this way if you forgot to add a local file in your repo, you will directly get an error when you try to compile it). However, for development purpose you may want to create an alternative flake file, for instance containing configuration for your preferred editors as described [https://discourse.nixos.org/t/local-personal-development-tools-with-flakes/22714/8 here]… of course without committing this file since it contains only your own preferred tools. You can do so by doing something like that (say for a file called <code>extra/flake.nix</code>): | ||
</div> | </div> | ||
Line 874: | Line 616: | ||
<span id="See_also"></span> | <span id="See_also"></span> | ||
== См. также == | == См. также == | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | |||
=== Official sources === | |||
</div> | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <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 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 spec describing flake inputs in more detail] | |||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
* [https://github.com/NixOS/rfcs/pull/49 RFC 49] (2019) - Original flakes specification | * [https://github.com/NixOS/rfcs/pull/49 RFC 49] (2019) - Original flakes specification | ||
</div> | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> | |||
=== Guides === | |||
</div> | </div> | ||
Line 912: | Line 670: | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
* [https:// | * [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> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
=== Useful flake modules === | |||
</div> | |||
<div lang="en" dir="ltr" class="mw-content-ltr"> | |||
* [[Flake Utils|flake-utils]]: Library to avoid some boiler-code when writing flakes | |||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
* [ | * [[Flake Parts|flake-parts]]: Library to help write modular and organized flakes | ||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
* [ | * [[Flake Compat|flake-compat]]: A compatibility layer for flakes | ||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
* [https:// | * [https://github.com/nix-community/todomvc-nix building Rust and Haskell flakes] | ||
</div> | </div> | ||
<div lang="en" dir="ltr" class="mw-content-ltr"> | <div lang="en" dir="ltr" class="mw-content-ltr"> | ||
{{references}} | |||
</div> | </div> | ||
[[Category:Software]] | [[Category:Software]] | ||
[[Category:Nix]] | [[Category:Nix]] | ||
[[Category:Nix Language]] | |||
[[Category:Flakes]] | [[Category:Flakes]] |