Flakes/es: Difference between revisions

FuzzyBot (talk | contribs)
Updating to match new version of source page
FuzzyBot (talk | contribs)
Updating to match new version of source page
 
Line 1: Line 1:
<languages />
<languages />


<div class="mw-translate-fuzzy">
{{Cleanup}}
'''Nix flakes''' es una [https://nixos.org/manual/nix/stable/contributing/experimental-Features.html característica experimental] que fue introducida en Nix 2.4 ([https://nixos.org/manual/nix/unstable/release-notes/rl-2.4.html ver notas]).
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 19: Line 17:
<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
== Flake file structure ==
== Flake file structure ==
</div>
<div lang="en" dir="ltr" class="mw-content-ltr">
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:
</div>
{{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}}
<div lang="en" dir="ltr" class="mw-content-ltr">
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.
</div>
<div lang="en" dir="ltr" class="mw-content-ltr">
{{Note|Flakes require you to specify its outputs for each architecture separately. For more information, read the related section below.}}
{{Note|Flakes require you to specify its outputs for each architecture separately. For more information, read the related section below.}}
</div>
</div>
Line 51: Line 49:
<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
=== Nix configuration ===
=== Nix configuration ===
</div>
<div lang="en" dir="ltr" class="mw-content-ltr">
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:
</div>
{{File|3=<nowiki>{
{{File|3=<nowiki>{
   ...
   ...
Line 62: Line 65:
     ];
     ];
   }
   }
}</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>.}}
}</nowiki>|name=flake.nix|lang=nix}}
 
<div lang="en" dir="ltr" class="mw-content-ltr">
{{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>


Line 76: Line 82:
When using any [[Nix command|<code>nix</code> command]], add the following command-line options:
When using any [[Nix command|<code>nix</code> command]], add the following command-line options:
</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 ===
=== Enabling flakes permanently ===
Line 122: Line 130:
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">
== Usage ==
== Usage ==
Line 140: Line 149:
<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
=== The nix flakes command ===
=== The nix flakes command ===
</div>
{{Main|Nix (command)}}
{{Main|Nix (command)}}
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 151: Line 161:
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<syntaxhighlight lang="console">
<syntaxhighlight lang="console">
$ nix flake show
$ nix flake show
Line 159: Line 168:
         └───hello: package 'hello-2.12.2'
         └───hello: package 'hello-2.12.2'
</syntaxhighlight>
</syntaxhighlight>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 169: Line 177:
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
{
{
   description = "Example flake with a devShell";
   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";
inputs.nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
</div>


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


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 202: Line 204:
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<syntaxhighlight lang="console">
<syntaxhighlight lang="console">
$ nix develop
$ nix develop
</syntaxhighlight>
</syntaxhighlight>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 221: Line 221:
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<syntaxHighlight lang=console>
<syntaxHighlight lang=console>
$ nix build .#hello
$ nix build .#hello
</syntaxHighlight>
</syntaxHighlight>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 281: Line 279:
<code>inputs.nixpkgs.url = "github:NixOS/nixpkgs/<branch name>";</code>
<code>inputs.nixpkgs.url = "github:NixOS/nixpkgs/<branch name>";</code>


<div lang="en" dir="ltr" class="mw-content-ltr">
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:
</div>


<code>inputs.nixpkgs.url = "<nowiki>https://nixos.org/channels/nixpkgs-unstable/nixexprs.tar.xz</nowiki>";</code>
<code>inputs.nixpkgs.url = "<nowiki>https://nixos.org/channels/nixpkgs-unstable/nixexprs.tar.xz</nowiki>";</code>


<div lang="en" dir="ltr" class="mw-content-ltr">
In this example the input would point to the `nixpkgs-unstable` channel.
In this example the input would point to the `nixpkgs-unstable` channel.
 
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 322: Line 323:
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
   inputs.self.submodules = true;
   inputs.self.submodules = true;
</syntaxhighlight>
</syntaxhighlight>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 445: Line 444:
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
{
{
   description = "A flake targeting multiple architectures";
   description = "A flake targeting multiple architectures";
</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 }: let
outputs = { self, nixpkgs }: let
     systems = [ "x86_64-linux" "aarch64-linux" ];
     systems = [ "x86_64-linux" "aarch64-linux" ];
Line 474: Line 468:
}
}
</syntaxhighlight>
</syntaxhighlight>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 496: Line 489:
</div>
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
{
{
Line 508: Line 500:
     };
     };
}
}
</syntaxhighlight>
</syntaxhighlight>  
</div>  


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 636: Line 627:
# Output should show ~/libdep-src-checkout/ so you know it worked
# Output should show ~/libdep-src-checkout/ so you know it worked
</syntaxHighlight>
</syntaxHighlight>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
Line 720: Line 712:
* [https://github.com/nix-community/todomvc-nix building Rust and Haskell flakes]
* [https://github.com/nix-community/todomvc-nix building Rust and Haskell flakes]
</div>
</div>
{{references}}


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">
{{references}}
[[Category:Software|Software]]
[[Category:Nix|Nix]]
[[Category:Nix Language|Nix Language]]
[[Category:Flakes|Flakes]]
</div>
</div>
[[Category:Software]]
[[Category:Nix]]
[[Category:Nix Language]]
[[Category:Flakes]]