Flakes: Difference between revisions

imported>Sedlund
m apparently there an order to the comments I missed.
m Fixed indentation in the example flake.nix
 
(78 intermediate revisions by 43 users not shown)
Line 1: Line 1:
'''Nix flakes''' are an [https://nixos.org/manual/nix/stable/contributing/experimental-features.html experimental feature] of the Nix package manager.
<languages />


== Introduction ==
{{Cleanup}}


Flakes introduce a policy for managing dependencies between Nix expressions. It improves reproducibility, composability and usability in the Nix ecosystem. Although it's still an experimental feature, flakes have been widely used by the Nix community.
<translate>
<!--T:182-->
'''Nix flakes''' are an [[Experimental Nix 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.


Technically, a [https://nixos.org/manual/nix/unstable/command-ref/new-cli/nix3-flake.html#description flake] is a file system tree that contains a Nix file named <code>flake.nix</code> in its root directory.
<!--T:183-->
A flake is a directory which directly contains a Nix file called <code>flake.nix</code>, that follows a very specific structure. Flakes introduce a URL-like syntax{{Cite manual|nix|command-ref/new-cli/nix3-flake|number=8.5.17|title=nix flake|subsection=url-like-syntax|subtitle=URL-like syntax}} for specifying remote resources. To simplify the URL syntax, flakes use a registry of symbolic identifiers,{{Cite manual|nix|command-ref/new-cli/nix3-registry|number=8.5.62|title=nix registry}} allowing the direct specification of resources through syntax such as <code>github:NixOS/nixpkgs</code>.


Flakes add the following behavior to Nix:
<!--T:184-->
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}}


# A <code>flake.nix</code> file offers a uniform [https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake.html#flake-format schema], where:
== Flake file structure == <!--T:185-->
#* Other flakes can be referenced as dependencies providing Nix language code or other files.
#* The values produced by the Nix expression in <code>flake.nix</code> are structured according to pre-defined use cases.
# References to other flakes can be specified using a dedicated [https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake.html#flake-references URL-like syntax]. A [https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-registry.html flake registry] allows using symbolic identifiers for further brevity. References can be automatically locked to their current specific version and later updated programmatically.
# A [https://nixos.org/manual/nix/stable/command-ref/new-cli/nix.html new command line interface], implemented as a separate experimental feature, leverages flakes by accepting flake references in order to build, run, or deploy software defined as a flake.


== Enable flakes ==
<!--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:
</translate>


Flakes were introduced with Nix 2.4 ([https://nixos.org/manual/nix/unstable/release-notes/rl-2.4.html release notes]).
{{File|3=<nowiki>{
  description = "A very basic flake";


===Temporary===
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
  };
 
  outputs = { self, nixpkgs }: {
    packages.x86_64-linux = {
      default = self.packages.x86_64-linux.hello;
      hello = nixpkgs.legacyPackages.x86_64-linux.hello;
    };
  };
}</nowiki>|name=flake.nix|lang=nix}}
 
<translate>
<!--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.
 
<!--T:232-->
{{Note|Flakes require you to specify its outputs for each architecture separately. For more information, read the related section below.}}
 
=== 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:
</translate>
 
{{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}}
 
<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>.}}
 
== Setup == <!--T:192-->
 
=== Enabling flakes temporarily === <!--T:5-->
 
<!--T:6-->
When using any [[Nix command|<code>nix</code> command]], add the following command-line options:
</translate>


Add <code>--experimental-features 'nix-command flakes'</code> when using any <code>nix3</code> commands.
<syntaxhighlight lang="shell">
--experimental-features 'nix-command flakes'
</syntaxhighlight>


=== Permanent ===
<translate>
=== Enabling flakes permanently === <!--T:193-->


==== NixOS ====
==== NixOS ==== <!--T:7-->


Add the following to your system configuration:
<!--T:8-->
Add the following to the [[Overview_of_the_NixOS_Linux_distribution#Declarative_Configuration system configuration |NixOS configuration]]:
</translate>


<syntaxHighlight lang=nix>
<syntaxHighlight lang=nix>
Line 33: Line 88:
</syntaxHighlight>
</syntaxHighlight>


==== Other Distros: With Home-Manager ====
<translate>
====Home Manager==== <!--T:10-->


If you use HM, add the following to your home-manager config:
<!--T:11-->
Add the following to your [[Home Manager|home manager]] config:
</translate>


<syntaxHighlight lang=nix>
<syntaxhighlight lang="nix">
   nix = {
   nix.settings.experimental-features = [ "nix-command" "flakes" ];
    package = pkgs.nix;
</syntaxhighlight>
    settings.experimental-features = [ "nix-command" "flakes" ];
  };
</syntaxHighlight>


===== Other Distros: Without Home-Manager =====
<translate>
====Nix standalone==== <!--T:13-->


{{ note | Flakes are already enabled if you installed Nix using the [https://github.com/DeterminateSystems/nix-installer Determinate Installer]. }}
<!--T:14-->
{{Note | The  [https://github.com/DeterminateSystems/nix-installer Determinate Nix Installer] enables flakes by default.}}


<!--T:15-->
Add the following to <code>~/.config/nix/nix.conf</code> or <code>/etc/nix/nix.conf</code>:
Add the following to <code>~/.config/nix/nix.conf</code> or <code>/etc/nix/nix.conf</code>:
</translate>


<syntaxHighlight lang=text>
<syntaxHighlight lang=text>
Line 54: Line 113:
</syntaxHighlight>
</syntaxHighlight>


== Basic project usage ==
<translate>
== Usage == <!--T:17-->
 
<!--T:20-->
{{Warning | Since contents of flake files are copied to the world-readable [[Nix_package_manager#Nix_store|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-->
{{Note | For flakes in [[git]] repositories, only files in the working tree will be copied to the store.
 
<!--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.}}
 
=== The nix flakes command === <!--T:64-->
</translate>
 
{{Main|Nix (command)}}
 
<translate>
<!--T:65-->
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}}.
 
<!--T:194-->
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:
</translate>
 
<syntaxhighlight lang="console">
$ nix flake show
└───packages
    └───x86_64-linux
        ├───default: package 'hello-2.12.2'
        └───hello: package 'hello-2.12.2'
</syntaxhighlight>
 
<translate>
==== Development shells ==== <!--T:196-->
 
<!--T:197-->
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>.
</translate>
 
<syntaxhighlight lang="nix">
{
  description = "Example flake with a devShell";
 
inputs.nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
 
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>
 
<translate>
<!--T:201-->
To enter the development shell environment:
</translate>
 
<syntaxhighlight lang="console">
$ nix develop
</syntaxhighlight>


{{warning | Files that are part of the flake will be copied to the world-readable nix store when the flake is evaluated; avoid putting unencrypted secrets in your flake.}}
<translate>
<!--T:203-->
{{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).}}


In your project, run <code>nix flake init</code> to generate the flake.nix file.
==== Build specific attributes in a flake repository ==== <!--T:102-->


For flakes in git repos, only files in the working tree will be copied to the store.
<!--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:
</translate>


Therefore, if you use <code>git</code> for your flake, ensure to <code>git add</code> any project files after you first create them.
<syntaxHighlight lang=console>
$ nix build .#hello
</syntaxHighlight>


See also https://www.tweag.io/blog/2020-05-25-flakes/
<translate>
<!--T:205-->
Likewise, you can specify an attribute with the run command: <code>nix run .#hello</code> and the develop command: <code>nix develop .#hello</code>.


== Flake schema ==
== Flake schema == <!--T:27-->


<!--T:28-->
The flake.nix file is a Nix file but that has special restrictions (more on that later).
The flake.nix file is a Nix file but that has special restrictions (more on that later).


<!--T:29-->
It has 4 top-level attributes:
It has 4 top-level attributes:


<!--T:30-->
* <code>description</code> is a string describing the flake.
* <code>description</code> is a string describing the flake.
<!--T:147-->
* <code>inputs</code> is an attribute set of all the dependencies of the flake. The schema is described below.
* <code>inputs</code> is an attribute set of all the dependencies of the flake. The schema is described below.
<!--T:148-->
* <code>outputs</code> is a function of one argument that takes an attribute set of all the realized inputs, and outputs another attribute set whose schema is described below.
* <code>outputs</code> is a function of one argument that takes an attribute set of all the realized inputs, and outputs another attribute set whose schema is described below.
* <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.


=== Input schema ===
<!--T:149-->
* <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]].
 
=== Input schema === <!--T:31-->
 
<!--T:32-->
[https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake.html#flake-inputs The nix flake inputs manual].
 
<!--T:150-->
[https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake.html#flake-references The nix flake references manual].
 
<!--T:33-->
The inputs attribute defines the dependencies of the flake. For example, nixpkgs has to be defined as a dependency for a system flake in order for the system to build properly.
 
<!--T:34-->
[[Nixpkgs]] can be defined using the following code:
</translate>
 
<code>inputs.nixpkgs.url = "github:NixOS/nixpkgs/<branch name>";</code>
 
<translate>
<!--T:235-->
Nixpkgs can alternatively also point to an url cached by the NixOS organization:
</translate>
 
<code>inputs.nixpkgs.url = "<nowiki>https://nixos.org/channels/nixpkgs-unstable/nixexprs.tar.xz</nowiki>";</code>
 
<translate>
<!--T:236-->
In this example the input would point to the `nixpkgs-unstable` channel.
 
<!--T:36-->
For any repository with its own flake.nix file, the website must also be defined. Nix knows where the nixpkgs repository is, so stating that it's on GitHub is unnecessary.
 
<!--T:37-->
For example, adding [[Hyprland]] as an input would look something like this:
</translate>


This is not a complete schema but should be enough to get you started:
<code>inputs.hyprland.url = "github:hyprwm/Hyprland";</code>


<syntaxHighlight lang=nix>
<translate>
{
<!--T:39-->
  inputs = {
If you want to make Hyprland follow the nixpkgs input to avoid having multiple versions of nixpkgs, this can be done using the following code:
    # use release 23.05 branch of the GitHub repository as input, this is the most common input format
</translate>
    nixpkgs.url = "github:NixOS/nixpkgs/release-23.05";
    # Git URL, can be used for any Git repository based on https/ssh protocol
    git-example.url = "git+https://git.somehost.tld/user/path?ref=branch&rev=fdc8ef970de2b4634e1b3dca296e1ed918459a9e";
    # The example above will also copy .git, use this for (shallow) local Git repos
    git-directory-example.url = "git+file:/path/to/repo?shallow=1";
    # You have a local copy of a git fork and are working on a new branch
    forked-git-flake.url = "git+file:/home/user/forked-flake?branch=feat/myNewFeature"


    # Local directories (for absolute paths you can omit 'path:')
<code>inputs.hyprland.inputs.nixpkgs.follows = "nixpkgs";</code>
    directory-example.url = "path:/path/to/repo";


    bar = {
<translate>
      url = "github:foo/bar/branch";
<!--T:41-->
      # if the input is not a flake, you need to set flake=false
Using curly brackets (<code>{}</code>), we can shorten all of this and put it in a table. The code will look something like this:
      flake = false;
</translate>
    };


    sops-nix = {
<syntaxhighlight lang="nix">
      url = "github:Mic92/sops-nix";
inputs = {
      # The `follows` keyword in inputs is used for inheritance.
  nixpkgs.url = "github:NixOS/nixpkgs/<branch name>";
      # Here, `inputs.nixpkgs` of sops-nix is kept consistent with the `inputs.nixpkgs` of
  hyprland = {
      # the current flake, to avoid problems caused by different versions of nixpkgs.
    url = "github:hyprwm/Hyprland";
      inputs.nixpkgs.follows = "nixpkgs";
    inputs.nixpkgs.follows = "nixpkgs";
    };
  };
};
</syntaxhighlight>


    # Pin flakes to a specific revision
<translate>
    nix-doom-emacs = {
<!--T:206-->
      url = "github:vlaci/nix-doom-emacs?rev=238b18d7b2c8239f676358634bfb32693d3706f3";
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:
      flake = false;
</translate>
    };


    # To use a subdirectory of a repo, pass `dir=xxx`
<syntaxhighlight lang="nix">
    nixpkgs.url = "github:foo/bar?dir=shu";
  inputs.self.submodules = true;
  }
</syntaxhighlight>
}
</syntaxHighlight>
Also see [https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake.html#flake-references the nix flake manual].


The bar input is then passed to the output schema
<translate>
=== Output schema === <!--T:42-->


=== Output schema ===
<!--T:151-->
This is described in the nix package manager [https://github.com/NixOS/nix/blob/master/src/nix/flake-check.md src/nix/flake-check.md].


<!--T:43-->
Once the inputs are resolved, they're passed to the function `outputs` along with with `self`, which is the directory of this flake in the store. `outputs` returns the outputs of the flake, according to the following schema.
Once the inputs are resolved, they're passed to the function `outputs` along with with `self`, which is the directory of this flake in the store. `outputs` returns the outputs of the flake, according to the following schema.


This is described in the nix package manager [https://github.com/NixOS/nix/blob/master/src/nix/flake.cc src/nix/flake.cc] in CmdFlakeCheck.
<!--T:44-->
 
Where:
Where:


<!--T:45-->
* <code><system></code> is something like "x86_64-linux", "aarch64-linux", "i686-linux", "x86_64-darwin"
* <code><system></code> is something like "x86_64-linux", "aarch64-linux", "i686-linux", "x86_64-darwin"
<!--T:152-->
* <code><name></code> is an attribute name like "hello".
* <code><name></code> is an attribute name like "hello".
<!--T:153-->
* <code><flake></code> is a flake name like "nixpkgs".
* <code><flake></code> is a flake name like "nixpkgs".
<!--T:154-->
* <code><store-path></code> is a <code>/nix/store..</code> path
* <code><store-path></code> is a <code>/nix/store..</code> path
</translate>


<syntaxHighlight lang=nix>
<syntaxhighlight lang="nix">
{ self, ... }@inputs:
{ self, ... }@inputs:
{
{
Line 151: Line 330:
     type = "app";
     type = "app";
     program = "<store-path>";
     program = "<store-path>";
    meta = {description = "..."; inherit otherMetaAttrs; };
   };
   };
   # Executed by `nix run . -- <args?>`
   # Executed by `nix run . -- <args?>`
   apps."<system>".default = { type = "app"; program = "..."; };
   apps."<system>".default = { type = "app"; program = "..."; meta = {description = "..."; inherit otherMetaAttrs; }; };


   # Formatter (alejandra, nixfmt or nixpkgs-fmt)
   # Formatter (alejandra, nixfmt, treefmt-nix or nixpkgs-fmt)
   formatter."<system>" = derivation;
   formatter."<system>" = derivation;
   # Used for nixpkgs packages, also accessible via `nix build .#<name>`
   # Used for nixpkgs packages, also accessible via `nix build .#<name>`
Line 164: Line 344:
   overlays.default = final: prev: { };
   overlays.default = final: prev: { };
   # Nixos module, consumed by other flakes
   # Nixos module, consumed by other flakes
   nixosModules."<name>" = { config }: { options = {}; config = {}; };
   nixosModules."<name>" = { config, ... }: { options = {}; config = {}; };
   # Default module
   # Default module
   nixosModules.default = { config }: { options = {}; config = {}; };
   nixosModules.default = { config, ... }: { options = {}; config = {}; };
   # Used with `nixos-rebuild --flake .#<hostname>`
   # Used with `nixos-rebuild switch --flake .#<hostname>`
   # nixosConfigurations."<hostname>".config.system.build.toplevel must be a derivation
   # nixosConfigurations."<hostname>".config.system.build.toplevel must be a derivation
   nixosConfigurations."<hostname>" = {};
   nixosConfigurations."<hostname>" = {};
Line 184: Line 364:
   templates.default = { path = "<store-path>"; description = ""; };
   templates.default = { path = "<store-path>"; description = ""; };
}
}
</syntaxHighlight>
</syntaxhighlight>


<translate>
<!--T:48-->
You can also define additional arbitrary attributes, but these are the outputs that Nix knows about.
You can also define additional arbitrary attributes, but these are the outputs that Nix knows about.


==== nix run ====
== Core usage patterns == <!--T:208-->
When output <code>apps.<system>.myapp</code> is not defined, <code>nix run myapp</code> runs <code><packages or legacyPackages.<system>.myapp>/bin/<myapp.meta.mainProgram or myapp.pname or myapp.name (the non-version part)></code>
 
== Using flakes with stable Nix ==
 
There exists the [https://github.com/edolstra/flake-compat flake-compat] library that you can use to shim <code>default.nix</code> and <code>shell.nix</code> files. It will download the inputs of the flake, pass them to the flake’s <code>outputs</code> function and return an attribute set containing <code>defaultNix</code> and <code>shellNix</code> attributes. The attributes will contain the output attribute set with an extra <code>default</code> attribute pointing to current platform’s <code>defaultPackage</code> (resp. <code>devShell</code> for <code>shellNix</code>).
 
Place the following into <code>default.nix</code> (for <code>shell.nix</code>, replace <code>defaultNix</code> with <code>shellNix</code>) to use the shim:
 
<syntaxHighlight lang=nix>
(import (
  fetchTarball {
    url = "https://github.com/edolstra/flake-compat/archive/12c64ca55c1014cdc1b16ed5a804aa8576601ff2.tar.gz";
    sha256 = "0jm6nzb83wa6ai17ly9fzpqc40wg1viib8klq8lby54agpl213w5"; }
) {
  src =  ./.;
}).defaultNix
</syntaxHighlight>


You can also use the lockfile to make updating the hashes easier using <code>nix flake lock --update-input flake-compat</code>. Add the following to your <code>flake.nix</code>:
=== Making your evaluations pure === <!--T:60-->


<syntaxHighlight lang=nix>
<!--T:61-->
  inputs.flake-compat = {
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:
    url = "github:edolstra/flake-compat";
    flake = false;
  };
</syntaxHighlight>


and add <code>flake-compat</code> to the arguments of <code>outputs</code> attribute. Then you will be able to use <code>default.nix</code> like the following:
<!--T:62-->
* {{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.


<syntaxHighlight lang=nix>
<!--T:156-->
(import (
* <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.
  let
    lock = builtins.fromJSON (builtins.readFile ./flake.lock);
  in fetchTarball {
    url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
    sha256 = lock.nodes.flake-compat.locked.narHash; }
) {
  src =  ./.;
}).defaultNix
</syntaxHighlight>


== Accessing flakes from Nix expressions ==
<!--T:209-->
*  <code>builtins.getEnv</code> is also impure. Avoid reading from environment variables and likewise, do not reference files outside of the flake's directory.


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:/path/to/directory").packages.x86_64-linux.default</code>, where 'directory' is the directory that contains your <code>flake.nix</code>.
=== Defining a flake for multiple architectures === <!--T:210-->


== Making your evaluations pure ==
<!--T:211-->
Flakes force you to specify a program for each supported architecture. An example below shows how to write a flake that targets multiple architectures.
</translate>


Nix flakes run in pure evaluation mode, which is underdocumented. Some tips for now:
<syntaxhighlight lang="nix">
{
  description = "A flake targeting multiple architectures";


* fetchurl and fetchtar [https://github.com/NixOS/nix/blob/36c4d6f59247826dde32ad2e6b5a9471a9a1c911/src/libexpr/primops/fetchTree.cc#L201 require] a sha256 argument to be considered pure.
inputs = {
* builtins.currentSystem is non-hermetic and impure. This can usually be avoided by passing the system (i.e., x86_64-linux) explicitly to derivations requiring it.
    nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
* Imports from channels like <code><nixpkgs></code> can be made pure by instead importing from the <code>output</code> function in <code>flake.nix</code>, where the arguments provide the store path to the flake's inputs:
  };


<syntaxHighlight lang=nix>
outputs = { self, nixpkgs }: let
outputs = { self, nixpkgs, ... }:
    systems = [ "x86_64-linux" "aarch64-linux" ];
  {
     forAllSystems = f: builtins.listToAttrs (map (system: {
     nixosConfigurations.machine = nixpkgs.lib.nixosSystem {
       name = system;
       # Note that you cannot put arbitrary configuration here: the configuration must be placed in the files loaded via modules
       value = f system;
       system = "x86_64-linux";
    }) systems);
       modules = [
  in {
        (nixpkgs + "/nixos/modules/<some-module>.nix")
    packages = forAllSystems (system: let
        ./machine.nix
       pkgs = nixpkgs.legacyPackages.${system};
       ];
    in {
     };
      hello = pkgs.hello;
       default = pkgs.hello;
     });
   };
   };
</syntaxHighlight>
}
 
</syntaxhighlight>
== The nix flakes command ==
 
The {{ic|nix flake}} subcommand is described in [https://nixos.org/manual/nix/unstable/command-ref/new-cli/nix3-flake.html command reference page of the unstable manual].
 
== Install packages with `nix profile` ==


You can install Nix packages into your local profile from any flakes with `nix profile install. For example from `nixpkgs`` flake :
<translate>
<syntaxHighlight lang=bash>
<!--T:215-->
nix profile install nixpkgs#hello
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]]
</syntaxHighlight>


On NixOS you can syncronize your system and your profile references to `nixpkgs` with:
=== Using overlays === <!--T:216-->  
<syntaxHighlight lang=bash>
nix registry pin nixpkgs github:NixOS/nixpkgs/$(nixos-version --revision)
</syntaxHighlight>


== Using nix flakes with NixOS ==
<!--T:217-->
To use [[Overlays]] with flakes, refer to [[Overlays#In a Nix flake]] page.


nixos-rebuild switch will read its configuration from <code>/etc/nixos/flake.nix</code> if it is present.
=== Enable unfree software === <!--T:129-->


A basic nixos flake.nix could look like this:
<!--T:218-->
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.
</translate>


<syntaxHighlight lang=nix>
<syntaxhighlight lang="nix">
{
{
   outputs = { self, nixpkgs }: {
  inputs.nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
     # replace 'joes-desktop' with your hostname here.
   outputs = { self, nixpkgs, flake-compat }:
    nixosConfigurations.joes-desktop = nixpkgs.lib.nixosSystem {
     let
       system = "x86_64-linux";
       system = "x86_64-linux";
       modules = [ ./configuration.nix ];
       pkgs = import nixpkgs { inherit system; config.allowUnfree = true;};
    };
     in {
  };
       ...
}
</syntaxHighlight>
If you want to pass on the flake inputs to external configuration files, you can use the <code>specialArgs</code> attribute:
<syntaxHighlight lang=nix>
{
  inputs.nixpkgs.url = github:NixOS/nixpkgs;
  inputs.home-manager.url = github:nix-community/home-manager;
 
  outputs = { self, nixpkgs, ... }@attrs: {
     nixosConfigurations.fnord = nixpkgs.lib.nixosSystem {
       system = "x86_64-linux";
      specialArgs = attrs;
      modules = [ ./configuration.nix ];
     };
     };
  };
}
</syntaxHighlight>
Then, you can access the flake inputs from the file <code>configuration.nix</code> like this:
<syntaxHighlight lang=nix>
{ config, lib, nixpkgs, home-manager, ... }: {
  # do something with home-manager here, for instance:
  imports = [ home-manager.nixosModules.default ];
  ...
}
}
</syntaxHighlight>
</syntaxhighlight>  
 
nixos-rebuild also allows to specify different flake using the <code>--flake</code> flag (# is optional):


<syntaxHighlight lang=console>
<translate>
$ sudo nixos-rebuild switch --flake '.#'
== NixOS configuration with flakes == <!--T:220-->
</syntaxHighlight>


By default nixos-rebuild will use the currents system hostname to lookup the right nixos configuration in <code>nixosConfigurations</code>. You can also override this by using appending it to the flake parameter:
<!--T:221-->
It is possible to manage a [[NixOS]] system configuration using flakes, gaining the benefits of reproducible, declarative inputs and streamlined updates.


<syntaxHighlight lang=console>
<!--T:222-->
$ sudo nixos-rebuild switch --flake '/etc/nixos#joes-desktop'
For details and examples, see [[NixOS system configuration#Defining NixOS as a flake]].
</syntaxHighlight>


To switch a remote configuration, use:
== Development tricks == <!--T:131-->
<syntaxHighlight lang=console>
$ nixos-rebuild --flake .#mymachine \
  --target-host mymachine-hostname --build-host localhost \
  switch
</syntaxHighlight>


{{warning|Remote building seems to be broken at the moment, which is why the build host is set to “localhost”.}}
=== Automatically switch nix shells with direnv === <!--T:97-->


== Super fast nix-shell ==
<!--T:98-->
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].


A feature of the nix Flake edition is that Nix evaluations are cached.
=== Pushing Flakes to Cachix === <!--T:99-->
</translate>


Let’s say that your project has a <code>shell.nix</code> file that looks like this:
https://docs.cachix.org/pushing#flakes


<syntaxHighlight lang=nix>
<translate>
{ pkgs ? import <nixpkgs> { } }:
=== Flake support in projects without flakes === <!--T:50-->
with pkgs;
mkShell {
  buildInputs = [
    nixpkgs-fmt
  ];


  shellHook = ''
<!--T:51-->
    # ...
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.
  '';
}
</syntaxHighlight>


Running nix-shell can be a bit slow and take 1-3 seconds.
<!--T:223-->
Another project that allows consuming flakes from non-flake projects is [https://github.com/fricklerhandwerk/flake-inputs flake-inputs].


Now create a <code>flake.nix</code> file in the same repository:
=== Accessing flakes from Nix expressions === <!--T:58-->


<syntaxHighlight lang=nix>
<!--T:59-->
{
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>.
  description = "my project description";


  inputs.flake-utils.url = "github:numtide/flake-utils";
=== Efficiently build multiple flake outputs === <!--T:224-->


  outputs = { self, nixpkgs, flake-utils }:
<!--T:101-->
    flake-utils.lib.eachDefaultSystem
To push ''all'' flake outputs automatically, checkout [https://github.com/srid/devour-flake#usage devour-flake].
      (system:
        let pkgs = nixpkgs.legacyPackages.${system}; in
        {
          devShells.default = import ./shell.nix { inherit pkgs; };
        }
      );
}
</syntaxHighlight>


Run git add flake.nix so that Nix recognizes it.
=== Build a package added in a PR === <!--T:161-->
</translate>


And finally, run <code>nix develop</code>. This is what replaces the old nix-shell invocation.
<syntaxHighlight>
 
nix build github:nixos/nixpkgs?ref=pull/<PR_NUMBER>/head#<PACKAGE>
Exit and run again, this command should now be super fast.
 
{{warning|TODO: there is an alternative version where the defaultPackage is a pkgs.buildEnv that contains all the dependencies. And then nix shell is used to open the environment.}}
 
=== Direnv integration ===
 
Assuming that the flake defines a <code>devShell</code> output attribute and that you are using direnv. Here is how to replace the old use nix stdlib function with the faster flake version:
 
<syntaxHighlight lang=sh>
use_flake() {
  watch_file flake.nix
  watch_file flake.lock
  eval "$(nix print-dev-env --profile "$(direnv_layout_dir)/flake-profile")"
}
</syntaxHighlight>
</syntaxHighlight>


Copy this in <code>~/.config/direnv/lib/use_flake.sh</code> or in <code>~/.config/direnv/direnvrc</code>
<translate>
or directly in your project specific <code>.envrc</code>.
<!--T:162-->
this allows building a package that has not yet been added to nixpkgs.


Note: You may not need to create <code>use_flake()</code> yourself; as of [https://github.com/direnv/direnv/releases/tag/v2.29.0#:~:text=add%20use_flake%20function direnv 2.29,] <code>use flake</code> is part of direnv's standard library.
<!--T:132-->
note that this will download a full source tarball of nixpkgs. if you already have a local clone, using that may be faster due to delta compression:
</translate>


With this in place, you can now replace the use nix invocation in the <code>.envrc</code> file with <code>use flake</code>:
<syntaxHighlight>
 
git fetch upstream pull/<PR_NUMBER>/head && git checkout FETCH_HEAD && nix build .#PACKAGE
<syntaxHighlight lang=text>
# .envrc
use flake
</syntaxHighlight>
</syntaxHighlight>


The nice thing about this approach is that evaluation is cached.
<translate>
<!--T:163-->
this allows building a package that has not yet been added to nixpkgs.


==== Optimize the reloads ====
=== How to add a file locally in git but not include it in commits === <!--T:164-->


Nix Flakes has a Nix evaluation caching mechanism. Is it possible to expose that somehow to automatically trigger direnv reloads?
<!--T:133-->
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>):
</translate>


With the previous solution, direnv would only reload if the flake.nix or flake.lock files have changed. This is not completely precise as the flake.nix file might import other files in the repository.
<syntaxHighlight>
 
git add --intent-to-add extra/flake.nix
==== Setting the bash prompt like nix-shell ====
git update-index --skip-worktree --assume-unchanged extra/flake.nix
 
A [https://github.com/NixOS/nix/pull/4189 new experimental feature of flakes] allow to setup a bash-prompt per flake:
<syntaxHighlight lang=nix>
{
  description = "...";
  nixConfig.bash-prompt = "\[nix-develop\]$ ";
  ...
}
</syntaxHighlight>
</syntaxHighlight>


Otherwise it's also possible to set the <code>nix develop</code> bash prompt system wide using the [https://nixos.org/manual/nix/unstable/command-ref/conf-file.html nix.conf option bash-prompt]. (On nixos I think it is set in <code>nix.extraOptions</code>)
<translate>
=== Rapid iteration of a direct dependency === <!--T:135-->


== Pushing Flakes to Cachix ==
<!--T:165-->
One common pain point with using Nix as a development environment is the need to completely rebuild dependencies and re-enter the dev shell every time they are updated. The <code>nix develop --redirect <flake> <directory></code> command allows you to provide a mutable dependency to your shell as if it were built by Nix.


https://docs.cachix.org/pushing#flakes
<!--T:136-->
Consider a situation where your executable, <code>consumexe</code>, depends on a library, <code>libdep</code>. You're trying to work on both at the same time, where changes to <code>libdep</code> are reflected in real time for <code>consumexe</code>. This workflow can be achieved like so:
</translate>


To push ''all'' flake outputs automatically, use [https://github.com/srid/devour-flake#usage devour-flake].
<syntaxHighlight lang=bash>
 
cd ~/libdep-src-checkout/
== Build specific attributes in a flake repository ==
nix develop # Or `nix-shell` if applicable.
 
export prefix="./install" # configure nix to install it here
When in the repository top-level, run <code>nix build .#<attr></code>. It will look in the <code>legacyPackages</code> and <code>packages</code> output attributes for the corresponding derivation.
buildPhase  # build it like nix does
 
installPhase # install it like nix does
Eg, in nixpkgs:
 
<syntaxHighlight lang=console>
$ nix build .#hello
</syntaxHighlight>
</syntaxHighlight>


=== Building flakes from a Git repo url with submodules ===
<translate>
<!--T:166-->
Now that you've built the dependency, <code>consumexe</code> can take it as an input. '''In another terminal''':
</translate>


As per nix 2.9.1, git submodules in package <code>src</code>s won't get copied to the nix store, this may cause the build to fail.  To workaround this, use:
<syntaxHighlight lang=bash>
 
cd ~/consumexe-src-checkout/
<syntaxHighlight lang=console>
nix develop --redirect libdep ~/libdep-src-checkout/install
$ nix build .?submodules=1#hello
echo $buildInputs | tr " " "\n" | grep libdep
# Output should show ~/libdep-src-checkout/ so you know it worked
</syntaxHighlight>
</syntaxHighlight>


See: https://github.com/NixOS/nix/pull/5434
<translate>


== Importing packages from multiple channels ==
<!--T:167-->
If Nix warns you that your redirected flake isn't actually used as an input to the evaluated flake, try using the <code>--inputs-from .</code> flag. If all worked well you should be able to <code>buildPhase && installPhase</code> when the dependency changes and rebuild your consumer with the new version ''without'' exiting the development shell.


A NixOS config flake skeleton could be as follows:
== See also == <!--T:138-->
<syntaxHighlight lang=nix>
{
  description = "NixOS configuration with two or more channels";


  inputs = {
=== Official sources === <!--T:225-->
    nixpkgs.url = "nixpkgs/nixos-21.11";
    nixpkgs-unstable.url = "nixpkgs/nixos-unstable";
  };


  outputs = { self, nixpkgs, nixpkgs-unstable }:
<!--T:139-->
    let
* [https://nix.dev/concepts/flakes Flakes] - nix.dev
      system = "x86_64-linux";
      overlay-unstable = final: prev: {
        unstable = nixpkgs-unstable.legacyPackages.${prev.system};
        # use this variant if unfree packages are needed:
        # unstable = import nixpkgs-unstable {
        #  inherit system;
        #  config.allowUnfree = true;
        # };


      };
<!--T:176-->
    in {
* [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.
      nixosConfigurations."<hostname>" = nixpkgs.lib.nixosSystem {
        inherit system;
        modules = [
          # Overlays-module makes "pkgs.unstable" available in configuration.nix
          ({ config, pkgs, ... }: { nixpkgs.overlays = [ overlay-unstable ]; })
          ./configuration.nix
        ];
      };
    };
}
</syntaxHighlight>


<syntaxHighlight lang=nix>
<!--T:178-->
# NixOS configuration.nix, can now use "pkgs.package" or "pkgs.unstable.package"
* [https://github.com/NixOS/nix/blob/master/src/nix/flake.md spec describing flake inputs in more detail]
{ config, pkgs, ... }: {
  environment.systemPackages = [pkgs.firefox pkgs.unstable.chromium];
  # ...
}
</syntaxHighlight>
Same can be done with the NURs, as it already has an ''overlay'' attribute in the flake.nix of the project, you can just add <syntaxHighlight lang=nix>nixpkgs.overlays = [ nur.overlay ];</syntaxHighlight>


If the variable <code>nixpkgs</code> points to the flake, you can also define <code>pkgs</code> with overlays with:
<!--T:168-->
* [https://github.com/NixOS/rfcs/pull/49 RFC 49] (2019) - Original flakes specification


<syntaxHighlight lang=nix>
=== Guides === <!--T:226-->
pkgs = import nixpkgs { overlays = [ /*the overlay in question*/ ]; };
</syntaxHighlight>


== Getting ''Instant'' System Flakes Repl ==
<!--T:169-->
* [https://jade.fyi/blog/flakes-arent-real/ Flakes aren't real and can't hurt you] (Jade Lovelace, 2024)


How to get a nix repl out of your system flake:
<!--T:170-->
* [https://github.com/ryan4yin/nixos-and-flakes-book NixOS & Flakes Book](Ryan4yin, 2023) - 🛠️ ❤️ An unofficial NixOS & Flakes book for beginners.


<syntaxHighlight lang=text>
<!--T:171-->
# nix repl
* [https://xeiaso.net/blog/nix-flakes-1-2022-02-21 Nix Flakes: an Introduction] (Xe Iaso, 2022)
>> :lf /etc/nixos
>> nixosConfigurations.myhost.config
{ ... }
</syntaxHighlight>


Or out of your current flake:
<!--T:172-->
<syntaxHighlight lang=text>
* [https://serokell.io/blog/practical-nix-flakes Practical Nix Flakes] (Alexander Bantyev, 2021) - Intro article on working with Nix and Flakes
# nix repl
>> :lf .#
</syntaxHighlight>


You can then access to the inputs, outputs… For instance if you would like to check the default version of the kernel present in nixpgs:
<!--T:173-->
<syntaxHighlight lang=text>
* [https://www.tweag.io/blog/2020-05-25-flakes/ Nix Flakes, Part 1: An introduction and tutorial] (Eelco Dolstra, 2020)
nix-repl> inputs.nixpkgs.legacyPackages.x86_64-linux.linuxPackages.kernel.version
"5.15.74"
</syntaxHighlight>


However, this won't be instant upon evaluation if any file changes have been done since your last configuration rebuild. Instead, if one puts:
<!--T:174-->
* [https://www.tweag.io/blog/2020-06-25-eval-cache/ Nix Flakes, Part 2: Evaluation caching] (Eelco Dolstra, 2020)


<syntaxHighlight lang=nix>
<!--T:175-->
nix.nixPath = let path = toString ./.; in [ "repl=${path}/repl.nix" "nixpkgs=${inputs.nixpkgs}" ];
* [https://www.tweag.io/blog/2020-07-31-nixos-flakes/ Nix Flakes, Part 3: Managing NixOS systems] (Eelco Dolstra, 2020)
</syntaxHighlight>
 
In their system <code>flake.nix</code> configuration file, and includes the following file in their root directory flake as <code>repl.nix</code>:
 
<syntaxHighlight lang=nix>
let
  flake = builtins.getFlake (toString ./.);
  nixpkgs = import <nixpkgs> { };
in
{ inherit flake; }
// flake
// builtins
// nixpkgs
// nixpkgs.lib
// flake.nixosConfigurations
</syntaxHighlight>
 
(Don't forget to <code>git add repl.nix && nixos-rebuild  switch --flake "/etc/nixos"</code>)
Then one can run (or bind a shell alias):
 
<syntaxHighlight lang=bash>
source /etc/set-environment && nix repl $(echo $NIX_PATH | perl -pe 's|.*(/nix/store/.*-source/repl.nix).*|\1|')</syntaxHighlight>
 
This will launch a repl with access to <code>nixpkgs</code>, <code>lib</code>, and the <code>flake</code> options in a split of a second.
 
An alternative approach to the above shell alias is omitting <code>repl</code> from <code>nix.nixPath</code> and creating a shell script:
<syntaxHighlight lang=nix>
nix.nixPath = [ "nixpkgs=${inputs.nixpkgs}" ];
environment.systemPackages = let
  repl_path = toString ./.;
  my-nix-fast-repl = pkgs.writeShellScriptBin "my-nix-fast-repl" ''
    source /etc/set-environment
    nix repl "${repl_path}/repl.nix" "$@"
  '';
in [
  my-nix-fast-repl
];
</syntaxHighlight>
 
== Enable unfree software ==
 
Refer to [[Unfree Software]].
 
== Development tricks ==
=== How to add a file locally in git but not include it in commits ===
 
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>):


<syntaxHighlight>
<!--T:177-->
git add --intent-to-add extra/flake.nix
* [https://www.youtube.com/watch?v=QXUlhnhuRX4&list=PLgknCdxP89RcGPTjngfNR9WmBgvD_xW0l Nix flakes 101: Introduction to nix flakes] (Jörg Thalheim, 2020) YouTube video
git update-index --skip-worktree extra/flake.nix
</syntaxHighlight>


=== Rapid iteration of a direct dependency ===
=== Useful flake modules === <!--T:227-->  
One common pain point with using Nix as a development environment is the need to completely rebuild dependencies and re-enter the dev shell every time they are updated. The <code>nix develop --redirect <flake> <directory></code> command allows you to provide a mutable dependency to your shell as if it were built by Nix.


Consider a situation where your executable, <code>consumexe</code>, depends on a library, <code>libdep</code>. You're trying to work on both at the same time, where changes to <code>libdep</code> are reflected in real time for <code>consumexe</code>. This workflow can be achieved like so:
<!--T:179-->
* [[Flake Utils|flake-utils]]: Library to avoid some boiler-code when writing flakes


<syntaxHighlight lang=bash>
<!--T:228-->
cd ~/libdep-src-checkout/
* [[Flake Parts|flake-parts]]: Library to help write modular and organized flakes
nix develop # Or `nix-shell` if applicable.
export prefix="./install" # configure nix to install it here
buildPhase  # build it like nix does
installPhase # install it like nix does
</syntaxHighlight>
Now that you've built the dependency, <code>consumexe</code> can take it as an input. '''In another terminal''':
<syntaxHighlight lang=bash>
cd ~/consumexe-src-checkout/
nix develop --redirect libdep ~/libdep-src-checkout/install
echo $buildInputs | tr " " "\n" | grep libdep
# Output should show ~/libdep-src-checkout/ so you know it worked
</syntaxHighlight>
If Nix warns you that your redirected flake isn't actually used as an input to the evaluated flake, try using the <code>--inputs-from .</code> flag. If all worked well you should be able to <code>buildPhase && installPhase</code> when the dependency changes and rebuild your consumer with the new version ''without'' exiting the development shell.


== See also ==
<!--T:229-->
* [[Flake Compat|flake-compat]]: A compatibility layer for flakes


* [https://www.tweag.io/blog/2020-05-25-flakes/ Nix Flakes, Part 1: An introduction and tutorial] (Eelco Dolstra, 2020)
<!--T:181-->
* [https://www.tweag.io/blog/2020-06-25-eval-cache/ Nix Flakes, Part 2: Evaluation caching] (Eelco Dolstra, 2020)
* [https://www.tweag.io/blog/2020-07-31-nixos-flakes/ Nix Flakes, Part 3: Managing NixOS systems] (Eelco Dolstra, 2020)
* [https://github.com/ryan4yin/nixos-and-flakes-book NixOS & Flakes Book](Ryan4yin, 2023) - 🛠️ ❤️ An unofficial NixOS & Flakes book for beginners.
* [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.
* [https://xeiaso.net/blog/nix-flakes-1-2022-02-21 Nix Flakes: an Introduction] (Xe Iaso, 2022)
* [https://serokell.io/blog/practical-nix-flakes Practical Nix Flakes] (Alexander Bantyev, 2021) - Intro article on working with Nix and Flakes
* [https://www.youtube.com/watch?v=QXUlhnhuRX4&list=PLgknCdxP89RcGPTjngfNR9WmBgvD_xW0l Nix flakes 101: Introduction to nix flakes] (Jörg Thalheim, 2020)
* [https://github.com/NixOS/rfcs/pull/49 RFC 49] (2019) - Original flakes specification
* [https://github.com/NixOS/nix/blob/master/src/nix/flake.md spec describing flake inputs in more detail]
* [https://github.com/numtide/flake-utils flake-utils: Library to avoid some boiler-code when writing flakes]
* [https://zimbatm.com/NixFlakes/#direnv-integration zimbat's direnv article]
* [https://github.com/nix-community/todomvc-nix building Rust and Haskell flakes]
* [https://github.com/nix-community/todomvc-nix building Rust and Haskell flakes]
</translate>


{{references}}


[[Category:Software]]
<translate>
[[Category:Nix]]
<!--T:230-->
[[Category:Flakes]]
[[Category:Software|Software]]
[[Category:Nix|Nix]]
[[Category:Nix Language|Nix Language]]
[[Category:Flakes|Flakes]]
</translate>