Flakes: Difference between revisions
Lucperkins (talk | contribs) m Fixed indentation in the example flake.nix |
m Update link to manual to use stable instead of hard coded version |
||
| (6 intermediate revisions by 6 users not shown) | |||
| Line 5: | Line 5: | ||
<translate> | <translate> | ||
<!--T:182--> | <!--T:182--> | ||
'''Nix flakes''' are an [ | '''Nix flakes''' are an [https://nix.dev/manual/nix/stable/contributing/experimental-features experimental feature] first introduced in the 2.4 [[Nix]] release,{{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)}} aiming to address a number of areas of improvement for the Nix ecosystem: they provide a uniform structure for Nix projects, allow for pinning specific versions of each dependencies, and sharing these dependencies via lock files, and overall make it more convenient to write reproducible Nix expressions. | ||
<!--T:183--> | <!--T:183--> | ||
| Line 103: | Line 103: | ||
<!--T:14--> | <!--T:14--> | ||
{{Note | The [https://github.com/DeterminateSystems/nix-installer Determinate Nix Installer] enables flakes by default.}} | {{Note | The [https://github.com/DeterminateSystems/nix-installer Determinate Nix Installer] enables flakes by default, but installs the proprietary Determinate Nix.}} | ||
<!--T:15--> | <!--T:15--> | ||
| Line 157: | 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 193: | Line 193: | ||
<!--T:103--> | <!--T:103--> | ||
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: | Running <code>nix build</code> will look in the <code>legacyPackages</code> and <code>packages</code> output attributes for the corresponding [[derivations|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: | ||
</translate> | </translate> | ||
| Line 296: | Line 296: | ||
<!--T:151--> | <!--T:151--> | ||
The output schema is described the [https://nix.dev/manual/nix/2.33/command-ref/new-cli/nix3-flake-check.html#evaluation-checks nix flake check manual page]. | |||
<!--T:43--> | <!--T:43--> | ||
| Line 381: | Line 381: | ||
<!--T:156--> | <!--T:156--> | ||
* <code>builtins.currentSystem</code> is non-hermetic and impure as it reflects the host system performing the | * <code>builtins.currentSystem</code> is non-hermetic and impure as it reflects the host system performing the evaluation. This can usually be avoided by passing the system (i.e., x86_64-linux) explicitly to derivations requiring it. | ||
<!--T:209--> | <!--T:209--> | ||