Flakes: Difference between revisions
No edit summary |
m →Development shells: fix code block formatting |
||
| (3 intermediate revisions by 2 users not shown) | |||
| Line 13: | Line 13: | ||
Flakes also allow for locking references and versions, which can then be queried and updated programatically via the 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}}. Additionally, an experimental CLI utility accepts flake references for expressions that build, run, and deploy packages.{{Cite manual|nix|command-ref/new-cli/nix|number=8.5.1|title=nix}} | Flakes also allow for locking references and versions, which can then be queried and updated programatically via the 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}}. Additionally, an experimental CLI utility accepts flake references for expressions that build, run, and deploy packages.{{Cite manual|nix|command-ref/new-cli/nix|number=8.5.1|title=nix}} | ||
<!--T:185--> | == Flake file structure == <!--T:185--> | ||
<!--T:231--> | |||
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: | 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: | ||
</translate> | </translate> | ||
| Line 22: | Line 22: | ||
description = "A very basic flake"; | description = "A very basic flake"; | ||
inputs = { | inputs = { | ||
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; | nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; | ||
}; | }; | ||
outputs = { self, nixpkgs }: { | outputs = { self, nixpkgs }: { | ||
packages.x86_64-linux = { | |||
packages.x86_64-linux | default = self.packages.x86_64-linux.hello; | ||
hello = nixpkgs.legacyPackages.x86_64-linux.hello; | |||
}; | |||
}; | |||
}; | |||
}</nowiki>|name=flake.nix|lang=nix}} | }</nowiki>|name=flake.nix|lang=nix}} | ||
| Line 38: | Line 37: | ||
<!--T:190--> | <!--T:190--> | ||
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. | 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. | ||
<!--T:232--> | |||
<!--T: | {{Note|Flakes require you to specify its outputs for each architecture separately. For more information, read the related section below.}} | ||
=== Nix configuration === | |||
=== Nix configuration === <!--T:191--> | |||
<!--T:233--> | |||
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: | 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: | ||
</translate> | </translate> | ||
| Line 61: | Line 60: | ||
<translate> | <translate> | ||
<!--T:234--> | |||
{{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>.}} | {{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>.}} | ||
| Line 125: | Line 125: | ||
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.}} | ||
<!--T:64--> | === The nix flakes command === <!--T:64--> | ||
</translate> | </translate> | ||
| Line 158: | Line 157: | ||
description = "Example flake with a devShell"; | description = "Example flake with a devShell"; | ||
inputs.nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; | inputs.nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; | ||
outputs = { self, nixpkgs}: | outputs = { self, nixpkgs }: | ||
let | let | ||
system = "x86_64-linux"; | system = "x86_64-linux"; | ||
| Line 243: | Line 242: | ||
<translate> | <translate> | ||
<!--T:235--> | |||
Nixpkgs can alternatively also point to an url cached by the NixOS organization: | Nixpkgs can alternatively also point to an url cached by the NixOS organization: | ||
</translate> | </translate> | ||
| Line 249: | Line 249: | ||
<translate> | <translate> | ||
<!--T:236--> | |||
In this example the input would point to the `nixpkgs-unstable` channel. | In this example the input would point to the `nixpkgs-unstable` channel. | ||