Flakes: Difference between revisions
TobiasBora (talk | contribs) No edit summary |
Moved flake-utils usage to its own page; formatting and wording improvements |
||
Line 26: | Line 26: | ||
<!--T:145--> | <!--T:145--> | ||
* An [https://nixos.org/manual/nix/stable/command-ref/new-cli/nix.html experimental command-line interface] accepts flake references for expressions that build, run, and deploy packages. | * An [https://nixos.org/manual/nix/stable/command-ref/new-cli/nix.html experimental command-line interface] accepts flake references for expressions that build, run, and deploy packages. | ||
=== Enabling flakes === | |||
====Enable flakes temporarily==== <!--T:5--> | ====Enable flakes temporarily==== <!--T:5--> | ||
Line 48: | Line 50: | ||
<translate> | <translate> | ||
==== | ====With Home Manager==== <!--T:10--> | ||
<!--T:11--> | <!--T:11--> | ||
Add the following to your home | Add the following to your [[Home Manager|home manager]] config: | ||
</translate> | </translate> | ||
Line 59: | Line 61: | ||
<translate> | <translate> | ||
====Other Distros, without Home | ====Other Distros, without Home Manager==== <!--T:13--> | ||
<!--T:14--> | <!--T:14--> | ||
Line 74: | Line 76: | ||
===Basic Usage of Flake=== <!--T:17--> | ===Basic Usage of Flake=== <!--T:17--> | ||
<!--T:20--> | <!--T:20--> | ||
{{Warning | Since contents of flake files are copied to the world-readable Nix store folder, do not put any unencrypted secrets in flake files. You should instead use a [[Comparison of secret managing schemes|secret managing scheme]].}} | {{Warning | Since contents of flake files are copied to the world-readable Nix store folder, do not put any unencrypted secrets in flake files. You should instead use a [[Comparison of secret managing schemes|secret managing scheme]].}} | ||
<!--T:146--> | <!--T:146--> | ||
For flakes in git | {{Note | For flakes in [[git]] repositories, only files in the working tree will be copied to the store. | ||
<!--T:22--> | <!--T:22--> | ||
Therefore, if you use <code>git</code> for your flake, ensure to <code>git add</code> any project files after you first create them. | Therefore, if you use <code>git</code> for your flake, ensure to <code>git add</code> any project files after you first create them.}} | ||
====Generate flake.nix file==== <!--T:24--> | ====Generate flake.nix file==== <!--T:24--> | ||
<!--T:25--> | <!--T:25--> | ||
To | To initialize a flake, run the following flake command in the project directory: | ||
</translate> | </translate> | ||
<syntaxhighlight lang="console"> | |||
< | $ nix flake init | ||
nix flake init | </syntaxhighlight> | ||
</ | |||
<translate> | <translate> | ||
Line 112: | Line 102: | ||
</translate> | </translate> | ||
<syntaxHighlight lang=nix> | <syntaxHighlight lang=nix> | ||
{ | { | ||
Line 130: | Line 119: | ||
} | } | ||
</syntaxHighlight> | </syntaxHighlight> | ||
<translate> | <translate> | ||
Flakes force you to specify a program for each supported architecture. To avoid this, third-parties projects like [[Flake Utils|flake-utils]] or [[Flake Parts|flake-parts]] 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]] | |||
== Flake schema == <!--T:27--> | == Flake schema == <!--T:27--> |