<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.nixos.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Pigs</id>
	<title>Official NixOS Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.nixos.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Pigs"/>
	<link rel="alternate" type="text/html" href="https://wiki.nixos.org/wiki/Special:Contributions/Pigs"/>
	<updated>2026-04-09T01:15:48Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.45.0</generator>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=Flakes&amp;diff=29529</id>
		<title>Flakes</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=Flakes&amp;diff=29529"/>
		<updated>2026-01-22T16:47:33Z</updated>

		<summary type="html">&lt;p&gt;Pigs: Update link to manual to use stable instead of hard coded version&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;languages /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Cleanup}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:182--&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Nix flakes&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:183--&amp;gt;&lt;br /&gt;
A flake is a directory which directly contains a Nix file called &amp;lt;code&amp;gt;flake.nix&amp;lt;/code&amp;gt;, 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 &amp;lt;code&amp;gt;github:NixOS/nixpkgs&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:184--&amp;gt;&lt;br /&gt;
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}}&lt;br /&gt;
&lt;br /&gt;
== Flake file structure == &amp;lt;!--T:185--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:231--&amp;gt;&lt;br /&gt;
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:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{File|3=&amp;lt;nowiki&amp;gt;{&lt;br /&gt;
  description = &amp;quot;A very basic flake&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
  inputs = {&lt;br /&gt;
    nixpkgs.url = &amp;quot;github:nixos/nixpkgs?ref=nixos-unstable&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
&lt;br /&gt;
  outputs = { self, nixpkgs }: {&lt;br /&gt;
    packages.x86_64-linux = {&lt;br /&gt;
      default = self.packages.x86_64-linux.hello;&lt;br /&gt;
      hello = nixpkgs.legacyPackages.x86_64-linux.hello;&lt;br /&gt;
    };&lt;br /&gt;
  };&lt;br /&gt;
}&amp;lt;/nowiki&amp;gt;|name=flake.nix|lang=nix}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:190--&amp;gt;&lt;br /&gt;
In the example above, you can see the description, the input specified as a GitHub repository with a specific branch (here &amp;lt;code&amp;gt;nixos/nixpkgs&amp;lt;/code&amp;gt; on the &amp;lt;code&amp;gt;nixos-unstable&amp;lt;/code&amp;gt; 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 &amp;lt;code&amp;gt;hello&amp;lt;/code&amp;gt;. Even if your flake&#039;s output wouldn&#039;t use its input (however, in practice, that is highly unlikely), the output still needs to be a Nix function.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:232--&amp;gt;&lt;br /&gt;
{{Note|Flakes require you to specify its outputs for each architecture separately. For more information, read the related section below.}}&lt;br /&gt;
&lt;br /&gt;
=== Nix configuration === &amp;lt;!--T:191--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:233--&amp;gt;&lt;br /&gt;
It is possible to override the global Nix configuration set in your &amp;lt;code&amp;gt;nix.conf&amp;lt;/code&amp;gt; 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:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{File|3=&amp;lt;nowiki&amp;gt;{&lt;br /&gt;
  ...&lt;br /&gt;
  nixConfig = {&lt;br /&gt;
    extra-substituters = [&lt;br /&gt;
      &amp;quot;https://nix-community.cachix.org&amp;quot;&lt;br /&gt;
    ];&lt;br /&gt;
    extra-trusted-public-keys = [&lt;br /&gt;
      &amp;quot;nix-community.cachix.org-1:...=&amp;quot;&lt;br /&gt;
    ];&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/nowiki&amp;gt;|name=flake.nix|lang=nix}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:234--&amp;gt;&lt;br /&gt;
{{Note|If you are used to configuring your Nix settings via the NixOS configuration, these options are under &amp;lt;code&amp;gt;nix.settings&amp;lt;/code&amp;gt; and not &amp;lt;code&amp;gt;nix&amp;lt;/code&amp;gt;. For example, you cannot specify the automatic storage optimisation under &amp;lt;code&amp;gt;nix.optimisation.enable&amp;lt;/code&amp;gt;.}}&lt;br /&gt;
&lt;br /&gt;
== Setup == &amp;lt;!--T:192--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enabling flakes temporarily === &amp;lt;!--T:5--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:6--&amp;gt;&lt;br /&gt;
When using any [[Nix command|&amp;lt;code&amp;gt;nix&amp;lt;/code&amp;gt; command]], add the following command-line options:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
 --experimental-features &#039;nix-command flakes&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Enabling flakes permanently === &amp;lt;!--T:193--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== NixOS ==== &amp;lt;!--T:7--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:8--&amp;gt;&lt;br /&gt;
Add the following to the [[Overview_of_the_NixOS_Linux_distribution#Declarative_Configuration system configuration |NixOS configuration]]:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxHighlight lang=nix&amp;gt;&lt;br /&gt;
  nix.settings.experimental-features = [ &amp;quot;nix-command&amp;quot; &amp;quot;flakes&amp;quot; ];&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
====Home Manager==== &amp;lt;!--T:10--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:11--&amp;gt;&lt;br /&gt;
Add the following to your [[Home Manager|home manager]] config:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
  nix.settings.experimental-features = [ &amp;quot;nix-command&amp;quot; &amp;quot;flakes&amp;quot; ];&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
====Nix standalone==== &amp;lt;!--T:13--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:14--&amp;gt;&lt;br /&gt;
{{Note | The  [https://github.com/DeterminateSystems/nix-installer Determinate Nix Installer] enables flakes by default, but installs the proprietary Determinate Nix.}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:15--&amp;gt;&lt;br /&gt;
Add the following to &amp;lt;code&amp;gt;~/.config/nix/nix.conf&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;/etc/nix/nix.conf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxHighlight lang=text&amp;gt;&lt;br /&gt;
experimental-features = nix-command flakes&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
== Usage == &amp;lt;!--T:17--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:20--&amp;gt;&lt;br /&gt;
{{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]].}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:146--&amp;gt;&lt;br /&gt;
{{Note | For flakes in [[git]] repositories, only files in the working tree will be copied to the store.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:22--&amp;gt;&lt;br /&gt;
Therefore, if you use &amp;lt;code&amp;gt;git&amp;lt;/code&amp;gt; for your flake, ensure to &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; any project files after you first create them.}}&lt;br /&gt;
&lt;br /&gt;
=== The nix flakes command === &amp;lt;!--T:64--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Main|Nix (command)}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:65--&amp;gt;&lt;br /&gt;
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}}.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:194--&amp;gt;&lt;br /&gt;
This flake produces a single flake output &amp;lt;code&amp;gt;packages&amp;lt;/code&amp;gt;. And within that, &amp;lt;code&amp;gt;x86_64-linux&amp;lt;/code&amp;gt; is a system-specifc attribute set. And within that, two package [[derivations]] &amp;lt;code&amp;gt;default&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;hello&amp;lt;/code&amp;gt;. 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:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
$ nix flake show&lt;br /&gt;
└───packages&lt;br /&gt;
    └───x86_64-linux&lt;br /&gt;
        ├───default: package &#039;hello-2.12.2&#039;&lt;br /&gt;
        └───hello: package &#039;hello-2.12.2&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== Development shells ==== &amp;lt;!--T:196--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:197--&amp;gt;&lt;br /&gt;
A &amp;lt;code&amp;gt;devShell&amp;lt;/code&amp;gt; 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 &amp;lt;code&amp;gt;nix-shell&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  description = &amp;quot;Example flake with a devShell&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
  inputs.nixpkgs.url = &amp;quot;github:nixos/nixpkgs?ref=nixos-unstable&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
  outputs = { self, nixpkgs }:&lt;br /&gt;
    let&lt;br /&gt;
      system = &amp;quot;x86_64-linux&amp;quot;;&lt;br /&gt;
      pkgs = import nixpkgs { inherit system; };&lt;br /&gt;
    in {&lt;br /&gt;
      devShells.x86_64-linux.default = pkgs.mkShell {&lt;br /&gt;
        buildInputs = with pkgs; [&lt;br /&gt;
          hello&lt;br /&gt;
        ];&lt;br /&gt;
        shellHook = &#039;&#039;&lt;br /&gt;
          echo &amp;quot;Welcome to the devShell!&amp;quot;&lt;br /&gt;
        &#039;&#039;;&lt;br /&gt;
      };&lt;br /&gt;
    };&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:201--&amp;gt;&lt;br /&gt;
To enter the development shell environment:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
$ nix develop&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:203--&amp;gt;&lt;br /&gt;
{{note|You don’t need to define a devShell to enter a development shell using nix develop.&lt;br /&gt;
If no devShell is defined, nix develop will drop you into an environment containing the default build dependencies of the flake (if any).}}&lt;br /&gt;
&lt;br /&gt;
==== Build specific attributes in a flake repository ==== &amp;lt;!--T:102--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:103--&amp;gt;&lt;br /&gt;
Running &amp;lt;code&amp;gt;nix build&amp;lt;/code&amp;gt; will look in the &amp;lt;code&amp;gt;legacyPackages&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;packages&amp;lt;/code&amp;gt; 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 &amp;lt;code&amp;gt;nix build .#&amp;lt;attr&amp;gt;&amp;lt;/code&amp;gt;. In the example above, if you wanted to build the &amp;lt;code&amp;gt;packages.x86_64-linux.hello&amp;lt;/code&amp;gt; attribute, run:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxHighlight lang=console&amp;gt;&lt;br /&gt;
$ nix build .#hello&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:205--&amp;gt;&lt;br /&gt;
Likewise, you can specify an attribute with the run command: &amp;lt;code&amp;gt;nix run .#hello&amp;lt;/code&amp;gt; and the develop command: &amp;lt;code&amp;gt;nix develop .#hello&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Flake schema == &amp;lt;!--T:27--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:28--&amp;gt;&lt;br /&gt;
The flake.nix file is a Nix file but that has special restrictions (more on that later).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:29--&amp;gt;&lt;br /&gt;
It has 4 top-level attributes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:30--&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;description&amp;lt;/code&amp;gt; is a string describing the flake.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:147--&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;inputs&amp;lt;/code&amp;gt; is an attribute set of all the dependencies of the flake. The schema is described below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:148--&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;outputs&amp;lt;/code&amp;gt; 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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:149--&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;nixConfig&amp;lt;/code&amp;gt; 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&#039;s nix experience by adding flake-specific configuration, such as a [[Binary Cache|binary cache]].&lt;br /&gt;
&lt;br /&gt;
=== Input schema === &amp;lt;!--T:31--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:32--&amp;gt;&lt;br /&gt;
[https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake.html#flake-inputs The nix flake inputs manual].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:150--&amp;gt;&lt;br /&gt;
[https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake.html#flake-references The nix flake references manual].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:33--&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:34--&amp;gt;&lt;br /&gt;
[[Nixpkgs]] can be defined using the following code:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;inputs.nixpkgs.url = &amp;quot;github:NixOS/nixpkgs/&amp;lt;branch name&amp;gt;&amp;quot;;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:235--&amp;gt;&lt;br /&gt;
Nixpkgs can alternatively also point to an url cached by the NixOS organization:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;inputs.nixpkgs.url = &amp;quot;&amp;lt;nowiki&amp;gt;https://nixos.org/channels/nixpkgs-unstable/nixexprs.tar.xz&amp;lt;/nowiki&amp;gt;&amp;quot;;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:236--&amp;gt;&lt;br /&gt;
In this example the input would point to the `nixpkgs-unstable` channel.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:36--&amp;gt;&lt;br /&gt;
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&#039;s on GitHub is unnecessary.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:37--&amp;gt;&lt;br /&gt;
For example, adding [[Hyprland]] as an input would look something like this:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;inputs.hyprland.url = &amp;quot;github:hyprwm/Hyprland&amp;quot;;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:39--&amp;gt;&lt;br /&gt;
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:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;inputs.hyprland.inputs.nixpkgs.follows = &amp;quot;nixpkgs&amp;quot;;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:41--&amp;gt;&lt;br /&gt;
Using curly brackets (&amp;lt;code&amp;gt;{}&amp;lt;/code&amp;gt;), we can shorten all of this and put it in a table. The code will look something like this:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
inputs = {&lt;br /&gt;
  nixpkgs.url = &amp;quot;github:NixOS/nixpkgs/&amp;lt;branch name&amp;gt;&amp;quot;;&lt;br /&gt;
  hyprland = {&lt;br /&gt;
    url = &amp;quot;github:hyprwm/Hyprland&amp;quot;;&lt;br /&gt;
    inputs.nixpkgs.follows = &amp;quot;nixpkgs&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:206--&amp;gt;&lt;br /&gt;
By default, Git submodules in package &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt;&#039;s won&#039;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:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
  inputs.self.submodules = true;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Output schema === &amp;lt;!--T:42--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:151--&amp;gt;&lt;br /&gt;
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].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:43--&amp;gt;&lt;br /&gt;
Once the inputs are resolved, they&#039;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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:44--&amp;gt;&lt;br /&gt;
Where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:45--&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;&amp;lt;system&amp;gt;&amp;lt;/code&amp;gt; is something like &amp;quot;x86_64-linux&amp;quot;, &amp;quot;aarch64-linux&amp;quot;, &amp;quot;i686-linux&amp;quot;, &amp;quot;x86_64-darwin&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:152--&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;&amp;lt;name&amp;gt;&amp;lt;/code&amp;gt; is an attribute name like &amp;quot;hello&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:153--&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;&amp;lt;flake&amp;gt;&amp;lt;/code&amp;gt; is a flake name like &amp;quot;nixpkgs&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:154--&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;&amp;lt;store-path&amp;gt;&amp;lt;/code&amp;gt; is a &amp;lt;code&amp;gt;/nix/store..&amp;lt;/code&amp;gt; path&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
{ self, ... }@inputs:&lt;br /&gt;
{&lt;br /&gt;
  # Executed by `nix flake check`&lt;br /&gt;
  checks.&amp;quot;&amp;lt;system&amp;gt;&amp;quot;.&amp;quot;&amp;lt;name&amp;gt;&amp;quot; = derivation;&lt;br /&gt;
  # Executed by `nix build .#&amp;lt;name&amp;gt;`&lt;br /&gt;
  packages.&amp;quot;&amp;lt;system&amp;gt;&amp;quot;.&amp;quot;&amp;lt;name&amp;gt;&amp;quot; = derivation;&lt;br /&gt;
  # Executed by `nix build .`&lt;br /&gt;
  packages.&amp;quot;&amp;lt;system&amp;gt;&amp;quot;.default = derivation;&lt;br /&gt;
  # Executed by `nix run .#&amp;lt;name&amp;gt;`&lt;br /&gt;
  apps.&amp;quot;&amp;lt;system&amp;gt;&amp;quot;.&amp;quot;&amp;lt;name&amp;gt;&amp;quot; = {&lt;br /&gt;
    type = &amp;quot;app&amp;quot;;&lt;br /&gt;
    program = &amp;quot;&amp;lt;store-path&amp;gt;&amp;quot;;&lt;br /&gt;
    meta = {description = &amp;quot;...&amp;quot;; inherit otherMetaAttrs; };&lt;br /&gt;
  };&lt;br /&gt;
  # Executed by `nix run . -- &amp;lt;args?&amp;gt;`&lt;br /&gt;
  apps.&amp;quot;&amp;lt;system&amp;gt;&amp;quot;.default = { type = &amp;quot;app&amp;quot;; program = &amp;quot;...&amp;quot;; meta = {description = &amp;quot;...&amp;quot;; inherit otherMetaAttrs; }; };&lt;br /&gt;
&lt;br /&gt;
  # Formatter (alejandra, nixfmt, treefmt-nix or nixpkgs-fmt)&lt;br /&gt;
  formatter.&amp;quot;&amp;lt;system&amp;gt;&amp;quot; = derivation;&lt;br /&gt;
  # Used for nixpkgs packages, also accessible via `nix build .#&amp;lt;name&amp;gt;`&lt;br /&gt;
  legacyPackages.&amp;quot;&amp;lt;system&amp;gt;&amp;quot;.&amp;quot;&amp;lt;name&amp;gt;&amp;quot; = derivation;&lt;br /&gt;
  # Overlay, consumed by other flakes&lt;br /&gt;
  overlays.&amp;quot;&amp;lt;name&amp;gt;&amp;quot; = final: prev: { };&lt;br /&gt;
  # Default overlay&lt;br /&gt;
  overlays.default = final: prev: { };&lt;br /&gt;
  # Nixos module, consumed by other flakes&lt;br /&gt;
  nixosModules.&amp;quot;&amp;lt;name&amp;gt;&amp;quot; = { config, ... }: { options = {}; config = {}; };&lt;br /&gt;
  # Default module&lt;br /&gt;
  nixosModules.default = { config, ... }: { options = {}; config = {}; };&lt;br /&gt;
  # Used with `nixos-rebuild switch --flake .#&amp;lt;hostname&amp;gt;`&lt;br /&gt;
  # nixosConfigurations.&amp;quot;&amp;lt;hostname&amp;gt;&amp;quot;.config.system.build.toplevel must be a derivation&lt;br /&gt;
  nixosConfigurations.&amp;quot;&amp;lt;hostname&amp;gt;&amp;quot; = {};&lt;br /&gt;
  # Used by `nix develop .#&amp;lt;name&amp;gt;`&lt;br /&gt;
  devShells.&amp;quot;&amp;lt;system&amp;gt;&amp;quot;.&amp;quot;&amp;lt;name&amp;gt;&amp;quot; = derivation;&lt;br /&gt;
  # Used by `nix develop`&lt;br /&gt;
  devShells.&amp;quot;&amp;lt;system&amp;gt;&amp;quot;.default = derivation;&lt;br /&gt;
  # Hydra build jobs&lt;br /&gt;
  hydraJobs.&amp;quot;&amp;lt;attr&amp;gt;&amp;quot;.&amp;quot;&amp;lt;system&amp;gt;&amp;quot; = derivation;&lt;br /&gt;
  # Used by `nix flake init -t &amp;lt;flake&amp;gt;#&amp;lt;name&amp;gt;`&lt;br /&gt;
  templates.&amp;quot;&amp;lt;name&amp;gt;&amp;quot; = {&lt;br /&gt;
    path = &amp;quot;&amp;lt;store-path&amp;gt;&amp;quot;;&lt;br /&gt;
    description = &amp;quot;template description goes here?&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
  # Used by `nix flake init -t &amp;lt;flake&amp;gt;`&lt;br /&gt;
  templates.default = { path = &amp;quot;&amp;lt;store-path&amp;gt;&amp;quot;; description = &amp;quot;&amp;quot;; };&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:48--&amp;gt;&lt;br /&gt;
You can also define additional arbitrary attributes, but these are the outputs that Nix knows about.&lt;br /&gt;
&lt;br /&gt;
== Core usage patterns == &amp;lt;!--T:208--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Making your evaluations pure === &amp;lt;!--T:60--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:61--&amp;gt;&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:62--&amp;gt;&lt;br /&gt;
* {{Nixpkgs Manual|name=fetchurl|anchor=#sec-pkgs-fetchers-fetchurl-inputs}} and {{Nixpkgs Manual|name=fetchzip|anchor=#sec-pkgs-fetchers-fetchzip-inputs}} require a &amp;lt;code&amp;gt;sha256&amp;lt;/code&amp;gt; argument to be considered pure.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:156--&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;builtins.currentSystem&amp;lt;/code&amp;gt; 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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:209--&amp;gt;&lt;br /&gt;
*  &amp;lt;code&amp;gt;builtins.getEnv&amp;lt;/code&amp;gt; is also impure. Avoid reading from environment variables and likewise, do not reference files outside of the flake&#039;s directory.&lt;br /&gt;
&lt;br /&gt;
=== Defining a flake for multiple architectures === &amp;lt;!--T:210--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:211--&amp;gt;&lt;br /&gt;
Flakes force you to specify a program for each supported architecture. An example below shows how to write a flake that targets multiple architectures.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  description = &amp;quot;A flake targeting multiple architectures&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
inputs = {&lt;br /&gt;
    nixpkgs.url = &amp;quot;github:nixos/nixpkgs?ref=nixos-unstable&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
&lt;br /&gt;
outputs = { self, nixpkgs }: let&lt;br /&gt;
    systems = [ &amp;quot;x86_64-linux&amp;quot; &amp;quot;aarch64-linux&amp;quot; ];&lt;br /&gt;
    forAllSystems = f: builtins.listToAttrs (map (system: {&lt;br /&gt;
      name = system;&lt;br /&gt;
      value = f system;&lt;br /&gt;
    }) systems);&lt;br /&gt;
  in {&lt;br /&gt;
    packages = forAllSystems (system: let&lt;br /&gt;
      pkgs = nixpkgs.legacyPackages.${system};&lt;br /&gt;
    in {&lt;br /&gt;
      hello = pkgs.hello;&lt;br /&gt;
      default = pkgs.hello;&lt;br /&gt;
    });&lt;br /&gt;
  };&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:215--&amp;gt;&lt;br /&gt;
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]]&lt;br /&gt;
&lt;br /&gt;
=== Using overlays === &amp;lt;!--T:216--&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:217--&amp;gt;&lt;br /&gt;
To use [[Overlays]] with flakes, refer to [[Overlays#In a Nix flake]] page.&lt;br /&gt;
&lt;br /&gt;
=== Enable unfree software === &amp;lt;!--T:129--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:218--&amp;gt;&lt;br /&gt;
To allow for [[Unfree software|unfree software]] in a flake project, you need to explicitly allow it by setting &amp;lt;code&amp;gt;config.allowUnree = true;&amp;lt;/code&amp;gt; when importing Nixpkgs.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  inputs.nixpkgs.url = &amp;quot;github:nixos/nixpkgs?ref=nixos-unstable&amp;quot;;&lt;br /&gt;
  outputs = { self, nixpkgs, flake-compat }:&lt;br /&gt;
    let&lt;br /&gt;
      system = &amp;quot;x86_64-linux&amp;quot;;&lt;br /&gt;
      pkgs = import nixpkgs { inherit system; config.allowUnfree = true;};&lt;br /&gt;
    in {&lt;br /&gt;
      ...&lt;br /&gt;
    };&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
== NixOS configuration with flakes == &amp;lt;!--T:220--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:221--&amp;gt;&lt;br /&gt;
It is possible to manage a [[NixOS]] system configuration using flakes, gaining the benefits of reproducible, declarative inputs and streamlined updates.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:222--&amp;gt;&lt;br /&gt;
For details and examples, see [[NixOS system configuration#Defining NixOS as a flake]].&lt;br /&gt;
&lt;br /&gt;
== Development tricks == &amp;lt;!--T:131--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Automatically switch nix shells with direnv === &amp;lt;!--T:97--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:98--&amp;gt;&lt;br /&gt;
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].&lt;br /&gt;
&lt;br /&gt;
=== Pushing Flakes to Cachix === &amp;lt;!--T:99--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
https://docs.cachix.org/pushing#flakes&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Flake support in projects without flakes === &amp;lt;!--T:50--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:51--&amp;gt;&lt;br /&gt;
The [https://github.com/edolstra/flake-compat flake-compat] library provides a compatibility layer that allows projects using traditional &amp;lt;code&amp;gt;default.nix&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;shell.nix&amp;lt;/code&amp;gt; files to operate with flakes. For more details and usage examples, see the [[Flake Compat]] page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:223--&amp;gt;&lt;br /&gt;
Another project that allows consuming flakes from non-flake projects is [https://github.com/fricklerhandwerk/flake-inputs flake-inputs].&lt;br /&gt;
&lt;br /&gt;
=== Accessing flakes from Nix expressions === &amp;lt;!--T:58--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:59--&amp;gt;&lt;br /&gt;
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 &amp;lt;code&amp;gt;(builtins.getFlake &amp;quot;/path/to/directory&amp;quot;).packages.x86_64-linux.default&amp;lt;/code&amp;gt;, where &#039;directory&#039; is the directory that contains your &amp;lt;code&amp;gt;flake.nix&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Efficiently build multiple flake outputs === &amp;lt;!--T:224--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:101--&amp;gt;&lt;br /&gt;
To push &#039;&#039;all&#039;&#039; flake outputs automatically, checkout [https://github.com/srid/devour-flake#usage devour-flake].&lt;br /&gt;
&lt;br /&gt;
=== Build a package added in a PR === &amp;lt;!--T:161--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxHighlight&amp;gt;&lt;br /&gt;
nix build github:nixos/nixpkgs?ref=pull/&amp;lt;PR_NUMBER&amp;gt;/head#&amp;lt;PACKAGE&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:162--&amp;gt;&lt;br /&gt;
this allows building a package that has not yet been added to nixpkgs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:132--&amp;gt;&lt;br /&gt;
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:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxHighlight&amp;gt;&lt;br /&gt;
git fetch upstream pull/&amp;lt;PR_NUMBER&amp;gt;/head &amp;amp;&amp;amp; git checkout FETCH_HEAD &amp;amp;&amp;amp; nix build .#PACKAGE&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:163--&amp;gt;&lt;br /&gt;
this allows building a package that has not yet been added to nixpkgs.&lt;br /&gt;
&lt;br /&gt;
=== How to add a file locally in git but not include it in commits === &amp;lt;!--T:164--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:133--&amp;gt;&lt;br /&gt;
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 &amp;lt;code&amp;gt;extra/flake.nix&amp;lt;/code&amp;gt;):&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxHighlight&amp;gt;&lt;br /&gt;
git add --intent-to-add extra/flake.nix&lt;br /&gt;
git update-index --skip-worktree --assume-unchanged extra/flake.nix&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Rapid iteration of a direct dependency === &amp;lt;!--T:135--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:165--&amp;gt;&lt;br /&gt;
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 &amp;lt;code&amp;gt;nix develop --redirect &amp;lt;flake&amp;gt; &amp;lt;directory&amp;gt;&amp;lt;/code&amp;gt; command allows you to provide a mutable dependency to your shell as if it were built by Nix.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:136--&amp;gt;&lt;br /&gt;
Consider a situation where your executable, &amp;lt;code&amp;gt;consumexe&amp;lt;/code&amp;gt;, depends on a library, &amp;lt;code&amp;gt;libdep&amp;lt;/code&amp;gt;. You&#039;re trying to work on both at the same time, where changes to &amp;lt;code&amp;gt;libdep&amp;lt;/code&amp;gt; are reflected in real time for &amp;lt;code&amp;gt;consumexe&amp;lt;/code&amp;gt;. This workflow can be achieved like so:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxHighlight lang=bash&amp;gt;&lt;br /&gt;
cd ~/libdep-src-checkout/&lt;br /&gt;
nix develop # Or `nix-shell` if applicable.&lt;br /&gt;
export prefix=&amp;quot;./install&amp;quot; # configure nix to install it here&lt;br /&gt;
buildPhase   # build it like nix does&lt;br /&gt;
installPhase # install it like nix does&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:166--&amp;gt;&lt;br /&gt;
Now that you&#039;ve built the dependency, &amp;lt;code&amp;gt;consumexe&amp;lt;/code&amp;gt; can take it as an input. &#039;&#039;&#039;In another terminal&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxHighlight lang=bash&amp;gt;&lt;br /&gt;
cd ~/consumexe-src-checkout/&lt;br /&gt;
nix develop --redirect libdep ~/libdep-src-checkout/install&lt;br /&gt;
echo $buildInputs | tr &amp;quot; &amp;quot; &amp;quot;\n&amp;quot; | grep libdep&lt;br /&gt;
# Output should show ~/libdep-src-checkout/ so you know it worked&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:167--&amp;gt;&lt;br /&gt;
If Nix warns you that your redirected flake isn&#039;t actually used as an input to the evaluated flake, try using the &amp;lt;code&amp;gt;--inputs-from .&amp;lt;/code&amp;gt; flag. If all worked well you should be able to &amp;lt;code&amp;gt;buildPhase &amp;amp;&amp;amp; installPhase&amp;lt;/code&amp;gt; when the dependency changes and rebuild your consumer with the new version &#039;&#039;without&#039;&#039; exiting the development shell.&lt;br /&gt;
&lt;br /&gt;
== See also == &amp;lt;!--T:138--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Official sources === &amp;lt;!--T:225--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:139--&amp;gt;&lt;br /&gt;
* [https://nix.dev/concepts/flakes Flakes] - nix.dev&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:176--&amp;gt;&lt;br /&gt;
* [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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:178--&amp;gt;&lt;br /&gt;
* [https://github.com/NixOS/nix/blob/master/src/nix/flake.md spec describing flake inputs in more detail]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:168--&amp;gt;&lt;br /&gt;
* [https://github.com/NixOS/rfcs/pull/49 RFC 49] (2019) - Original flakes specification&lt;br /&gt;
&lt;br /&gt;
=== Guides === &amp;lt;!--T:226--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:169--&amp;gt;&lt;br /&gt;
* [https://jade.fyi/blog/flakes-arent-real/ Flakes aren&#039;t real and can&#039;t hurt you] (Jade Lovelace, 2024)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:170--&amp;gt;&lt;br /&gt;
* [https://github.com/ryan4yin/nixos-and-flakes-book NixOS &amp;amp; Flakes Book](Ryan4yin, 2023) - 🛠️ ❤️ An unofficial NixOS &amp;amp; Flakes book for beginners.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:171--&amp;gt;&lt;br /&gt;
* [https://xeiaso.net/blog/nix-flakes-1-2022-02-21 Nix Flakes: an Introduction] (Xe Iaso, 2022)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:172--&amp;gt;&lt;br /&gt;
* [https://serokell.io/blog/practical-nix-flakes Practical Nix Flakes] (Alexander Bantyev, 2021) - Intro article on working with Nix and Flakes&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:173--&amp;gt;&lt;br /&gt;
* [https://www.tweag.io/blog/2020-05-25-flakes/ Nix Flakes, Part 1: An introduction and tutorial] (Eelco Dolstra, 2020)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:174--&amp;gt;&lt;br /&gt;
* [https://www.tweag.io/blog/2020-06-25-eval-cache/ Nix Flakes, Part 2: Evaluation caching] (Eelco Dolstra, 2020)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:175--&amp;gt;&lt;br /&gt;
* [https://www.tweag.io/blog/2020-07-31-nixos-flakes/ Nix Flakes, Part 3: Managing NixOS systems] (Eelco Dolstra, 2020)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:177--&amp;gt;&lt;br /&gt;
* [https://www.youtube.com/watch?v=QXUlhnhuRX4&amp;amp;list=PLgknCdxP89RcGPTjngfNR9WmBgvD_xW0l Nix flakes 101: Introduction to nix flakes] (Jörg Thalheim, 2020) YouTube video&lt;br /&gt;
&lt;br /&gt;
=== Useful flake modules === &amp;lt;!--T:227--&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:179--&amp;gt;&lt;br /&gt;
* [[Flake Utils|flake-utils]]: Library to avoid some boiler-code when writing flakes&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:228--&amp;gt;&lt;br /&gt;
* [[Flake Parts|flake-parts]]: Library to help write modular and organized flakes&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:229--&amp;gt;&lt;br /&gt;
* [[Flake Compat|flake-compat]]: A compatibility layer for flakes&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:181--&amp;gt;&lt;br /&gt;
* [https://github.com/nix-community/todomvc-nix building Rust and Haskell flakes]&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{references}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:230--&amp;gt;&lt;br /&gt;
[[Category:Software|Software]]&lt;br /&gt;
[[Category:Nix|Nix]]&lt;br /&gt;
[[Category:Nix Language|Nix Language]]&lt;br /&gt;
[[Category:Flakes|Flakes]]&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=Emacs&amp;diff=29407</id>
		<title>Emacs</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=Emacs&amp;diff=29407"/>
		<updated>2026-01-09T23:24:42Z</updated>

		<summary type="html">&lt;p&gt;Pigs: /* Configuration */ provide a clearer list of possible ways to configure emacs&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{application infobox&lt;br /&gt;
  |name=GNU Emacs&lt;br /&gt;
  |image=EmacsIcon.svg&lt;br /&gt;
  |type=Text Editor&lt;br /&gt;
  |firstRelease=1985; 40 years ago&lt;br /&gt;
  |license=[https://www.gnu.org/licenses/gpl.html GNU General Public License]&lt;br /&gt;
  |os=Cross-platform&lt;br /&gt;
  |website=[https://www.gnu.org/software/emacs gnu.org/emacs]&lt;br /&gt;
  |github=&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;strong&amp;gt;Emacs&amp;lt;/strong&amp;gt; is a free and open-source text editor known for its exceptional extensibility and adaptability. It can be customized into anything from a simple editor to a full development environment or productivity tool. Emacs features built-in self-documentation, syntax-aware editing, and a vast ecosystem of community-developed packages.&amp;lt;ref&amp;gt;https://www.gnu.org/software/emacs/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For an easier introduction, [https://doomemacs.org Doom Emacs] offers a pre-configured Emacs framework with modern defaults and features like IDE tools, note-taking, and task management.&lt;br /&gt;
&lt;br /&gt;
There is an official Matrix room for Nix/Emacs: [https://matrix.to/#/#emacs:nixos.org #emacs:nixos.org].&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
==== Shell ====&lt;br /&gt;
&lt;br /&gt;
To temporarily use Emacs in a shell environment without modifying your system configuration, you can run:&lt;br /&gt;
{{Commands|&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
$ nix-shell -p emacs&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
This makes the Emacs editor available in your current shell. You can then launch Emacs by typing &amp;lt;code&amp;gt;emacs&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== System setup ====&lt;br /&gt;
&lt;br /&gt;
To install Emacs system-wide, making it available to all users, add the following to your configuration:&lt;br /&gt;
&lt;br /&gt;
{{file|/etc/nixos/configuration.nix|nix|&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
environment.systemPackages = [&lt;br /&gt;
  pkgs.emacs&lt;br /&gt;
];&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Alternatively, Emacs can be installed specific to a user via [[Home Manager]]:&lt;br /&gt;
&lt;br /&gt;
{{file|home.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
home.packages = [&lt;br /&gt;
  pkgs.emacs&lt;br /&gt;
];&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
After rebuilding your system with &amp;lt;code&amp;gt;nixos-rebuild switch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;home-manager switch&amp;lt;/code&amp;gt;, Emacs will be installed and accessible.&lt;br /&gt;
&lt;br /&gt;
== Configuration ==&lt;br /&gt;
&lt;br /&gt;
==== NixOS System Configuration ====&lt;br /&gt;
&lt;br /&gt;
System wide configuration of Emacs is limited to only the [https://www.gnu.org/software/emacs/manual/html_node/emacs/Emacs-Server.html Emacs daemon]. To enable Emacs daemon user services system-wide and set as default editor:&lt;br /&gt;
&lt;br /&gt;
{{file|/etc/nixos/configuration.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
services.emacs = {&lt;br /&gt;
   enable = true;&lt;br /&gt;
   defaultEditor = true;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Use &amp;lt;code&amp;gt;emacsclient&amp;lt;/code&amp;gt; to connect to the daemon. For a full list of module configuration options, see {{nixos:option|services.emacs}}.&lt;br /&gt;
&lt;br /&gt;
==== Home Manager ====&lt;br /&gt;
&lt;br /&gt;
[[Home Manager]] provides a larger set of user-specific configuration options for Emacs. &lt;br /&gt;
&lt;br /&gt;
A minimal configuration that installs Emacs alongside &amp;lt;code&amp;gt;nix-mode&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;nixfmt&amp;lt;/code&amp;gt; packages:&lt;br /&gt;
&lt;br /&gt;
{{file|home.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
programs.emacs = {&lt;br /&gt;
  enable = true;&lt;br /&gt;
  package = pkgs.emacs;  # replace with pkgs.emacs-gtk if desired&lt;br /&gt;
  extraPackages = epkgs: [&lt;br /&gt;
    epkgs.nix-mode&lt;br /&gt;
    epkgs.nixfmt&lt;br /&gt;
  ];&lt;br /&gt;
  extraConfig = &#039;&#039;&lt;br /&gt;
    (setq standard-indent 2)&lt;br /&gt;
  &#039;&#039;;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{note| An alternative option to setting the config inside a Nix string, you can load the config file by &amp;lt;code&amp;gt;extraConfig &amp;lt;nowiki&amp;gt;=&amp;lt;/nowiki&amp;gt; builtins.readFile ./emacs_config.el&amp;lt;/code&amp;gt;.}}&lt;br /&gt;
&lt;br /&gt;
To search for Emacs plugins within the package set, see {{nixos:package|emacsPackages.*}}. A full list of Home Manager configuration module options can be found [https://home-manager-options.extranix.com/?query=programs.emacs here].&lt;br /&gt;
&lt;br /&gt;
Home Manager also provides a configuration module for enabling the Emacs daemon:&lt;br /&gt;
&lt;br /&gt;
{{file|home.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
# Emacs is running as a daemon here, accesible via the &amp;quot;emacsclient&amp;quot; command&lt;br /&gt;
services.emacs = {&lt;br /&gt;
  enable = true;&lt;br /&gt;
  defaultEditor = true;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
See [https://home-manager-options.extranix.com/?query=services.emacs the module options] for &amp;lt;code&amp;gt;services.emacs&amp;lt;/code&amp;gt; configurations options.&lt;br /&gt;
&lt;br /&gt;
== Tips and Tricks ==&lt;br /&gt;
&lt;br /&gt;
==== Installing Packages ====&lt;br /&gt;
{{Note|Emacs, much like NixOS can rebuild and re-fetch all of its packages based on its initialization file alone, if one chooses to use an extension called &amp;quot;use-package&amp;quot;. Such a configuration file can be version controlled and used in all compatible operating systems.}}&lt;br /&gt;
One can mix and match whether Emacs packages are installed by Nix or Emacs. This can be particularly useful for Emacs packages that need to be built, such as vterm. One way to install Emacs packages through Nix is by the following, replacing {{ic|emacs-pgtk}} with the variant in use:&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
environment.systemPackages = with pkgs;&lt;br /&gt;
[ ...&lt;br /&gt;
  ((emacsPackagesFor emacs-pgtk).emacsWithPackages (&lt;br /&gt;
    epkgs: [ epkgs.vterm ]&lt;br /&gt;
  ))&lt;br /&gt;
  ...&lt;br /&gt;
];&lt;br /&gt;
&lt;br /&gt;
# To make the packages available to emacsclient, one can do the following:&lt;br /&gt;
services.emacs.package = with pkgs; (&lt;br /&gt;
  (emacsPackagesFor emacs-pgtk).emacsWithPackages (&lt;br /&gt;
    epkgs: [ epkgs.vterm ]&lt;br /&gt;
  )&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
# Some packages have characters like + that Nix considers a syntax error. &lt;br /&gt;
# To fix this, write the package name in quotes and specify the package set, even if using with epkgs;. &lt;br /&gt;
# For example, use epkgs.&amp;quot;ido-completing-read+&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;Note that if the expression &amp;lt;code&amp;gt;(emacsPackagesFor emacs-pgtk)&amp;lt;/code&amp;gt; is present, &amp;lt;code&amp;gt;emacs-pgtk&amp;lt;/code&amp;gt; need not be listed separately in the list &amp;lt;code&amp;gt;environment.systemPackages&amp;lt;/code&amp;gt;. Indeed, if one does that, &amp;lt;code&amp;gt;nixos-rebuild&amp;lt;/code&amp;gt; will warn about link collisions when the configuration is rebuilt.&lt;br /&gt;
&lt;br /&gt;
====== Alternative way of installation to ensuring consistent package management for emacs and emacsclient ======&lt;br /&gt;
If you plan to use the same packages for both emacs and emacsclient, you can define a custom emacs like this:&lt;br /&gt;
{{file|/etc/nixos/configuration.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
  nixpkgs.config.packageOverrides = pkgs: rec {&lt;br /&gt;
    myEmacs = pkgs.emacs.pkgs.withPackages (epkgs: with epkgs; [&lt;br /&gt;
      org&lt;br /&gt;
      nixmode&lt;br /&gt;
      ... # list all your desired emacsPackages here&lt;br /&gt;
    ]);&lt;br /&gt;
  };&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
You may then reference it twice:&lt;br /&gt;
&lt;br /&gt;
{{file|/etc/nixos/configuration.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
  ## if you want it per-user instead of system-wide use &#039;users.users.&amp;lt;name&amp;gt;.packages = with pkgs; [&#039; instead&lt;br /&gt;
  environment.systemPackages = with pkgs; [&lt;br /&gt;
    myEmacs&lt;br /&gt;
  ];&lt;br /&gt;
&lt;br /&gt;
  ## enabling emacsclient and making all the packages available&lt;br /&gt;
  services.emacs = {&lt;br /&gt;
    enable = true;&lt;br /&gt;
    package = pkgs.myEmacs;&lt;br /&gt;
  };&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Using this approach, there is no need to keep two lists of emacsPackages in sync.&lt;br /&gt;
&lt;br /&gt;
==== Tree-sitter ====&lt;br /&gt;
[[Emacs]] 29 [[emacswiki:Tree-sitter|supports Tree-sitter parsers]] when built with the &amp;lt;code&amp;gt;--with-tree-sitter&amp;lt;/code&amp;gt; option. The &amp;lt;code&amp;gt;emacsPackages.treesit-grammars&amp;lt;/code&amp;gt; fake package makes them accessible to Emacs when using &amp;lt;code&amp;gt;emacs29.pkgs.withPackages&amp;lt;/code&amp;gt;:&amp;lt;ref&amp;gt;https://github.com/NixOS/nixpkgs/pull/230751&amp;lt;/ref&amp;gt;&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  pkgs ? import &amp;lt;nixpkgs&amp;gt; { },&lt;br /&gt;
}:&lt;br /&gt;
pkgs.emacs29.pkgs.withPackages (epkgs: [&lt;br /&gt;
  (epkgs.treesit-grammars.with-grammars (grammars: [ grammars.tree-sitter-bash ]))&lt;br /&gt;
])&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When using Emacs with tree-sitter support, it&#039;s recommended to install both &amp;lt;code&amp;gt;epkgs.tree-sitter-langs&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;epkgs.treesit-grammars&amp;lt;/code&amp;gt;. While &amp;lt;code&amp;gt;treesit-grammars&amp;lt;/code&amp;gt; handles the registration of grammars with Emacs&#039;s native tree-sitter interface, the actual grammar files will come from &amp;lt;code&amp;gt;tree-sitter-langs&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt;tree-sitter-langs&amp;lt;/code&amp;gt; being a MELPA package means it receives regular updates when new grammar versions are released, whereas the grammars in the tree-sitter-grammars package may lag behind in nixpkgs. The combination ensures you get both up-to-date grammars and proper integration with Emacs&#039;s built-in tree-sitter support.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Bonus Tip:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;emacs.pkgs.pretty-sha-path&amp;lt;/code&amp;gt; is quality of life improvement for Nix, Guix users.&lt;br /&gt;
&lt;br /&gt;
Allows toggling Guix/Nix store paths by replacing SHA-sequences with ellipsis, i.e.:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;/gnu/store/72f54nfp6g1hz873w8z3gfcah0h4nl9p-foo-0.1  →  /gnu/store/…-foo-0.1&lt;br /&gt;
/nix/store/nh4n4yzb1bx7nss2rg342dz44g14m06x-bar-0.2  →  /nix/store/…-bar-0.2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
located at https://github.com/alezost/pretty-sha-path.el&lt;br /&gt;
&lt;br /&gt;
==== Automatic Package Management ====&lt;br /&gt;
If you use &amp;lt;code&amp;gt;use-package&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;leaf&amp;lt;/code&amp;gt; in your configuration, the community overlay can manage your Emacs packages automatically by using &amp;lt;code&amp;gt;emacsWithPackagesFromUsePackage&amp;lt;/code&amp;gt;. First, install the overlay (instructions above), then add the following to your &amp;lt;code&amp;gt;configuration.nix&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  environment.systemPackages = [&lt;br /&gt;
    (pkgs.emacsWithPackagesFromUsePackage {&lt;br /&gt;
      package = pkgs.emacsGit;  # replace with pkgs.emacsPgtk, or another version if desired.&lt;br /&gt;
      config = path/to/your/config.el;&lt;br /&gt;
      # config = path/to/your/config.org; # Org-Babel configs also supported&lt;br /&gt;
&lt;br /&gt;
      # Optionally provide extra packages not in the configuration file.&lt;br /&gt;
      extraEmacsPackages = epkgs: [&lt;br /&gt;
        epkgs.use-package&lt;br /&gt;
      ];&lt;br /&gt;
&lt;br /&gt;
      # Optionally override derivations.&lt;br /&gt;
      override = epkgs: epkgs // {&lt;br /&gt;
        somePackage = epkgs.melpaPackages.somePackage.overrideAttrs(old: {&lt;br /&gt;
           # Apply fixes here&lt;br /&gt;
        });&lt;br /&gt;
      };&lt;br /&gt;
    })&lt;br /&gt;
  ];&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See the [https://github.com/nix-community/emacs-overlay#extra-library-functionality overlay README] for a full list of options.&lt;br /&gt;
&lt;br /&gt;
==== Adding packages from outside ELPA/MELPA ====&lt;br /&gt;
Some packages may require more sophisticated derivation, but the following is a good starting point for adding external packages:&lt;br /&gt;
&lt;br /&gt;
{{file|lambda-line.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  melpaBuild,&lt;br /&gt;
  fetchFromGitHub,&lt;br /&gt;
  all-the-icons,&lt;br /&gt;
}:&lt;br /&gt;
melpaBuild {&lt;br /&gt;
  pname = &amp;quot;lambda-line&amp;quot;;&lt;br /&gt;
  version = &amp;quot;0-unstable-2022-11-23&amp;quot;;&lt;br /&gt;
  src = fetchFromGitHub {&lt;br /&gt;
    owner = &amp;quot;Lambda-Emacs&amp;quot;;&lt;br /&gt;
    repo = &amp;quot;lambda-line&amp;quot;;&lt;br /&gt;
    rev = &amp;quot;22186321a7442f1bd3b121f739007bd809cb38f8&amp;quot;;&lt;br /&gt;
    hash = &amp;quot;sha256-2tOXMqpmd14ohzmrRoV5Urf0HlnRPV1EVHm/d8OBSGE=&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
  # elisp dependencies&lt;br /&gt;
  packageRequires = [&lt;br /&gt;
    all-the-icons&lt;br /&gt;
  ];&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
You can then use the new package with automatic package management like so:&lt;br /&gt;
&lt;br /&gt;
{{file|configuration.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  environment.systemPackages = [&lt;br /&gt;
    (pkgs.emacsWithPackagesFromUsePackage {&lt;br /&gt;
      ...&lt;br /&gt;
      override = epkgs: epkgs // {&lt;br /&gt;
        lambda-line = callPackage ./lambda-line.nix {&lt;br /&gt;
          inherit (pkgs) fetchFromGitHub;&lt;br /&gt;
          inherit (epkgs) melpaBuild all-the-icons;&lt;br /&gt;
        };&lt;br /&gt;
      };&lt;br /&gt;
    })&lt;br /&gt;
  ];&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
or manual package management like so:&lt;br /&gt;
&lt;br /&gt;
{{file|configuration.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  environment.systemPackages = with pkgs;&lt;br /&gt;
    [ ...&lt;br /&gt;
      ((emacsPackagesFor emacs-pgtk).emacsWithPackages (epkgs: [ &lt;br /&gt;
          epkgs.vterm &lt;br /&gt;
          (callPackage ./lambda-line.nix {&lt;br /&gt;
            inherit (pkgs) fetchFromGitHub;&lt;br /&gt;
            inherit (epkgs) melpaBuild all-the-icons;&lt;br /&gt;
          };) &lt;br /&gt;
       ]))&lt;br /&gt;
      ...&lt;br /&gt;
    ];&lt;br /&gt;
}&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
==== Packaging and testing Emacs nixpkgs ====&lt;br /&gt;
Emacs packages can be defined and tested like other nixpkgs.&lt;br /&gt;
They can be obtained from melpa, elpa or other sources such as github.&lt;br /&gt;
&lt;br /&gt;
{{file|default.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
{ melpaBuild&lt;br /&gt;
, lib&lt;br /&gt;
, fetchFromGitHub&lt;br /&gt;
...&lt;br /&gt;
}:&lt;br /&gt;
&lt;br /&gt;
melpaBuild {&lt;br /&gt;
  pname = &amp;quot;...&amp;quot;;&lt;br /&gt;
  version = &amp;quot;...&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
  src = fetchFromGitHub {&lt;br /&gt;
    owner = &amp;quot;...&amp;quot;;&lt;br /&gt;
    repo = &amp;quot;...&amp;quot;;&lt;br /&gt;
    rev = &amp;quot;...&amp;quot;;&lt;br /&gt;
    hash = &amp;quot;...&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
&lt;br /&gt;
  packageRequires = [ ... ];&lt;br /&gt;
&lt;br /&gt;
  patches = [ ... ];&lt;br /&gt;
&lt;br /&gt;
  meta = {&lt;br /&gt;
    description = &amp;quot;...&amp;quot;;&lt;br /&gt;
    license = lib.licenses.gpl3Plus;&lt;br /&gt;
  };&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
They are located at &amp;lt;code&amp;gt;pkgs/applications/editors/emacs/elisp-packages/manual-packages/&amp;lt;/code&amp;gt; [https://github.com/NixOS/nixpkgs/tree/master/pkgs/applications/editors/emacs/elisp-packages/manual-packages] and a new pkg must be added under &amp;lt;code&amp;gt;pkgs/applications/editors/elisp-packages/manual-packages.nix&amp;lt;/code&amp;gt; [https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/editors/emacs/elisp-packages/manual-packages.nix]. Once the nixpkg is ready, it can be tested using the following command. This inserts the nixpkg into the load-path of Emacs.&lt;br /&gt;
{{Commands|&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
$ nix-shell -I nixpkgs=&amp;lt;path_to_nixpkgs_copy&amp;gt; -p &amp;quot;(emacsPackagesFor pkgs.emacs28).emacsWithPackages (epkgs: [ epkgs.&amp;lt;package&amp;gt; ])&amp;quot;&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==== Window Manager Integration ====&lt;br /&gt;
Out of the box, non-&amp;quot;Mac Port&amp;quot; versions of Emacs will not be picked up properly by window managers like [https://github.com/koekeishiya/yabai Yabai] because [https://github.com/koekeishiya/yabai/issues/86#issuecomment-507537023 Emacs does not set the correct macOS window role]. This can be fixed with a patch (e.g. the first patch in the example above). However, even with the patch, Yabai may not correctly pick up Emacs if you invoke the &amp;lt;code&amp;gt;emacs&amp;lt;/code&amp;gt; binary directly from a shell. For Emacs to work properly with window managers you must invoke it by running the macOS app that is generated when you install Emacs with nix. You can setup an alias to do this like so (replace &amp;lt;code&amp;gt;pkgs.emacs&amp;lt;/code&amp;gt; with the package you are using):&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
programs.zsh = {&lt;br /&gt;
  enable = true;&lt;br /&gt;
  shellAliases = {&lt;br /&gt;
    emacs = &amp;quot;${pkgs.emacs}/Applications/Emacs.app/Contents/MacOS/Emacs&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Available Emacs Variants ====&lt;br /&gt;
{{warning| Certain issues are possible, when mixing different versions of Emacs, in particular a configuration file tailored towards emacs with native compilation, may misbehave on non-native compiling versions, unless only the emacs lisp code is shared between them.}}&lt;br /&gt;
&lt;br /&gt;
===== Stable (nixpkgs) =====&lt;br /&gt;
Emacs is available in nixpkgs under the names &amp;lt;code&amp;gt;emacs&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;emacs-gtk&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/NixOS/nixpkgs/pull/189543 Since 2022-09], the package called &amp;lt;code&amp;gt;emacs&amp;lt;/code&amp;gt; now installs the lucid toolkit instead of gtk. The reason is that Emacs is less stable with gtk especially in daemon mode. However, the lucid flavor of Emacs will not take into account the GTK theme (since it is not even GTK) and looks quite… ugly (see comparisons [https://emacs.stackexchange.com/questions/33065/on-linux-why-should-one-choose-lucid-over-gtk-gui-for-emacs here]). If you still prefer the GTK version of Emacs, you can instead install &amp;lt;code&amp;gt;emacs-gtk&amp;lt;/code&amp;gt; (before 2022-09 this package does not exist and Emacs defaults to the gtk version).&lt;br /&gt;
&lt;br /&gt;
===== Unstable (community overlay) =====&lt;br /&gt;
The [https://github.com/nix-community/emacs-overlay community overlay] provides nightly versions of the Emacs unstable branches, ELPA/MELPA packages, and [https://github.com/ch11ng/exwm EXWM] + its dependencies. &#039;&#039;&#039;To use these, first apply the overlay (instructions below), which will make the packages available in nixpkgs.&#039;&#039;&#039; Then you can follow the normal nixpkgs installation instructions (above), but use your package of choice from the overlay (e.g. &amp;lt;code&amp;gt;pkgs.emacsGit&amp;lt;/code&amp;gt;) in place of &amp;lt;code&amp;gt;pkgs.emacs&amp;lt;/code&amp;gt;. See the [https://github.com/nix-community/emacs-overlay#emacs-overlay README] for a complete list of packages provided, and their differences.&lt;br /&gt;
&lt;br /&gt;
====== With flakes ======&lt;br /&gt;
Using a system flake, one can specify the specific revision of the overlay as a flake input, for example:&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
inputs.emacs-overlay.url = &amp;quot;github:nix-community/emacs-overlay/da2f552d133497abd434006e0cae996c0a282394&amp;quot;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;This can then be used in the system configuration by using the {{ic|self}} argument:&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
nixpkgs.overlays = [ (import self.inputs.emacs-overlay) ];&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
======  Without flakes ======&lt;br /&gt;
For installing one of the unstable branches of Emacs, add the following lines to your configuration file:&lt;br /&gt;
{{file|configuration.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  nixpkgs.overlays = [&lt;br /&gt;
    (import (builtins.fetchGit {&lt;br /&gt;
      url = &amp;quot;https://github.com/nix-community/emacs-overlay.git&amp;quot;;&lt;br /&gt;
      ref = &amp;quot;master&amp;quot;;&lt;br /&gt;
      rev = &amp;quot;bfc8f6edcb7bcf3cf24e4a7199b3f6fed96aaecf&amp;quot;; # change the revision&lt;br /&gt;
    }))&lt;br /&gt;
  ];&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
===== Darwin (macOS) =====&lt;br /&gt;
Nixpkgs provides several of the &amp;quot;Mac Port&amp;quot; versions of Emacs, which have been patched to provide better integration with macOS (see the [https://nixos.org/manual/nixos/stable/index.html#module-services-emacs-releases NixOS manual entry for a full list of packages]). However, those packages typically track the stable releases of Emacs.&lt;br /&gt;
&lt;br /&gt;
If you would like to use the latest version of Emacs on Darwin, one option is to use a package like &amp;lt;code&amp;gt;emacsPgkt&amp;lt;/code&amp;gt; from the community overlay (see above), and apply patches yourself via an override. For example, here is a derivation that applies the patches from the [https://github.com/d12frosted/homebrew-emacs-plus &amp;lt;code&amp;gt;emacs-plus&amp;lt;/code&amp;gt; homebrew formula]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
pkgs.emacsPgtk.overrideAttrs (old: {&lt;br /&gt;
      patches =&lt;br /&gt;
        (old.patches or [])&lt;br /&gt;
        ++ [&lt;br /&gt;
          # Fix OS window role (needed for window managers like yabai)&lt;br /&gt;
          (fetchpatch {&lt;br /&gt;
            url = &amp;quot;https://raw.githubusercontent.com/d12frosted/homebrew-emacs-plus/master/patches/emacs-28/fix-window-role.patch&amp;quot;;&lt;br /&gt;
            sha256 = &amp;quot;0c41rgpi19vr9ai740g09lka3nkjk48ppqyqdnncjrkfgvm2710z&amp;quot;;&lt;br /&gt;
          })&lt;br /&gt;
          # Enable rounded window with no decoration&lt;br /&gt;
          (fetchpatch {&lt;br /&gt;
            url = &amp;quot;https://raw.githubusercontent.com/d12frosted/homebrew-emacs-plus/master/patches/emacs-29/round-undecorated-frame.patch&amp;quot;;&lt;br /&gt;
            sha256 = &amp;quot;111i0r3ahs0f52z15aaa3chlq7ardqnzpwp8r57kfsmnmg6c2nhf&amp;quot;;&lt;br /&gt;
          })&lt;br /&gt;
          # Make Emacs aware of OS-level light/dark mode&lt;br /&gt;
          (fetchpatch {&lt;br /&gt;
            url = &amp;quot;https://raw.githubusercontent.com/d12frosted/homebrew-emacs-plus/master/patches/emacs-28/system-appearance.patch&amp;quot;;&lt;br /&gt;
            sha256 = &amp;quot;14ndp2fqqc95s70fwhpxq58y8qqj4gzvvffp77snm2xk76c1bvnn&amp;quot;;&lt;br /&gt;
          })&lt;br /&gt;
        ];&lt;br /&gt;
    });&lt;br /&gt;
  };&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
==== Plasma taskbar grouping ====&lt;br /&gt;
To fix/workaround [[KDE|Plasma]] grouping Emacs incorrectly (confusing emacs.desktop with emacsclient.desktop), perform the following:&lt;br /&gt;
&lt;br /&gt;
* Open Emacs&lt;br /&gt;
* Right click title bar&lt;br /&gt;
* More Actions &amp;gt; Configure Special Window Settings&lt;br /&gt;
* Add Property &amp;gt; Desktop File Name&lt;br /&gt;
* Set desktop file name to &amp;quot;/home/&amp;lt;USERNAME&amp;gt;/.nix-profile/share/applications/emacs.desktop&amp;quot;&lt;br /&gt;
* Apply the changes&lt;br /&gt;
* Restart Emacs if need&lt;br /&gt;
&lt;br /&gt;
All Emacs instances should now be grouped together, allowing you to pin it and reliably switch to it with Super+&amp;lt;number&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Spell checking ====&lt;br /&gt;
Because Emacs expects the dictionaries to be on the same directory as aspell, they won&#039;t be picked up. To fix it install the &amp;lt;code&amp;gt;aspellWithDicts&amp;lt;/code&amp;gt; package, specifying the dictionaries you want to use: &lt;br /&gt;
&lt;br /&gt;
{{file|configuration.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  environment.systemPackages = with pkgs; [&lt;br /&gt;
    (aspellWithDicts (dicts: with dicts; [ en en-computers en-science es]))&lt;br /&gt;
  ];&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
A list of official dictionaries for aspell can be found on [https://ftp.gnu.org/gnu/aspell/dict/0index.html  Aspell Website]&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[Home Manager]] – For declarative Emacs configuration at the user level: [https://nix-community.github.io/home-manager/options.html#opt-programs.emacs.enable Emacs module in Home Manager]&lt;br /&gt;
* [https://www.gnu.org/software/emacs/manual/ Emacs Manuals] – Official Emacs documentation.&lt;br /&gt;
* [https://search.nixos.org/options?channel=unstable&amp;amp;query=services.emacs NixOS options for Emacs services] – System-level Emacs configuration.&lt;br /&gt;
* [https://discourse.nixos.org/search?q=emacs Emacs discussions on NixOS Discourse] – Community tips, troubleshooting, and use cases.&lt;br /&gt;
* [https://doomemacs.org Doom Emacs] – A popular Emacs configuration framework.&lt;br /&gt;
* [https://github.com/nix-community/emacs-overlay Emacs Overlay on Nixpkgs] – For nightly builds and additional Emacs packages.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
[[Category:Applications]]&lt;br /&gt;
[[Category:CLI Applications]]&lt;br /&gt;
[[Category:NixOS Manual]]&lt;br /&gt;
[[Category:Text Editor]]&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=Emacs&amp;diff=29404</id>
		<title>Emacs</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=Emacs&amp;diff=29404"/>
		<updated>2026-01-09T22:31:25Z</updated>

		<summary type="html">&lt;p&gt;Pigs: /* System setup */ make it clear the distinction between installing system wide vs home manager&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{application infobox&lt;br /&gt;
  |name=GNU Emacs&lt;br /&gt;
  |image=EmacsIcon.svg&lt;br /&gt;
  |type=Text Editor&lt;br /&gt;
  |firstRelease=1985; 40 years ago&lt;br /&gt;
  |license=[https://www.gnu.org/licenses/gpl.html GNU General Public License]&lt;br /&gt;
  |os=Cross-platform&lt;br /&gt;
  |website=[https://www.gnu.org/software/emacs gnu.org/emacs]&lt;br /&gt;
  |github=&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;strong&amp;gt;Emacs&amp;lt;/strong&amp;gt; is a free and open-source text editor known for its exceptional extensibility and adaptability. It can be customized into anything from a simple editor to a full development environment or productivity tool. Emacs features built-in self-documentation, syntax-aware editing, and a vast ecosystem of community-developed packages.&amp;lt;ref&amp;gt;https://www.gnu.org/software/emacs/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For an easier introduction, [https://doomemacs.org Doom Emacs] offers a pre-configured Emacs framework with modern defaults and features like IDE tools, note-taking, and task management.&lt;br /&gt;
&lt;br /&gt;
There is an official Matrix room for Nix/Emacs: [https://matrix.to/#/#emacs:nixos.org #emacs:nixos.org].&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
==== Shell ====&lt;br /&gt;
&lt;br /&gt;
To temporarily use Emacs in a shell environment without modifying your system configuration, you can run:&lt;br /&gt;
{{Commands|&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
$ nix-shell -p emacs&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
This makes the Emacs editor available in your current shell. You can then launch Emacs by typing &amp;lt;code&amp;gt;emacs&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== System setup ====&lt;br /&gt;
&lt;br /&gt;
To install Emacs system-wide, making it available to all users, add the following to your configuration:&lt;br /&gt;
&lt;br /&gt;
{{file|/etc/nixos/configuration.nix|nix|&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
environment.systemPackages = [&lt;br /&gt;
  pkgs.emacs&lt;br /&gt;
];&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Alternatively, Emacs can be installed specific to a user via [[Home Manager]]:&lt;br /&gt;
&lt;br /&gt;
{{file|home.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
home.packages = [&lt;br /&gt;
  pkgs.emacs&lt;br /&gt;
];&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
After rebuilding your system with &amp;lt;code&amp;gt;nixos-rebuild switch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;home-manager switch&amp;lt;/code&amp;gt;, Emacs will be installed and accessible.&lt;br /&gt;
&lt;br /&gt;
== Configuration ==&lt;br /&gt;
{{Note|Currently, configuring Emacs is possible by using Home Manager. A workaround for a global configuration is highlighted in the advanced section.}}&lt;br /&gt;
&lt;br /&gt;
==== Basic ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
programs.emacs = {&lt;br /&gt;
   enable = true;&lt;br /&gt;
   defaultEditor = true;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Advanced ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
# Global Configuration&lt;br /&gt;
# Emacs is running as a daemon here, accesible via the &amp;quot;emacsclient&amp;quot; command&lt;br /&gt;
services.emacs = {&lt;br /&gt;
  enable = true;&lt;br /&gt;
  package = pkgs.emacs; &lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
# Home Configuration&lt;br /&gt;
programs.emacs = {&lt;br /&gt;
  enable = true;&lt;br /&gt;
  package = pkgs.emacs;  # replace with pkgs.emacs-gtk if desired&lt;br /&gt;
  extraConfig = &#039;&#039;&lt;br /&gt;
    (setq standard-indent 2)&lt;br /&gt;
  &#039;&#039;;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Tips and Tricks ==&lt;br /&gt;
&lt;br /&gt;
==== Installing Packages ====&lt;br /&gt;
{{Note|Emacs, much like NixOS can rebuild and re-fetch all of its packages based on its initialization file alone, if one chooses to use an extension called &amp;quot;use-package&amp;quot;. Such a configuration file can be version controlled and used in all compatible operating systems.}}&lt;br /&gt;
One can mix and match whether Emacs packages are installed by Nix or Emacs. This can be particularly useful for Emacs packages that need to be built, such as vterm. One way to install Emacs packages through Nix is by the following, replacing {{ic|emacs-pgtk}} with the variant in use:&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
environment.systemPackages = with pkgs;&lt;br /&gt;
[ ...&lt;br /&gt;
  ((emacsPackagesFor emacs-pgtk).emacsWithPackages (&lt;br /&gt;
    epkgs: [ epkgs.vterm ]&lt;br /&gt;
  ))&lt;br /&gt;
  ...&lt;br /&gt;
];&lt;br /&gt;
&lt;br /&gt;
# To make the packages available to emacsclient, one can do the following:&lt;br /&gt;
services.emacs.package = with pkgs; (&lt;br /&gt;
  (emacsPackagesFor emacs-pgtk).emacsWithPackages (&lt;br /&gt;
    epkgs: [ epkgs.vterm ]&lt;br /&gt;
  )&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
# Some packages have characters like + that Nix considers a syntax error. &lt;br /&gt;
# To fix this, write the package name in quotes and specify the package set, even if using with epkgs;. &lt;br /&gt;
# For example, use epkgs.&amp;quot;ido-completing-read+&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;Note that if the expression &amp;lt;code&amp;gt;(emacsPackagesFor emacs-pgtk)&amp;lt;/code&amp;gt; is present, &amp;lt;code&amp;gt;emacs-pgtk&amp;lt;/code&amp;gt; need not be listed separately in the list &amp;lt;code&amp;gt;environment.systemPackages&amp;lt;/code&amp;gt;. Indeed, if one does that, &amp;lt;code&amp;gt;nixos-rebuild&amp;lt;/code&amp;gt; will warn about link collisions when the configuration is rebuilt.&lt;br /&gt;
&lt;br /&gt;
====== Alternative way of installation to ensuring consistent package management for emacs and emacsclient ======&lt;br /&gt;
If you plan to use the same packages for both emacs and emacsclient, you can define a custom emacs like this:&lt;br /&gt;
{{file|/etc/nixos/configuration.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
  nixpkgs.config.packageOverrides = pkgs: rec {&lt;br /&gt;
    myEmacs = pkgs.emacs.pkgs.withPackages (epkgs: with epkgs; [&lt;br /&gt;
      org&lt;br /&gt;
      nixmode&lt;br /&gt;
      ... # list all your desired emacsPackages here&lt;br /&gt;
    ]);&lt;br /&gt;
  };&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
You may then reference it twice:&lt;br /&gt;
&lt;br /&gt;
{{file|/etc/nixos/configuration.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
  ## if you want it per-user instead of system-wide use &#039;users.users.&amp;lt;name&amp;gt;.packages = with pkgs; [&#039; instead&lt;br /&gt;
  environment.systemPackages = with pkgs; [&lt;br /&gt;
    myEmacs&lt;br /&gt;
  ];&lt;br /&gt;
&lt;br /&gt;
  ## enabling emacsclient and making all the packages available&lt;br /&gt;
  services.emacs = {&lt;br /&gt;
    enable = true;&lt;br /&gt;
    package = pkgs.myEmacs;&lt;br /&gt;
  };&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Using this approach, there is no need to keep two lists of emacsPackages in sync.&lt;br /&gt;
&lt;br /&gt;
==== Tree-sitter ====&lt;br /&gt;
[[Emacs]] 29 [[emacswiki:Tree-sitter|supports Tree-sitter parsers]] when built with the &amp;lt;code&amp;gt;--with-tree-sitter&amp;lt;/code&amp;gt; option. The &amp;lt;code&amp;gt;emacsPackages.treesit-grammars&amp;lt;/code&amp;gt; fake package makes them accessible to Emacs when using &amp;lt;code&amp;gt;emacs29.pkgs.withPackages&amp;lt;/code&amp;gt;:&amp;lt;ref&amp;gt;https://github.com/NixOS/nixpkgs/pull/230751&amp;lt;/ref&amp;gt;&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  pkgs ? import &amp;lt;nixpkgs&amp;gt; { },&lt;br /&gt;
}:&lt;br /&gt;
pkgs.emacs29.pkgs.withPackages (epkgs: [&lt;br /&gt;
  (epkgs.treesit-grammars.with-grammars (grammars: [ grammars.tree-sitter-bash ]))&lt;br /&gt;
])&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When using Emacs with tree-sitter support, it&#039;s recommended to install both &amp;lt;code&amp;gt;epkgs.tree-sitter-langs&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;epkgs.treesit-grammars&amp;lt;/code&amp;gt;. While &amp;lt;code&amp;gt;treesit-grammars&amp;lt;/code&amp;gt; handles the registration of grammars with Emacs&#039;s native tree-sitter interface, the actual grammar files will come from &amp;lt;code&amp;gt;tree-sitter-langs&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt;tree-sitter-langs&amp;lt;/code&amp;gt; being a MELPA package means it receives regular updates when new grammar versions are released, whereas the grammars in the tree-sitter-grammars package may lag behind in nixpkgs. The combination ensures you get both up-to-date grammars and proper integration with Emacs&#039;s built-in tree-sitter support.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Bonus Tip:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;emacs.pkgs.pretty-sha-path&amp;lt;/code&amp;gt; is quality of life improvement for Nix, Guix users.&lt;br /&gt;
&lt;br /&gt;
Allows toggling Guix/Nix store paths by replacing SHA-sequences with ellipsis, i.e.:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;/gnu/store/72f54nfp6g1hz873w8z3gfcah0h4nl9p-foo-0.1  →  /gnu/store/…-foo-0.1&lt;br /&gt;
/nix/store/nh4n4yzb1bx7nss2rg342dz44g14m06x-bar-0.2  →  /nix/store/…-bar-0.2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
located at https://github.com/alezost/pretty-sha-path.el&lt;br /&gt;
&lt;br /&gt;
==== Automatic Package Management ====&lt;br /&gt;
If you use &amp;lt;code&amp;gt;use-package&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;leaf&amp;lt;/code&amp;gt; in your configuration, the community overlay can manage your Emacs packages automatically by using &amp;lt;code&amp;gt;emacsWithPackagesFromUsePackage&amp;lt;/code&amp;gt;. First, install the overlay (instructions above), then add the following to your &amp;lt;code&amp;gt;configuration.nix&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  environment.systemPackages = [&lt;br /&gt;
    (pkgs.emacsWithPackagesFromUsePackage {&lt;br /&gt;
      package = pkgs.emacsGit;  # replace with pkgs.emacsPgtk, or another version if desired.&lt;br /&gt;
      config = path/to/your/config.el;&lt;br /&gt;
      # config = path/to/your/config.org; # Org-Babel configs also supported&lt;br /&gt;
&lt;br /&gt;
      # Optionally provide extra packages not in the configuration file.&lt;br /&gt;
      extraEmacsPackages = epkgs: [&lt;br /&gt;
        epkgs.use-package&lt;br /&gt;
      ];&lt;br /&gt;
&lt;br /&gt;
      # Optionally override derivations.&lt;br /&gt;
      override = epkgs: epkgs // {&lt;br /&gt;
        somePackage = epkgs.melpaPackages.somePackage.overrideAttrs(old: {&lt;br /&gt;
           # Apply fixes here&lt;br /&gt;
        });&lt;br /&gt;
      };&lt;br /&gt;
    })&lt;br /&gt;
  ];&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See the [https://github.com/nix-community/emacs-overlay#extra-library-functionality overlay README] for a full list of options.&lt;br /&gt;
&lt;br /&gt;
==== Adding packages from outside ELPA/MELPA ====&lt;br /&gt;
Some packages may require more sophisticated derivation, but the following is a good starting point for adding external packages:&lt;br /&gt;
&lt;br /&gt;
{{file|lambda-line.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  melpaBuild,&lt;br /&gt;
  fetchFromGitHub,&lt;br /&gt;
  all-the-icons,&lt;br /&gt;
}:&lt;br /&gt;
melpaBuild {&lt;br /&gt;
  pname = &amp;quot;lambda-line&amp;quot;;&lt;br /&gt;
  version = &amp;quot;0-unstable-2022-11-23&amp;quot;;&lt;br /&gt;
  src = fetchFromGitHub {&lt;br /&gt;
    owner = &amp;quot;Lambda-Emacs&amp;quot;;&lt;br /&gt;
    repo = &amp;quot;lambda-line&amp;quot;;&lt;br /&gt;
    rev = &amp;quot;22186321a7442f1bd3b121f739007bd809cb38f8&amp;quot;;&lt;br /&gt;
    hash = &amp;quot;sha256-2tOXMqpmd14ohzmrRoV5Urf0HlnRPV1EVHm/d8OBSGE=&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
  # elisp dependencies&lt;br /&gt;
  packageRequires = [&lt;br /&gt;
    all-the-icons&lt;br /&gt;
  ];&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
You can then use the new package with automatic package management like so:&lt;br /&gt;
&lt;br /&gt;
{{file|configuration.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  environment.systemPackages = [&lt;br /&gt;
    (pkgs.emacsWithPackagesFromUsePackage {&lt;br /&gt;
      ...&lt;br /&gt;
      override = epkgs: epkgs // {&lt;br /&gt;
        lambda-line = callPackage ./lambda-line.nix {&lt;br /&gt;
          inherit (pkgs) fetchFromGitHub;&lt;br /&gt;
          inherit (epkgs) melpaBuild all-the-icons;&lt;br /&gt;
        };&lt;br /&gt;
      };&lt;br /&gt;
    })&lt;br /&gt;
  ];&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
or manual package management like so:&lt;br /&gt;
&lt;br /&gt;
{{file|configuration.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  environment.systemPackages = with pkgs;&lt;br /&gt;
    [ ...&lt;br /&gt;
      ((emacsPackagesFor emacs-pgtk).emacsWithPackages (epkgs: [ &lt;br /&gt;
          epkgs.vterm &lt;br /&gt;
          (callPackage ./lambda-line.nix {&lt;br /&gt;
            inherit (pkgs) fetchFromGitHub;&lt;br /&gt;
            inherit (epkgs) melpaBuild all-the-icons;&lt;br /&gt;
          };) &lt;br /&gt;
       ]))&lt;br /&gt;
      ...&lt;br /&gt;
    ];&lt;br /&gt;
}&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
==== Packaging and testing Emacs nixpkgs ====&lt;br /&gt;
Emacs packages can be defined and tested like other nixpkgs.&lt;br /&gt;
They can be obtained from melpa, elpa or other sources such as github.&lt;br /&gt;
&lt;br /&gt;
{{file|default.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
{ melpaBuild&lt;br /&gt;
, lib&lt;br /&gt;
, fetchFromGitHub&lt;br /&gt;
...&lt;br /&gt;
}:&lt;br /&gt;
&lt;br /&gt;
melpaBuild {&lt;br /&gt;
  pname = &amp;quot;...&amp;quot;;&lt;br /&gt;
  version = &amp;quot;...&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
  src = fetchFromGitHub {&lt;br /&gt;
    owner = &amp;quot;...&amp;quot;;&lt;br /&gt;
    repo = &amp;quot;...&amp;quot;;&lt;br /&gt;
    rev = &amp;quot;...&amp;quot;;&lt;br /&gt;
    hash = &amp;quot;...&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
&lt;br /&gt;
  packageRequires = [ ... ];&lt;br /&gt;
&lt;br /&gt;
  patches = [ ... ];&lt;br /&gt;
&lt;br /&gt;
  meta = {&lt;br /&gt;
    description = &amp;quot;...&amp;quot;;&lt;br /&gt;
    license = lib.licenses.gpl3Plus;&lt;br /&gt;
  };&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
They are located at &amp;lt;code&amp;gt;pkgs/applications/editors/emacs/elisp-packages/manual-packages/&amp;lt;/code&amp;gt; [https://github.com/NixOS/nixpkgs/tree/master/pkgs/applications/editors/emacs/elisp-packages/manual-packages] and a new pkg must be added under &amp;lt;code&amp;gt;pkgs/applications/editors/elisp-packages/manual-packages.nix&amp;lt;/code&amp;gt; [https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/editors/emacs/elisp-packages/manual-packages.nix]. Once the nixpkg is ready, it can be tested using the following command. This inserts the nixpkg into the load-path of Emacs.&lt;br /&gt;
{{Commands|&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
$ nix-shell -I nixpkgs=&amp;lt;path_to_nixpkgs_copy&amp;gt; -p &amp;quot;(emacsPackagesFor pkgs.emacs28).emacsWithPackages (epkgs: [ epkgs.&amp;lt;package&amp;gt; ])&amp;quot;&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==== Window Manager Integration ====&lt;br /&gt;
Out of the box, non-&amp;quot;Mac Port&amp;quot; versions of Emacs will not be picked up properly by window managers like [https://github.com/koekeishiya/yabai Yabai] because [https://github.com/koekeishiya/yabai/issues/86#issuecomment-507537023 Emacs does not set the correct macOS window role]. This can be fixed with a patch (e.g. the first patch in the example above). However, even with the patch, Yabai may not correctly pick up Emacs if you invoke the &amp;lt;code&amp;gt;emacs&amp;lt;/code&amp;gt; binary directly from a shell. For Emacs to work properly with window managers you must invoke it by running the macOS app that is generated when you install Emacs with nix. You can setup an alias to do this like so (replace &amp;lt;code&amp;gt;pkgs.emacs&amp;lt;/code&amp;gt; with the package you are using):&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
programs.zsh = {&lt;br /&gt;
  enable = true;&lt;br /&gt;
  shellAliases = {&lt;br /&gt;
    emacs = &amp;quot;${pkgs.emacs}/Applications/Emacs.app/Contents/MacOS/Emacs&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Available Emacs Variants ====&lt;br /&gt;
{{warning| Certain issues are possible, when mixing different versions of Emacs, in particular a configuration file tailored towards emacs with native compilation, may misbehave on non-native compiling versions, unless only the emacs lisp code is shared between them.}}&lt;br /&gt;
&lt;br /&gt;
===== Stable (nixpkgs) =====&lt;br /&gt;
Emacs is available in nixpkgs under the names &amp;lt;code&amp;gt;emacs&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;emacs-gtk&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/NixOS/nixpkgs/pull/189543 Since 2022-09], the package called &amp;lt;code&amp;gt;emacs&amp;lt;/code&amp;gt; now installs the lucid toolkit instead of gtk. The reason is that Emacs is less stable with gtk especially in daemon mode. However, the lucid flavor of Emacs will not take into account the GTK theme (since it is not even GTK) and looks quite… ugly (see comparisons [https://emacs.stackexchange.com/questions/33065/on-linux-why-should-one-choose-lucid-over-gtk-gui-for-emacs here]). If you still prefer the GTK version of Emacs, you can instead install &amp;lt;code&amp;gt;emacs-gtk&amp;lt;/code&amp;gt; (before 2022-09 this package does not exist and Emacs defaults to the gtk version).&lt;br /&gt;
&lt;br /&gt;
===== Unstable (community overlay) =====&lt;br /&gt;
The [https://github.com/nix-community/emacs-overlay community overlay] provides nightly versions of the Emacs unstable branches, ELPA/MELPA packages, and [https://github.com/ch11ng/exwm EXWM] + its dependencies. &#039;&#039;&#039;To use these, first apply the overlay (instructions below), which will make the packages available in nixpkgs.&#039;&#039;&#039; Then you can follow the normal nixpkgs installation instructions (above), but use your package of choice from the overlay (e.g. &amp;lt;code&amp;gt;pkgs.emacsGit&amp;lt;/code&amp;gt;) in place of &amp;lt;code&amp;gt;pkgs.emacs&amp;lt;/code&amp;gt;. See the [https://github.com/nix-community/emacs-overlay#emacs-overlay README] for a complete list of packages provided, and their differences.&lt;br /&gt;
&lt;br /&gt;
====== With flakes ======&lt;br /&gt;
Using a system flake, one can specify the specific revision of the overlay as a flake input, for example:&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
inputs.emacs-overlay.url = &amp;quot;github:nix-community/emacs-overlay/da2f552d133497abd434006e0cae996c0a282394&amp;quot;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;This can then be used in the system configuration by using the {{ic|self}} argument:&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
nixpkgs.overlays = [ (import self.inputs.emacs-overlay) ];&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
======  Without flakes ======&lt;br /&gt;
For installing one of the unstable branches of Emacs, add the following lines to your configuration file:&lt;br /&gt;
{{file|configuration.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  nixpkgs.overlays = [&lt;br /&gt;
    (import (builtins.fetchGit {&lt;br /&gt;
      url = &amp;quot;https://github.com/nix-community/emacs-overlay.git&amp;quot;;&lt;br /&gt;
      ref = &amp;quot;master&amp;quot;;&lt;br /&gt;
      rev = &amp;quot;bfc8f6edcb7bcf3cf24e4a7199b3f6fed96aaecf&amp;quot;; # change the revision&lt;br /&gt;
    }))&lt;br /&gt;
  ];&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
===== Darwin (macOS) =====&lt;br /&gt;
Nixpkgs provides several of the &amp;quot;Mac Port&amp;quot; versions of Emacs, which have been patched to provide better integration with macOS (see the [https://nixos.org/manual/nixos/stable/index.html#module-services-emacs-releases NixOS manual entry for a full list of packages]). However, those packages typically track the stable releases of Emacs.&lt;br /&gt;
&lt;br /&gt;
If you would like to use the latest version of Emacs on Darwin, one option is to use a package like &amp;lt;code&amp;gt;emacsPgkt&amp;lt;/code&amp;gt; from the community overlay (see above), and apply patches yourself via an override. For example, here is a derivation that applies the patches from the [https://github.com/d12frosted/homebrew-emacs-plus &amp;lt;code&amp;gt;emacs-plus&amp;lt;/code&amp;gt; homebrew formula]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
pkgs.emacsPgtk.overrideAttrs (old: {&lt;br /&gt;
      patches =&lt;br /&gt;
        (old.patches or [])&lt;br /&gt;
        ++ [&lt;br /&gt;
          # Fix OS window role (needed for window managers like yabai)&lt;br /&gt;
          (fetchpatch {&lt;br /&gt;
            url = &amp;quot;https://raw.githubusercontent.com/d12frosted/homebrew-emacs-plus/master/patches/emacs-28/fix-window-role.patch&amp;quot;;&lt;br /&gt;
            sha256 = &amp;quot;0c41rgpi19vr9ai740g09lka3nkjk48ppqyqdnncjrkfgvm2710z&amp;quot;;&lt;br /&gt;
          })&lt;br /&gt;
          # Enable rounded window with no decoration&lt;br /&gt;
          (fetchpatch {&lt;br /&gt;
            url = &amp;quot;https://raw.githubusercontent.com/d12frosted/homebrew-emacs-plus/master/patches/emacs-29/round-undecorated-frame.patch&amp;quot;;&lt;br /&gt;
            sha256 = &amp;quot;111i0r3ahs0f52z15aaa3chlq7ardqnzpwp8r57kfsmnmg6c2nhf&amp;quot;;&lt;br /&gt;
          })&lt;br /&gt;
          # Make Emacs aware of OS-level light/dark mode&lt;br /&gt;
          (fetchpatch {&lt;br /&gt;
            url = &amp;quot;https://raw.githubusercontent.com/d12frosted/homebrew-emacs-plus/master/patches/emacs-28/system-appearance.patch&amp;quot;;&lt;br /&gt;
            sha256 = &amp;quot;14ndp2fqqc95s70fwhpxq58y8qqj4gzvvffp77snm2xk76c1bvnn&amp;quot;;&lt;br /&gt;
          })&lt;br /&gt;
        ];&lt;br /&gt;
    });&lt;br /&gt;
  };&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
==== Plasma taskbar grouping ====&lt;br /&gt;
To fix/workaround [[KDE|Plasma]] grouping Emacs incorrectly (confusing emacs.desktop with emacsclient.desktop), perform the following:&lt;br /&gt;
&lt;br /&gt;
* Open Emacs&lt;br /&gt;
* Right click title bar&lt;br /&gt;
* More Actions &amp;gt; Configure Special Window Settings&lt;br /&gt;
* Add Property &amp;gt; Desktop File Name&lt;br /&gt;
* Set desktop file name to &amp;quot;/home/&amp;lt;USERNAME&amp;gt;/.nix-profile/share/applications/emacs.desktop&amp;quot;&lt;br /&gt;
* Apply the changes&lt;br /&gt;
* Restart Emacs if need&lt;br /&gt;
&lt;br /&gt;
All Emacs instances should now be grouped together, allowing you to pin it and reliably switch to it with Super+&amp;lt;number&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Spell checking ====&lt;br /&gt;
Because Emacs expects the dictionaries to be on the same directory as aspell, they won&#039;t be picked up. To fix it install the &amp;lt;code&amp;gt;aspellWithDicts&amp;lt;/code&amp;gt; package, specifying the dictionaries you want to use: &lt;br /&gt;
&lt;br /&gt;
{{file|configuration.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  environment.systemPackages = with pkgs; [&lt;br /&gt;
    (aspellWithDicts (dicts: with dicts; [ en en-computers en-science es]))&lt;br /&gt;
  ];&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
A list of official dictionaries for aspell can be found on [https://ftp.gnu.org/gnu/aspell/dict/0index.html  Aspell Website]&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[Home Manager]] – For declarative Emacs configuration at the user level: [https://nix-community.github.io/home-manager/options.html#opt-programs.emacs.enable Emacs module in Home Manager]&lt;br /&gt;
* [https://www.gnu.org/software/emacs/manual/ Emacs Manuals] – Official Emacs documentation.&lt;br /&gt;
* [https://search.nixos.org/options?channel=unstable&amp;amp;query=services.emacs NixOS options for Emacs services] – System-level Emacs configuration.&lt;br /&gt;
* [https://discourse.nixos.org/search?q=emacs Emacs discussions on NixOS Discourse] – Community tips, troubleshooting, and use cases.&lt;br /&gt;
* [https://doomemacs.org Doom Emacs] – A popular Emacs configuration framework.&lt;br /&gt;
* [https://github.com/nix-community/emacs-overlay Emacs Overlay on Nixpkgs] – For nightly builds and additional Emacs packages.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
[[Category:Applications]]&lt;br /&gt;
[[Category:CLI Applications]]&lt;br /&gt;
[[Category:NixOS Manual]]&lt;br /&gt;
[[Category:Text Editor]]&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=Emacs&amp;diff=29403</id>
		<title>Emacs</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=Emacs&amp;diff=29403"/>
		<updated>2026-01-09T19:51:22Z</updated>

		<summary type="html">&lt;p&gt;Pigs: /* Advanced */ defaultEditor is only an option for services.emacs, not programs.emacs&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{application infobox&lt;br /&gt;
  |name=GNU Emacs&lt;br /&gt;
  |image=EmacsIcon.svg&lt;br /&gt;
  |type=Text Editor&lt;br /&gt;
  |firstRelease=1985; 40 years ago&lt;br /&gt;
  |license=[https://www.gnu.org/licenses/gpl.html GNU General Public License]&lt;br /&gt;
  |os=Cross-platform&lt;br /&gt;
  |website=[https://www.gnu.org/software/emacs gnu.org/emacs]&lt;br /&gt;
  |github=&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;strong&amp;gt;Emacs&amp;lt;/strong&amp;gt; is a free and open-source text editor known for its exceptional extensibility and adaptability. It can be customized into anything from a simple editor to a full development environment or productivity tool. Emacs features built-in self-documentation, syntax-aware editing, and a vast ecosystem of community-developed packages.&amp;lt;ref&amp;gt;https://www.gnu.org/software/emacs/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For an easier introduction, [https://doomemacs.org Doom Emacs] offers a pre-configured Emacs framework with modern defaults and features like IDE tools, note-taking, and task management.&lt;br /&gt;
&lt;br /&gt;
There is an official Matrix room for Nix/Emacs: [https://matrix.to/#/#emacs:nixos.org #emacs:nixos.org].&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
==== Shell ====&lt;br /&gt;
&lt;br /&gt;
To temporarily use Emacs in a shell environment without modifying your system configuration, you can run:&lt;br /&gt;
{{Commands|&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
$ nix-shell -p emacs&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
This makes the Emacs editor available in your current shell. You can then launch Emacs by typing &amp;lt;code&amp;gt;emacs&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== System setup ====&lt;br /&gt;
&lt;br /&gt;
To install Emacs system-wide, making it available to all users, add the following to your configuration:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
# Example for /etc/nixos/configuration.nix&lt;br /&gt;
environment.systemPackages = [&lt;br /&gt;
  pkgs.emacs&lt;br /&gt;
];&lt;br /&gt;
&lt;br /&gt;
# User-specific installation (in ~/.config/nixpkgs/home.nix)&lt;br /&gt;
home.packages = [&lt;br /&gt;
  pkgs.emacs&lt;br /&gt;
];&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
After rebuilding your system with &amp;lt;code&amp;gt;nixos-rebuild switch&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;home-manager switch&amp;lt;/code&amp;gt;, Emacs will be installed and accessible.&lt;br /&gt;
&lt;br /&gt;
== Configuration ==&lt;br /&gt;
{{Note|Currently, configuring Emacs is possible by using Home Manager. A workaround for a global configuration is highlighted in the advanced section.}}&lt;br /&gt;
&lt;br /&gt;
==== Basic ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
programs.emacs = {&lt;br /&gt;
   enable = true;&lt;br /&gt;
   defaultEditor = true;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Advanced ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
# Global Configuration&lt;br /&gt;
# Emacs is running as a daemon here, accesible via the &amp;quot;emacsclient&amp;quot; command&lt;br /&gt;
services.emacs = {&lt;br /&gt;
  enable = true;&lt;br /&gt;
  package = pkgs.emacs; &lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
# Home Configuration&lt;br /&gt;
programs.emacs = {&lt;br /&gt;
  enable = true;&lt;br /&gt;
  package = pkgs.emacs;  # replace with pkgs.emacs-gtk if desired&lt;br /&gt;
  extraConfig = &#039;&#039;&lt;br /&gt;
    (setq standard-indent 2)&lt;br /&gt;
  &#039;&#039;;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Tips and Tricks ==&lt;br /&gt;
&lt;br /&gt;
==== Installing Packages ====&lt;br /&gt;
{{Note|Emacs, much like NixOS can rebuild and re-fetch all of its packages based on its initialization file alone, if one chooses to use an extension called &amp;quot;use-package&amp;quot;. Such a configuration file can be version controlled and used in all compatible operating systems.}}&lt;br /&gt;
One can mix and match whether Emacs packages are installed by Nix or Emacs. This can be particularly useful for Emacs packages that need to be built, such as vterm. One way to install Emacs packages through Nix is by the following, replacing {{ic|emacs-pgtk}} with the variant in use:&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
environment.systemPackages = with pkgs;&lt;br /&gt;
[ ...&lt;br /&gt;
  ((emacsPackagesFor emacs-pgtk).emacsWithPackages (&lt;br /&gt;
    epkgs: [ epkgs.vterm ]&lt;br /&gt;
  ))&lt;br /&gt;
  ...&lt;br /&gt;
];&lt;br /&gt;
&lt;br /&gt;
# To make the packages available to emacsclient, one can do the following:&lt;br /&gt;
services.emacs.package = with pkgs; (&lt;br /&gt;
  (emacsPackagesFor emacs-pgtk).emacsWithPackages (&lt;br /&gt;
    epkgs: [ epkgs.vterm ]&lt;br /&gt;
  )&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
# Some packages have characters like + that Nix considers a syntax error. &lt;br /&gt;
# To fix this, write the package name in quotes and specify the package set, even if using with epkgs;. &lt;br /&gt;
# For example, use epkgs.&amp;quot;ido-completing-read+&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;Note that if the expression &amp;lt;code&amp;gt;(emacsPackagesFor emacs-pgtk)&amp;lt;/code&amp;gt; is present, &amp;lt;code&amp;gt;emacs-pgtk&amp;lt;/code&amp;gt; need not be listed separately in the list &amp;lt;code&amp;gt;environment.systemPackages&amp;lt;/code&amp;gt;. Indeed, if one does that, &amp;lt;code&amp;gt;nixos-rebuild&amp;lt;/code&amp;gt; will warn about link collisions when the configuration is rebuilt.&lt;br /&gt;
&lt;br /&gt;
====== Alternative way of installation to ensuring consistent package management for emacs and emacsclient ======&lt;br /&gt;
If you plan to use the same packages for both emacs and emacsclient, you can define a custom emacs like this:&lt;br /&gt;
{{file|/etc/nixos/configuration.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
  nixpkgs.config.packageOverrides = pkgs: rec {&lt;br /&gt;
    myEmacs = pkgs.emacs.pkgs.withPackages (epkgs: with epkgs; [&lt;br /&gt;
      org&lt;br /&gt;
      nixmode&lt;br /&gt;
      ... # list all your desired emacsPackages here&lt;br /&gt;
    ]);&lt;br /&gt;
  };&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
You may then reference it twice:&lt;br /&gt;
&lt;br /&gt;
{{file|/etc/nixos/configuration.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
  ## if you want it per-user instead of system-wide use &#039;users.users.&amp;lt;name&amp;gt;.packages = with pkgs; [&#039; instead&lt;br /&gt;
  environment.systemPackages = with pkgs; [&lt;br /&gt;
    myEmacs&lt;br /&gt;
  ];&lt;br /&gt;
&lt;br /&gt;
  ## enabling emacsclient and making all the packages available&lt;br /&gt;
  services.emacs = {&lt;br /&gt;
    enable = true;&lt;br /&gt;
    package = pkgs.myEmacs;&lt;br /&gt;
  };&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Using this approach, there is no need to keep two lists of emacsPackages in sync.&lt;br /&gt;
&lt;br /&gt;
==== Tree-sitter ====&lt;br /&gt;
[[Emacs]] 29 [[emacswiki:Tree-sitter|supports Tree-sitter parsers]] when built with the &amp;lt;code&amp;gt;--with-tree-sitter&amp;lt;/code&amp;gt; option. The &amp;lt;code&amp;gt;emacsPackages.treesit-grammars&amp;lt;/code&amp;gt; fake package makes them accessible to Emacs when using &amp;lt;code&amp;gt;emacs29.pkgs.withPackages&amp;lt;/code&amp;gt;:&amp;lt;ref&amp;gt;https://github.com/NixOS/nixpkgs/pull/230751&amp;lt;/ref&amp;gt;&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  pkgs ? import &amp;lt;nixpkgs&amp;gt; { },&lt;br /&gt;
}:&lt;br /&gt;
pkgs.emacs29.pkgs.withPackages (epkgs: [&lt;br /&gt;
  (epkgs.treesit-grammars.with-grammars (grammars: [ grammars.tree-sitter-bash ]))&lt;br /&gt;
])&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When using Emacs with tree-sitter support, it&#039;s recommended to install both &amp;lt;code&amp;gt;epkgs.tree-sitter-langs&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;epkgs.treesit-grammars&amp;lt;/code&amp;gt;. While &amp;lt;code&amp;gt;treesit-grammars&amp;lt;/code&amp;gt; handles the registration of grammars with Emacs&#039;s native tree-sitter interface, the actual grammar files will come from &amp;lt;code&amp;gt;tree-sitter-langs&amp;lt;/code&amp;gt;. &amp;lt;code&amp;gt;tree-sitter-langs&amp;lt;/code&amp;gt; being a MELPA package means it receives regular updates when new grammar versions are released, whereas the grammars in the tree-sitter-grammars package may lag behind in nixpkgs. The combination ensures you get both up-to-date grammars and proper integration with Emacs&#039;s built-in tree-sitter support.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Bonus Tip:&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;emacs.pkgs.pretty-sha-path&amp;lt;/code&amp;gt; is quality of life improvement for Nix, Guix users.&lt;br /&gt;
&lt;br /&gt;
Allows toggling Guix/Nix store paths by replacing SHA-sequences with ellipsis, i.e.:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;/gnu/store/72f54nfp6g1hz873w8z3gfcah0h4nl9p-foo-0.1  →  /gnu/store/…-foo-0.1&lt;br /&gt;
/nix/store/nh4n4yzb1bx7nss2rg342dz44g14m06x-bar-0.2  →  /nix/store/…-bar-0.2&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
located at https://github.com/alezost/pretty-sha-path.el&lt;br /&gt;
&lt;br /&gt;
==== Automatic Package Management ====&lt;br /&gt;
If you use &amp;lt;code&amp;gt;use-package&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;leaf&amp;lt;/code&amp;gt; in your configuration, the community overlay can manage your Emacs packages automatically by using &amp;lt;code&amp;gt;emacsWithPackagesFromUsePackage&amp;lt;/code&amp;gt;. First, install the overlay (instructions above), then add the following to your &amp;lt;code&amp;gt;configuration.nix&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  environment.systemPackages = [&lt;br /&gt;
    (pkgs.emacsWithPackagesFromUsePackage {&lt;br /&gt;
      package = pkgs.emacsGit;  # replace with pkgs.emacsPgtk, or another version if desired.&lt;br /&gt;
      config = path/to/your/config.el;&lt;br /&gt;
      # config = path/to/your/config.org; # Org-Babel configs also supported&lt;br /&gt;
&lt;br /&gt;
      # Optionally provide extra packages not in the configuration file.&lt;br /&gt;
      extraEmacsPackages = epkgs: [&lt;br /&gt;
        epkgs.use-package&lt;br /&gt;
      ];&lt;br /&gt;
&lt;br /&gt;
      # Optionally override derivations.&lt;br /&gt;
      override = epkgs: epkgs // {&lt;br /&gt;
        somePackage = epkgs.melpaPackages.somePackage.overrideAttrs(old: {&lt;br /&gt;
           # Apply fixes here&lt;br /&gt;
        });&lt;br /&gt;
      };&lt;br /&gt;
    })&lt;br /&gt;
  ];&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See the [https://github.com/nix-community/emacs-overlay#extra-library-functionality overlay README] for a full list of options.&lt;br /&gt;
&lt;br /&gt;
==== Adding packages from outside ELPA/MELPA ====&lt;br /&gt;
Some packages may require more sophisticated derivation, but the following is a good starting point for adding external packages:&lt;br /&gt;
&lt;br /&gt;
{{file|lambda-line.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  melpaBuild,&lt;br /&gt;
  fetchFromGitHub,&lt;br /&gt;
  all-the-icons,&lt;br /&gt;
}:&lt;br /&gt;
melpaBuild {&lt;br /&gt;
  pname = &amp;quot;lambda-line&amp;quot;;&lt;br /&gt;
  version = &amp;quot;0-unstable-2022-11-23&amp;quot;;&lt;br /&gt;
  src = fetchFromGitHub {&lt;br /&gt;
    owner = &amp;quot;Lambda-Emacs&amp;quot;;&lt;br /&gt;
    repo = &amp;quot;lambda-line&amp;quot;;&lt;br /&gt;
    rev = &amp;quot;22186321a7442f1bd3b121f739007bd809cb38f8&amp;quot;;&lt;br /&gt;
    hash = &amp;quot;sha256-2tOXMqpmd14ohzmrRoV5Urf0HlnRPV1EVHm/d8OBSGE=&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
  # elisp dependencies&lt;br /&gt;
  packageRequires = [&lt;br /&gt;
    all-the-icons&lt;br /&gt;
  ];&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
You can then use the new package with automatic package management like so:&lt;br /&gt;
&lt;br /&gt;
{{file|configuration.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  environment.systemPackages = [&lt;br /&gt;
    (pkgs.emacsWithPackagesFromUsePackage {&lt;br /&gt;
      ...&lt;br /&gt;
      override = epkgs: epkgs // {&lt;br /&gt;
        lambda-line = callPackage ./lambda-line.nix {&lt;br /&gt;
          inherit (pkgs) fetchFromGitHub;&lt;br /&gt;
          inherit (epkgs) melpaBuild all-the-icons;&lt;br /&gt;
        };&lt;br /&gt;
      };&lt;br /&gt;
    })&lt;br /&gt;
  ];&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
or manual package management like so:&lt;br /&gt;
&lt;br /&gt;
{{file|configuration.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  environment.systemPackages = with pkgs;&lt;br /&gt;
    [ ...&lt;br /&gt;
      ((emacsPackagesFor emacs-pgtk).emacsWithPackages (epkgs: [ &lt;br /&gt;
          epkgs.vterm &lt;br /&gt;
          (callPackage ./lambda-line.nix {&lt;br /&gt;
            inherit (pkgs) fetchFromGitHub;&lt;br /&gt;
            inherit (epkgs) melpaBuild all-the-icons;&lt;br /&gt;
          };) &lt;br /&gt;
       ]))&lt;br /&gt;
      ...&lt;br /&gt;
    ];&lt;br /&gt;
}&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
==== Packaging and testing Emacs nixpkgs ====&lt;br /&gt;
Emacs packages can be defined and tested like other nixpkgs.&lt;br /&gt;
They can be obtained from melpa, elpa or other sources such as github.&lt;br /&gt;
&lt;br /&gt;
{{file|default.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
{ melpaBuild&lt;br /&gt;
, lib&lt;br /&gt;
, fetchFromGitHub&lt;br /&gt;
...&lt;br /&gt;
}:&lt;br /&gt;
&lt;br /&gt;
melpaBuild {&lt;br /&gt;
  pname = &amp;quot;...&amp;quot;;&lt;br /&gt;
  version = &amp;quot;...&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
  src = fetchFromGitHub {&lt;br /&gt;
    owner = &amp;quot;...&amp;quot;;&lt;br /&gt;
    repo = &amp;quot;...&amp;quot;;&lt;br /&gt;
    rev = &amp;quot;...&amp;quot;;&lt;br /&gt;
    hash = &amp;quot;...&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
&lt;br /&gt;
  packageRequires = [ ... ];&lt;br /&gt;
&lt;br /&gt;
  patches = [ ... ];&lt;br /&gt;
&lt;br /&gt;
  meta = {&lt;br /&gt;
    description = &amp;quot;...&amp;quot;;&lt;br /&gt;
    license = lib.licenses.gpl3Plus;&lt;br /&gt;
  };&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
They are located at &amp;lt;code&amp;gt;pkgs/applications/editors/emacs/elisp-packages/manual-packages/&amp;lt;/code&amp;gt; [https://github.com/NixOS/nixpkgs/tree/master/pkgs/applications/editors/emacs/elisp-packages/manual-packages] and a new pkg must be added under &amp;lt;code&amp;gt;pkgs/applications/editors/elisp-packages/manual-packages.nix&amp;lt;/code&amp;gt; [https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/editors/emacs/elisp-packages/manual-packages.nix]. Once the nixpkg is ready, it can be tested using the following command. This inserts the nixpkg into the load-path of Emacs.&lt;br /&gt;
{{Commands|&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
$ nix-shell -I nixpkgs=&amp;lt;path_to_nixpkgs_copy&amp;gt; -p &amp;quot;(emacsPackagesFor pkgs.emacs28).emacsWithPackages (epkgs: [ epkgs.&amp;lt;package&amp;gt; ])&amp;quot;&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==== Window Manager Integration ====&lt;br /&gt;
Out of the box, non-&amp;quot;Mac Port&amp;quot; versions of Emacs will not be picked up properly by window managers like [https://github.com/koekeishiya/yabai Yabai] because [https://github.com/koekeishiya/yabai/issues/86#issuecomment-507537023 Emacs does not set the correct macOS window role]. This can be fixed with a patch (e.g. the first patch in the example above). However, even with the patch, Yabai may not correctly pick up Emacs if you invoke the &amp;lt;code&amp;gt;emacs&amp;lt;/code&amp;gt; binary directly from a shell. For Emacs to work properly with window managers you must invoke it by running the macOS app that is generated when you install Emacs with nix. You can setup an alias to do this like so (replace &amp;lt;code&amp;gt;pkgs.emacs&amp;lt;/code&amp;gt; with the package you are using):&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
programs.zsh = {&lt;br /&gt;
  enable = true;&lt;br /&gt;
  shellAliases = {&lt;br /&gt;
    emacs = &amp;quot;${pkgs.emacs}/Applications/Emacs.app/Contents/MacOS/Emacs&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Available Emacs Variants ====&lt;br /&gt;
{{warning| Certain issues are possible, when mixing different versions of Emacs, in particular a configuration file tailored towards emacs with native compilation, may misbehave on non-native compiling versions, unless only the emacs lisp code is shared between them.}}&lt;br /&gt;
&lt;br /&gt;
===== Stable (nixpkgs) =====&lt;br /&gt;
Emacs is available in nixpkgs under the names &amp;lt;code&amp;gt;emacs&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;emacs-gtk&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[https://github.com/NixOS/nixpkgs/pull/189543 Since 2022-09], the package called &amp;lt;code&amp;gt;emacs&amp;lt;/code&amp;gt; now installs the lucid toolkit instead of gtk. The reason is that Emacs is less stable with gtk especially in daemon mode. However, the lucid flavor of Emacs will not take into account the GTK theme (since it is not even GTK) and looks quite… ugly (see comparisons [https://emacs.stackexchange.com/questions/33065/on-linux-why-should-one-choose-lucid-over-gtk-gui-for-emacs here]). If you still prefer the GTK version of Emacs, you can instead install &amp;lt;code&amp;gt;emacs-gtk&amp;lt;/code&amp;gt; (before 2022-09 this package does not exist and Emacs defaults to the gtk version).&lt;br /&gt;
&lt;br /&gt;
===== Unstable (community overlay) =====&lt;br /&gt;
The [https://github.com/nix-community/emacs-overlay community overlay] provides nightly versions of the Emacs unstable branches, ELPA/MELPA packages, and [https://github.com/ch11ng/exwm EXWM] + its dependencies. &#039;&#039;&#039;To use these, first apply the overlay (instructions below), which will make the packages available in nixpkgs.&#039;&#039;&#039; Then you can follow the normal nixpkgs installation instructions (above), but use your package of choice from the overlay (e.g. &amp;lt;code&amp;gt;pkgs.emacsGit&amp;lt;/code&amp;gt;) in place of &amp;lt;code&amp;gt;pkgs.emacs&amp;lt;/code&amp;gt;. See the [https://github.com/nix-community/emacs-overlay#emacs-overlay README] for a complete list of packages provided, and their differences.&lt;br /&gt;
&lt;br /&gt;
====== With flakes ======&lt;br /&gt;
Using a system flake, one can specify the specific revision of the overlay as a flake input, for example:&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
inputs.emacs-overlay.url = &amp;quot;github:nix-community/emacs-overlay/da2f552d133497abd434006e0cae996c0a282394&amp;quot;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;This can then be used in the system configuration by using the {{ic|self}} argument:&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
nixpkgs.overlays = [ (import self.inputs.emacs-overlay) ];&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
======  Without flakes ======&lt;br /&gt;
For installing one of the unstable branches of Emacs, add the following lines to your configuration file:&lt;br /&gt;
{{file|configuration.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  nixpkgs.overlays = [&lt;br /&gt;
    (import (builtins.fetchGit {&lt;br /&gt;
      url = &amp;quot;https://github.com/nix-community/emacs-overlay.git&amp;quot;;&lt;br /&gt;
      ref = &amp;quot;master&amp;quot;;&lt;br /&gt;
      rev = &amp;quot;bfc8f6edcb7bcf3cf24e4a7199b3f6fed96aaecf&amp;quot;; # change the revision&lt;br /&gt;
    }))&lt;br /&gt;
  ];&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
===== Darwin (macOS) =====&lt;br /&gt;
Nixpkgs provides several of the &amp;quot;Mac Port&amp;quot; versions of Emacs, which have been patched to provide better integration with macOS (see the [https://nixos.org/manual/nixos/stable/index.html#module-services-emacs-releases NixOS manual entry for a full list of packages]). However, those packages typically track the stable releases of Emacs.&lt;br /&gt;
&lt;br /&gt;
If you would like to use the latest version of Emacs on Darwin, one option is to use a package like &amp;lt;code&amp;gt;emacsPgkt&amp;lt;/code&amp;gt; from the community overlay (see above), and apply patches yourself via an override. For example, here is a derivation that applies the patches from the [https://github.com/d12frosted/homebrew-emacs-plus &amp;lt;code&amp;gt;emacs-plus&amp;lt;/code&amp;gt; homebrew formula]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
pkgs.emacsPgtk.overrideAttrs (old: {&lt;br /&gt;
      patches =&lt;br /&gt;
        (old.patches or [])&lt;br /&gt;
        ++ [&lt;br /&gt;
          # Fix OS window role (needed for window managers like yabai)&lt;br /&gt;
          (fetchpatch {&lt;br /&gt;
            url = &amp;quot;https://raw.githubusercontent.com/d12frosted/homebrew-emacs-plus/master/patches/emacs-28/fix-window-role.patch&amp;quot;;&lt;br /&gt;
            sha256 = &amp;quot;0c41rgpi19vr9ai740g09lka3nkjk48ppqyqdnncjrkfgvm2710z&amp;quot;;&lt;br /&gt;
          })&lt;br /&gt;
          # Enable rounded window with no decoration&lt;br /&gt;
          (fetchpatch {&lt;br /&gt;
            url = &amp;quot;https://raw.githubusercontent.com/d12frosted/homebrew-emacs-plus/master/patches/emacs-29/round-undecorated-frame.patch&amp;quot;;&lt;br /&gt;
            sha256 = &amp;quot;111i0r3ahs0f52z15aaa3chlq7ardqnzpwp8r57kfsmnmg6c2nhf&amp;quot;;&lt;br /&gt;
          })&lt;br /&gt;
          # Make Emacs aware of OS-level light/dark mode&lt;br /&gt;
          (fetchpatch {&lt;br /&gt;
            url = &amp;quot;https://raw.githubusercontent.com/d12frosted/homebrew-emacs-plus/master/patches/emacs-28/system-appearance.patch&amp;quot;;&lt;br /&gt;
            sha256 = &amp;quot;14ndp2fqqc95s70fwhpxq58y8qqj4gzvvffp77snm2xk76c1bvnn&amp;quot;;&lt;br /&gt;
          })&lt;br /&gt;
        ];&lt;br /&gt;
    });&lt;br /&gt;
  };&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
==== Plasma taskbar grouping ====&lt;br /&gt;
To fix/workaround [[KDE|Plasma]] grouping Emacs incorrectly (confusing emacs.desktop with emacsclient.desktop), perform the following:&lt;br /&gt;
&lt;br /&gt;
* Open Emacs&lt;br /&gt;
* Right click title bar&lt;br /&gt;
* More Actions &amp;gt; Configure Special Window Settings&lt;br /&gt;
* Add Property &amp;gt; Desktop File Name&lt;br /&gt;
* Set desktop file name to &amp;quot;/home/&amp;lt;USERNAME&amp;gt;/.nix-profile/share/applications/emacs.desktop&amp;quot;&lt;br /&gt;
* Apply the changes&lt;br /&gt;
* Restart Emacs if need&lt;br /&gt;
&lt;br /&gt;
All Emacs instances should now be grouped together, allowing you to pin it and reliably switch to it with Super+&amp;lt;number&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Spell checking ====&lt;br /&gt;
Because Emacs expects the dictionaries to be on the same directory as aspell, they won&#039;t be picked up. To fix it install the &amp;lt;code&amp;gt;aspellWithDicts&amp;lt;/code&amp;gt; package, specifying the dictionaries you want to use: &lt;br /&gt;
&lt;br /&gt;
{{file|configuration.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  environment.systemPackages = with pkgs; [&lt;br /&gt;
    (aspellWithDicts (dicts: with dicts; [ en en-computers en-science es]))&lt;br /&gt;
  ];&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
A list of official dictionaries for aspell can be found on [https://ftp.gnu.org/gnu/aspell/dict/0index.html  Aspell Website]&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[Home Manager]] – For declarative Emacs configuration at the user level: [https://nix-community.github.io/home-manager/options.html#opt-programs.emacs.enable Emacs module in Home Manager]&lt;br /&gt;
* [https://www.gnu.org/software/emacs/manual/ Emacs Manuals] – Official Emacs documentation.&lt;br /&gt;
* [https://search.nixos.org/options?channel=unstable&amp;amp;query=services.emacs NixOS options for Emacs services] – System-level Emacs configuration.&lt;br /&gt;
* [https://discourse.nixos.org/search?q=emacs Emacs discussions on NixOS Discourse] – Community tips, troubleshooting, and use cases.&lt;br /&gt;
* [https://doomemacs.org Doom Emacs] – A popular Emacs configuration framework.&lt;br /&gt;
* [https://github.com/nix-community/emacs-overlay Emacs Overlay on Nixpkgs] – For nightly builds and additional Emacs packages.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
[[Category:Applications]]&lt;br /&gt;
[[Category:CLI Applications]]&lt;br /&gt;
[[Category:NixOS Manual]]&lt;br /&gt;
[[Category:Text Editor]]&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=Flakes&amp;diff=29375</id>
		<title>Flakes</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=Flakes&amp;diff=29375"/>
		<updated>2026-01-05T18:50:02Z</updated>

		<summary type="html">&lt;p&gt;Pigs: fix broken link&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;languages /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Cleanup}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:182--&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Nix flakes&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:183--&amp;gt;&lt;br /&gt;
A flake is a directory which directly contains a Nix file called &amp;lt;code&amp;gt;flake.nix&amp;lt;/code&amp;gt;, 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 &amp;lt;code&amp;gt;github:NixOS/nixpkgs&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:184--&amp;gt;&lt;br /&gt;
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}}&lt;br /&gt;
&lt;br /&gt;
== Flake file structure == &amp;lt;!--T:185--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:231--&amp;gt;&lt;br /&gt;
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:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{File|3=&amp;lt;nowiki&amp;gt;{&lt;br /&gt;
  description = &amp;quot;A very basic flake&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
  inputs = {&lt;br /&gt;
    nixpkgs.url = &amp;quot;github:nixos/nixpkgs?ref=nixos-unstable&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
&lt;br /&gt;
  outputs = { self, nixpkgs }: {&lt;br /&gt;
    packages.x86_64-linux = {&lt;br /&gt;
      default = self.packages.x86_64-linux.hello;&lt;br /&gt;
      hello = nixpkgs.legacyPackages.x86_64-linux.hello;&lt;br /&gt;
    };&lt;br /&gt;
  };&lt;br /&gt;
}&amp;lt;/nowiki&amp;gt;|name=flake.nix|lang=nix}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:190--&amp;gt;&lt;br /&gt;
In the example above, you can see the description, the input specified as a GitHub repository with a specific branch (here &amp;lt;code&amp;gt;nixos/nixpkgs&amp;lt;/code&amp;gt; on the &amp;lt;code&amp;gt;nixos-unstable&amp;lt;/code&amp;gt; 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 &amp;lt;code&amp;gt;hello&amp;lt;/code&amp;gt;. Even if your flake&#039;s output wouldn&#039;t use its input (however, in practice, that is highly unlikely), the output still needs to be a Nix function.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:232--&amp;gt;&lt;br /&gt;
{{Note|Flakes require you to specify its outputs for each architecture separately. For more information, read the related section below.}}&lt;br /&gt;
&lt;br /&gt;
=== Nix configuration === &amp;lt;!--T:191--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:233--&amp;gt;&lt;br /&gt;
It is possible to override the global Nix configuration set in your &amp;lt;code&amp;gt;nix.conf&amp;lt;/code&amp;gt; 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:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{File|3=&amp;lt;nowiki&amp;gt;{&lt;br /&gt;
  ...&lt;br /&gt;
  nixConfig = {&lt;br /&gt;
    extra-substituters = [&lt;br /&gt;
      &amp;quot;https://nix-community.cachix.org&amp;quot;&lt;br /&gt;
    ];&lt;br /&gt;
    extra-trusted-public-keys = [&lt;br /&gt;
      &amp;quot;nix-community.cachix.org-1:...=&amp;quot;&lt;br /&gt;
    ];&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/nowiki&amp;gt;|name=flake.nix|lang=nix}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:234--&amp;gt;&lt;br /&gt;
{{Note|If you are used to configuring your Nix settings via the NixOS configuration, these options are under &amp;lt;code&amp;gt;nix.settings&amp;lt;/code&amp;gt; and not &amp;lt;code&amp;gt;nix&amp;lt;/code&amp;gt;. For example, you cannot specify the automatic storage optimisation under &amp;lt;code&amp;gt;nix.optimisation.enable&amp;lt;/code&amp;gt;.}}&lt;br /&gt;
&lt;br /&gt;
== Setup == &amp;lt;!--T:192--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enabling flakes temporarily === &amp;lt;!--T:5--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:6--&amp;gt;&lt;br /&gt;
When using any [[Nix command|&amp;lt;code&amp;gt;nix&amp;lt;/code&amp;gt; command]], add the following command-line options:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
 --experimental-features &#039;nix-command flakes&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Enabling flakes permanently === &amp;lt;!--T:193--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== NixOS ==== &amp;lt;!--T:7--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:8--&amp;gt;&lt;br /&gt;
Add the following to the [[Overview_of_the_NixOS_Linux_distribution#Declarative_Configuration system configuration |NixOS configuration]]:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxHighlight lang=nix&amp;gt;&lt;br /&gt;
  nix.settings.experimental-features = [ &amp;quot;nix-command&amp;quot; &amp;quot;flakes&amp;quot; ];&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
====Home Manager==== &amp;lt;!--T:10--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:11--&amp;gt;&lt;br /&gt;
Add the following to your [[Home Manager|home manager]] config:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
  nix.settings.experimental-features = [ &amp;quot;nix-command&amp;quot; &amp;quot;flakes&amp;quot; ];&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
====Nix standalone==== &amp;lt;!--T:13--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:14--&amp;gt;&lt;br /&gt;
{{Note | The  [https://github.com/DeterminateSystems/nix-installer Determinate Nix Installer] enables flakes by default.}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:15--&amp;gt;&lt;br /&gt;
Add the following to &amp;lt;code&amp;gt;~/.config/nix/nix.conf&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;/etc/nix/nix.conf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxHighlight lang=text&amp;gt;&lt;br /&gt;
experimental-features = nix-command flakes&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
== Usage == &amp;lt;!--T:17--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:20--&amp;gt;&lt;br /&gt;
{{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]].}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:146--&amp;gt;&lt;br /&gt;
{{Note | For flakes in [[git]] repositories, only files in the working tree will be copied to the store.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:22--&amp;gt;&lt;br /&gt;
Therefore, if you use &amp;lt;code&amp;gt;git&amp;lt;/code&amp;gt; for your flake, ensure to &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; any project files after you first create them.}}&lt;br /&gt;
&lt;br /&gt;
=== The nix flakes command === &amp;lt;!--T:64--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Main|Nix (command)}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:65--&amp;gt;&lt;br /&gt;
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}}.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:194--&amp;gt;&lt;br /&gt;
This flake produces a single flake output &amp;lt;code&amp;gt;packages&amp;lt;/code&amp;gt;. And within that, &amp;lt;code&amp;gt;x86_64-linux&amp;lt;/code&amp;gt; is a system-specifc attribute set. And within that, two package [[derivations]] &amp;lt;code&amp;gt;default&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;hello&amp;lt;/code&amp;gt;. 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:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
$ nix flake show&lt;br /&gt;
└───packages&lt;br /&gt;
    └───x86_64-linux&lt;br /&gt;
        ├───default: package &#039;hello-2.12.2&#039;&lt;br /&gt;
        └───hello: package &#039;hello-2.12.2&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== Development shells ==== &amp;lt;!--T:196--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:197--&amp;gt;&lt;br /&gt;
A &amp;lt;code&amp;gt;devShell&amp;lt;/code&amp;gt; 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 &amp;lt;code&amp;gt;nix-shell&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  description = &amp;quot;Example flake with a devShell&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
  inputs.nixpkgs.url = &amp;quot;github:nixos/nixpkgs?ref=nixos-unstable&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
  outputs = { self, nixpkgs }:&lt;br /&gt;
    let&lt;br /&gt;
      system = &amp;quot;x86_64-linux&amp;quot;;&lt;br /&gt;
      pkgs = import nixpkgs { inherit system; };&lt;br /&gt;
    in {&lt;br /&gt;
      devShells.x86_64-linux.default = pkgs.mkShell {&lt;br /&gt;
        buildInputs = with pkgs; [&lt;br /&gt;
          hello&lt;br /&gt;
        ];&lt;br /&gt;
        shellHook = &#039;&#039;&lt;br /&gt;
          echo &amp;quot;Welcome to the devShell!&amp;quot;&lt;br /&gt;
        &#039;&#039;;&lt;br /&gt;
      };&lt;br /&gt;
    };&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:201--&amp;gt;&lt;br /&gt;
To enter the development shell environment:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
$ nix develop&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:203--&amp;gt;&lt;br /&gt;
{{note|You don’t need to define a devShell to enter a development shell using nix develop.&lt;br /&gt;
If no devShell is defined, nix develop will drop you into an environment containing the default build dependencies of the flake (if any).}}&lt;br /&gt;
&lt;br /&gt;
==== Build specific attributes in a flake repository ==== &amp;lt;!--T:102--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:103--&amp;gt;&lt;br /&gt;
Running &amp;lt;code&amp;gt;nix build&amp;lt;/code&amp;gt; will look in the &amp;lt;code&amp;gt;legacyPackages&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;packages&amp;lt;/code&amp;gt; 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 &amp;lt;code&amp;gt;nix build .#&amp;lt;attr&amp;gt;&amp;lt;/code&amp;gt;. In the example above, if you wanted to build the &amp;lt;code&amp;gt;packages.x86_64-linux.hello&amp;lt;/code&amp;gt; attribute, run:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxHighlight lang=console&amp;gt;&lt;br /&gt;
$ nix build .#hello&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:205--&amp;gt;&lt;br /&gt;
Likewise, you can specify an attribute with the run command: &amp;lt;code&amp;gt;nix run .#hello&amp;lt;/code&amp;gt; and the develop command: &amp;lt;code&amp;gt;nix develop .#hello&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Flake schema == &amp;lt;!--T:27--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:28--&amp;gt;&lt;br /&gt;
The flake.nix file is a Nix file but that has special restrictions (more on that later).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:29--&amp;gt;&lt;br /&gt;
It has 4 top-level attributes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:30--&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;description&amp;lt;/code&amp;gt; is a string describing the flake.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:147--&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;inputs&amp;lt;/code&amp;gt; is an attribute set of all the dependencies of the flake. The schema is described below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:148--&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;outputs&amp;lt;/code&amp;gt; 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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:149--&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;nixConfig&amp;lt;/code&amp;gt; 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&#039;s nix experience by adding flake-specific configuration, such as a [[Binary Cache|binary cache]].&lt;br /&gt;
&lt;br /&gt;
=== Input schema === &amp;lt;!--T:31--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:32--&amp;gt;&lt;br /&gt;
[https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake.html#flake-inputs The nix flake inputs manual].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:150--&amp;gt;&lt;br /&gt;
[https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake.html#flake-references The nix flake references manual].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:33--&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:34--&amp;gt;&lt;br /&gt;
[[Nixpkgs]] can be defined using the following code:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;inputs.nixpkgs.url = &amp;quot;github:NixOS/nixpkgs/&amp;lt;branch name&amp;gt;&amp;quot;;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:235--&amp;gt;&lt;br /&gt;
Nixpkgs can alternatively also point to an url cached by the NixOS organization:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;inputs.nixpkgs.url = &amp;quot;&amp;lt;nowiki&amp;gt;https://nixos.org/channels/nixpkgs-unstable/nixexprs.tar.xz&amp;lt;/nowiki&amp;gt;&amp;quot;;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:236--&amp;gt;&lt;br /&gt;
In this example the input would point to the `nixpkgs-unstable` channel.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:36--&amp;gt;&lt;br /&gt;
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&#039;s on GitHub is unnecessary.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:37--&amp;gt;&lt;br /&gt;
For example, adding [[Hyprland]] as an input would look something like this:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;inputs.hyprland.url = &amp;quot;github:hyprwm/Hyprland&amp;quot;;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:39--&amp;gt;&lt;br /&gt;
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:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;inputs.hyprland.inputs.nixpkgs.follows = &amp;quot;nixpkgs&amp;quot;;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:41--&amp;gt;&lt;br /&gt;
Using curly brackets (&amp;lt;code&amp;gt;{}&amp;lt;/code&amp;gt;), we can shorten all of this and put it in a table. The code will look something like this:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
inputs = {&lt;br /&gt;
  nixpkgs.url = &amp;quot;github:NixOS/nixpkgs/&amp;lt;branch name&amp;gt;&amp;quot;;&lt;br /&gt;
  hyprland = {&lt;br /&gt;
    url = &amp;quot;github:hyprwm/Hyprland&amp;quot;;&lt;br /&gt;
    inputs.nixpkgs.follows = &amp;quot;nixpkgs&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:206--&amp;gt;&lt;br /&gt;
By default, Git submodules in package &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt;&#039;s won&#039;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:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
  inputs.self.submodules = true;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Output schema === &amp;lt;!--T:42--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:151--&amp;gt;&lt;br /&gt;
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].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:43--&amp;gt;&lt;br /&gt;
Once the inputs are resolved, they&#039;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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:44--&amp;gt;&lt;br /&gt;
Where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:45--&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;&amp;lt;system&amp;gt;&amp;lt;/code&amp;gt; is something like &amp;quot;x86_64-linux&amp;quot;, &amp;quot;aarch64-linux&amp;quot;, &amp;quot;i686-linux&amp;quot;, &amp;quot;x86_64-darwin&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:152--&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;&amp;lt;name&amp;gt;&amp;lt;/code&amp;gt; is an attribute name like &amp;quot;hello&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:153--&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;&amp;lt;flake&amp;gt;&amp;lt;/code&amp;gt; is a flake name like &amp;quot;nixpkgs&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:154--&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;&amp;lt;store-path&amp;gt;&amp;lt;/code&amp;gt; is a &amp;lt;code&amp;gt;/nix/store..&amp;lt;/code&amp;gt; path&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
{ self, ... }@inputs:&lt;br /&gt;
{&lt;br /&gt;
  # Executed by `nix flake check`&lt;br /&gt;
  checks.&amp;quot;&amp;lt;system&amp;gt;&amp;quot;.&amp;quot;&amp;lt;name&amp;gt;&amp;quot; = derivation;&lt;br /&gt;
  # Executed by `nix build .#&amp;lt;name&amp;gt;`&lt;br /&gt;
  packages.&amp;quot;&amp;lt;system&amp;gt;&amp;quot;.&amp;quot;&amp;lt;name&amp;gt;&amp;quot; = derivation;&lt;br /&gt;
  # Executed by `nix build .`&lt;br /&gt;
  packages.&amp;quot;&amp;lt;system&amp;gt;&amp;quot;.default = derivation;&lt;br /&gt;
  # Executed by `nix run .#&amp;lt;name&amp;gt;`&lt;br /&gt;
  apps.&amp;quot;&amp;lt;system&amp;gt;&amp;quot;.&amp;quot;&amp;lt;name&amp;gt;&amp;quot; = {&lt;br /&gt;
    type = &amp;quot;app&amp;quot;;&lt;br /&gt;
    program = &amp;quot;&amp;lt;store-path&amp;gt;&amp;quot;;&lt;br /&gt;
    meta = {description = &amp;quot;...&amp;quot;; inherit otherMetaAttrs; };&lt;br /&gt;
  };&lt;br /&gt;
  # Executed by `nix run . -- &amp;lt;args?&amp;gt;`&lt;br /&gt;
  apps.&amp;quot;&amp;lt;system&amp;gt;&amp;quot;.default = { type = &amp;quot;app&amp;quot;; program = &amp;quot;...&amp;quot;; meta = {description = &amp;quot;...&amp;quot;; inherit otherMetaAttrs; }; };&lt;br /&gt;
&lt;br /&gt;
  # Formatter (alejandra, nixfmt, treefmt-nix or nixpkgs-fmt)&lt;br /&gt;
  formatter.&amp;quot;&amp;lt;system&amp;gt;&amp;quot; = derivation;&lt;br /&gt;
  # Used for nixpkgs packages, also accessible via `nix build .#&amp;lt;name&amp;gt;`&lt;br /&gt;
  legacyPackages.&amp;quot;&amp;lt;system&amp;gt;&amp;quot;.&amp;quot;&amp;lt;name&amp;gt;&amp;quot; = derivation;&lt;br /&gt;
  # Overlay, consumed by other flakes&lt;br /&gt;
  overlays.&amp;quot;&amp;lt;name&amp;gt;&amp;quot; = final: prev: { };&lt;br /&gt;
  # Default overlay&lt;br /&gt;
  overlays.default = final: prev: { };&lt;br /&gt;
  # Nixos module, consumed by other flakes&lt;br /&gt;
  nixosModules.&amp;quot;&amp;lt;name&amp;gt;&amp;quot; = { config, ... }: { options = {}; config = {}; };&lt;br /&gt;
  # Default module&lt;br /&gt;
  nixosModules.default = { config, ... }: { options = {}; config = {}; };&lt;br /&gt;
  # Used with `nixos-rebuild switch --flake .#&amp;lt;hostname&amp;gt;`&lt;br /&gt;
  # nixosConfigurations.&amp;quot;&amp;lt;hostname&amp;gt;&amp;quot;.config.system.build.toplevel must be a derivation&lt;br /&gt;
  nixosConfigurations.&amp;quot;&amp;lt;hostname&amp;gt;&amp;quot; = {};&lt;br /&gt;
  # Used by `nix develop .#&amp;lt;name&amp;gt;`&lt;br /&gt;
  devShells.&amp;quot;&amp;lt;system&amp;gt;&amp;quot;.&amp;quot;&amp;lt;name&amp;gt;&amp;quot; = derivation;&lt;br /&gt;
  # Used by `nix develop`&lt;br /&gt;
  devShells.&amp;quot;&amp;lt;system&amp;gt;&amp;quot;.default = derivation;&lt;br /&gt;
  # Hydra build jobs&lt;br /&gt;
  hydraJobs.&amp;quot;&amp;lt;attr&amp;gt;&amp;quot;.&amp;quot;&amp;lt;system&amp;gt;&amp;quot; = derivation;&lt;br /&gt;
  # Used by `nix flake init -t &amp;lt;flake&amp;gt;#&amp;lt;name&amp;gt;`&lt;br /&gt;
  templates.&amp;quot;&amp;lt;name&amp;gt;&amp;quot; = {&lt;br /&gt;
    path = &amp;quot;&amp;lt;store-path&amp;gt;&amp;quot;;&lt;br /&gt;
    description = &amp;quot;template description goes here?&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
  # Used by `nix flake init -t &amp;lt;flake&amp;gt;`&lt;br /&gt;
  templates.default = { path = &amp;quot;&amp;lt;store-path&amp;gt;&amp;quot;; description = &amp;quot;&amp;quot;; };&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:48--&amp;gt;&lt;br /&gt;
You can also define additional arbitrary attributes, but these are the outputs that Nix knows about.&lt;br /&gt;
&lt;br /&gt;
== Core usage patterns == &amp;lt;!--T:208--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Making your evaluations pure === &amp;lt;!--T:60--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:61--&amp;gt;&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:62--&amp;gt;&lt;br /&gt;
* {{Nixpkgs Manual|name=fetchurl|anchor=#sec-pkgs-fetchers-fetchurl-inputs}} and {{Nixpkgs Manual|name=fetchzip|anchor=#sec-pkgs-fetchers-fetchzip-inputs}} require a &amp;lt;code&amp;gt;sha256&amp;lt;/code&amp;gt; argument to be considered pure.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:156--&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;builtins.currentSystem&amp;lt;/code&amp;gt; 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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:209--&amp;gt;&lt;br /&gt;
*  &amp;lt;code&amp;gt;builtins.getEnv&amp;lt;/code&amp;gt; is also impure. Avoid reading from environment variables and likewise, do not reference files outside of the flake&#039;s directory.&lt;br /&gt;
&lt;br /&gt;
=== Defining a flake for multiple architectures === &amp;lt;!--T:210--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:211--&amp;gt;&lt;br /&gt;
Flakes force you to specify a program for each supported architecture. An example below shows how to write a flake that targets multiple architectures.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  description = &amp;quot;A flake targeting multiple architectures&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
inputs = {&lt;br /&gt;
    nixpkgs.url = &amp;quot;github:nixos/nixpkgs?ref=nixos-unstable&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
&lt;br /&gt;
outputs = { self, nixpkgs }: let&lt;br /&gt;
    systems = [ &amp;quot;x86_64-linux&amp;quot; &amp;quot;aarch64-linux&amp;quot; ];&lt;br /&gt;
    forAllSystems = f: builtins.listToAttrs (map (system: {&lt;br /&gt;
      name = system;&lt;br /&gt;
      value = f system;&lt;br /&gt;
    }) systems);&lt;br /&gt;
  in {&lt;br /&gt;
    packages = forAllSystems (system: let&lt;br /&gt;
      pkgs = nixpkgs.legacyPackages.${system};&lt;br /&gt;
    in {&lt;br /&gt;
      hello = pkgs.hello;&lt;br /&gt;
      default = pkgs.hello;&lt;br /&gt;
    });&lt;br /&gt;
  };&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:215--&amp;gt;&lt;br /&gt;
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]]&lt;br /&gt;
&lt;br /&gt;
=== Using overlays === &amp;lt;!--T:216--&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:217--&amp;gt;&lt;br /&gt;
To use [[Overlays]] with flakes, refer to [[Overlays#In a Nix flake]] page.&lt;br /&gt;
&lt;br /&gt;
=== Enable unfree software === &amp;lt;!--T:129--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:218--&amp;gt;&lt;br /&gt;
To allow for [[Unfree software|unfree software]] in a flake project, you need to explicitly allow it by setting &amp;lt;code&amp;gt;config.allowUnree = true;&amp;lt;/code&amp;gt; when importing Nixpkgs.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  inputs.nixpkgs.url = &amp;quot;github:nixos/nixpkgs?ref=nixos-unstable&amp;quot;;&lt;br /&gt;
  outputs = { self, nixpkgs, flake-compat }:&lt;br /&gt;
    let&lt;br /&gt;
      system = &amp;quot;x86_64-linux&amp;quot;;&lt;br /&gt;
      pkgs = import nixpkgs { inherit system; config.allowUnfree = true;};&lt;br /&gt;
    in {&lt;br /&gt;
      ...&lt;br /&gt;
    };&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
== NixOS configuration with flakes == &amp;lt;!--T:220--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:221--&amp;gt;&lt;br /&gt;
It is possible to manage a [[NixOS]] system configuration using flakes, gaining the benefits of reproducible, declarative inputs and streamlined updates.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:222--&amp;gt;&lt;br /&gt;
For details and examples, see [[NixOS system configuration#Defining NixOS as a flake]].&lt;br /&gt;
&lt;br /&gt;
== Development tricks == &amp;lt;!--T:131--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Automatically switch nix shells with direnv === &amp;lt;!--T:97--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:98--&amp;gt;&lt;br /&gt;
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].&lt;br /&gt;
&lt;br /&gt;
=== Pushing Flakes to Cachix === &amp;lt;!--T:99--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
https://docs.cachix.org/pushing#flakes&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Flake support in projects without flakes === &amp;lt;!--T:50--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:51--&amp;gt;&lt;br /&gt;
The [https://github.com/edolstra/flake-compat flake-compat] library provides a compatibility layer that allows projects using traditional &amp;lt;code&amp;gt;default.nix&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;shell.nix&amp;lt;/code&amp;gt; files to operate with flakes. For more details and usage examples, see the [[Flake Compat]] page.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:223--&amp;gt;&lt;br /&gt;
Another project that allows consuming flakes from non-flake projects is [https://github.com/fricklerhandwerk/flake-inputs flake-inputs].&lt;br /&gt;
&lt;br /&gt;
=== Accessing flakes from Nix expressions === &amp;lt;!--T:58--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:59--&amp;gt;&lt;br /&gt;
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 &amp;lt;code&amp;gt;(builtins.getFlake &amp;quot;/path/to/directory&amp;quot;).packages.x86_64-linux.default&amp;lt;/code&amp;gt;, where &#039;directory&#039; is the directory that contains your &amp;lt;code&amp;gt;flake.nix&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Efficiently build multiple flake outputs === &amp;lt;!--T:224--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:101--&amp;gt;&lt;br /&gt;
To push &#039;&#039;all&#039;&#039; flake outputs automatically, checkout [https://github.com/srid/devour-flake#usage devour-flake].&lt;br /&gt;
&lt;br /&gt;
=== Build a package added in a PR === &amp;lt;!--T:161--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxHighlight&amp;gt;&lt;br /&gt;
nix build github:nixos/nixpkgs?ref=pull/&amp;lt;PR_NUMBER&amp;gt;/head#&amp;lt;PACKAGE&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:162--&amp;gt;&lt;br /&gt;
this allows building a package that has not yet been added to nixpkgs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:132--&amp;gt;&lt;br /&gt;
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:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxHighlight&amp;gt;&lt;br /&gt;
git fetch upstream pull/&amp;lt;PR_NUMBER&amp;gt;/head &amp;amp;&amp;amp; git checkout FETCH_HEAD &amp;amp;&amp;amp; nix build .#PACKAGE&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:163--&amp;gt;&lt;br /&gt;
this allows building a package that has not yet been added to nixpkgs.&lt;br /&gt;
&lt;br /&gt;
=== How to add a file locally in git but not include it in commits === &amp;lt;!--T:164--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:133--&amp;gt;&lt;br /&gt;
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 &amp;lt;code&amp;gt;extra/flake.nix&amp;lt;/code&amp;gt;):&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxHighlight&amp;gt;&lt;br /&gt;
git add --intent-to-add extra/flake.nix&lt;br /&gt;
git update-index --skip-worktree --assume-unchanged extra/flake.nix&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Rapid iteration of a direct dependency === &amp;lt;!--T:135--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:165--&amp;gt;&lt;br /&gt;
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 &amp;lt;code&amp;gt;nix develop --redirect &amp;lt;flake&amp;gt; &amp;lt;directory&amp;gt;&amp;lt;/code&amp;gt; command allows you to provide a mutable dependency to your shell as if it were built by Nix.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:136--&amp;gt;&lt;br /&gt;
Consider a situation where your executable, &amp;lt;code&amp;gt;consumexe&amp;lt;/code&amp;gt;, depends on a library, &amp;lt;code&amp;gt;libdep&amp;lt;/code&amp;gt;. You&#039;re trying to work on both at the same time, where changes to &amp;lt;code&amp;gt;libdep&amp;lt;/code&amp;gt; are reflected in real time for &amp;lt;code&amp;gt;consumexe&amp;lt;/code&amp;gt;. This workflow can be achieved like so:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxHighlight lang=bash&amp;gt;&lt;br /&gt;
cd ~/libdep-src-checkout/&lt;br /&gt;
nix develop # Or `nix-shell` if applicable.&lt;br /&gt;
export prefix=&amp;quot;./install&amp;quot; # configure nix to install it here&lt;br /&gt;
buildPhase   # build it like nix does&lt;br /&gt;
installPhase # install it like nix does&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:166--&amp;gt;&lt;br /&gt;
Now that you&#039;ve built the dependency, &amp;lt;code&amp;gt;consumexe&amp;lt;/code&amp;gt; can take it as an input. &#039;&#039;&#039;In another terminal&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxHighlight lang=bash&amp;gt;&lt;br /&gt;
cd ~/consumexe-src-checkout/&lt;br /&gt;
nix develop --redirect libdep ~/libdep-src-checkout/install&lt;br /&gt;
echo $buildInputs | tr &amp;quot; &amp;quot; &amp;quot;\n&amp;quot; | grep libdep&lt;br /&gt;
# Output should show ~/libdep-src-checkout/ so you know it worked&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:167--&amp;gt;&lt;br /&gt;
If Nix warns you that your redirected flake isn&#039;t actually used as an input to the evaluated flake, try using the &amp;lt;code&amp;gt;--inputs-from .&amp;lt;/code&amp;gt; flag. If all worked well you should be able to &amp;lt;code&amp;gt;buildPhase &amp;amp;&amp;amp; installPhase&amp;lt;/code&amp;gt; when the dependency changes and rebuild your consumer with the new version &#039;&#039;without&#039;&#039; exiting the development shell.&lt;br /&gt;
&lt;br /&gt;
== See also == &amp;lt;!--T:138--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Official sources === &amp;lt;!--T:225--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:139--&amp;gt;&lt;br /&gt;
* [https://nix.dev/concepts/flakes Flakes] - nix.dev&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:176--&amp;gt;&lt;br /&gt;
* [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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:178--&amp;gt;&lt;br /&gt;
* [https://github.com/NixOS/nix/blob/master/src/nix/flake.md spec describing flake inputs in more detail]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:168--&amp;gt;&lt;br /&gt;
* [https://github.com/NixOS/rfcs/pull/49 RFC 49] (2019) - Original flakes specification&lt;br /&gt;
&lt;br /&gt;
=== Guides === &amp;lt;!--T:226--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:169--&amp;gt;&lt;br /&gt;
* [https://jade.fyi/blog/flakes-arent-real/ Flakes aren&#039;t real and can&#039;t hurt you] (Jade Lovelace, 2024)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:170--&amp;gt;&lt;br /&gt;
* [https://github.com/ryan4yin/nixos-and-flakes-book NixOS &amp;amp; Flakes Book](Ryan4yin, 2023) - 🛠️ ❤️ An unofficial NixOS &amp;amp; Flakes book for beginners.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:171--&amp;gt;&lt;br /&gt;
* [https://xeiaso.net/blog/nix-flakes-1-2022-02-21 Nix Flakes: an Introduction] (Xe Iaso, 2022)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:172--&amp;gt;&lt;br /&gt;
* [https://serokell.io/blog/practical-nix-flakes Practical Nix Flakes] (Alexander Bantyev, 2021) - Intro article on working with Nix and Flakes&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:173--&amp;gt;&lt;br /&gt;
* [https://www.tweag.io/blog/2020-05-25-flakes/ Nix Flakes, Part 1: An introduction and tutorial] (Eelco Dolstra, 2020)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:174--&amp;gt;&lt;br /&gt;
* [https://www.tweag.io/blog/2020-06-25-eval-cache/ Nix Flakes, Part 2: Evaluation caching] (Eelco Dolstra, 2020)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:175--&amp;gt;&lt;br /&gt;
* [https://www.tweag.io/blog/2020-07-31-nixos-flakes/ Nix Flakes, Part 3: Managing NixOS systems] (Eelco Dolstra, 2020)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:177--&amp;gt;&lt;br /&gt;
* [https://www.youtube.com/watch?v=QXUlhnhuRX4&amp;amp;list=PLgknCdxP89RcGPTjngfNR9WmBgvD_xW0l Nix flakes 101: Introduction to nix flakes] (Jörg Thalheim, 2020) YouTube video&lt;br /&gt;
&lt;br /&gt;
=== Useful flake modules === &amp;lt;!--T:227--&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:179--&amp;gt;&lt;br /&gt;
* [[Flake Utils|flake-utils]]: Library to avoid some boiler-code when writing flakes&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:228--&amp;gt;&lt;br /&gt;
* [[Flake Parts|flake-parts]]: Library to help write modular and organized flakes&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:229--&amp;gt;&lt;br /&gt;
* [[Flake Compat|flake-compat]]: A compatibility layer for flakes&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:181--&amp;gt;&lt;br /&gt;
* [https://github.com/nix-community/todomvc-nix building Rust and Haskell flakes]&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{references}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:230--&amp;gt;&lt;br /&gt;
[[Category:Software|Software]]&lt;br /&gt;
[[Category:Nix|Nix]]&lt;br /&gt;
[[Category:Nix Language|Nix Language]]&lt;br /&gt;
[[Category:Flakes|Flakes]]&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=NixOS_as_a_desktop&amp;diff=29374</id>
		<title>NixOS as a desktop</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=NixOS_as_a_desktop&amp;diff=29374"/>
		<updated>2026-01-05T18:44:11Z</updated>

		<summary type="html">&lt;p&gt;Pigs: fix broken link&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;languages/&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:1--&amp;gt;&lt;br /&gt;
[[NixOS]] is a versatile operating system suitable for a wide range of use cases. This page is intended for users who wish to run NixOS as their primary desktop environment, either on physical hardware or within a virtual machine. Additionally, users planning to deploy NixOS in [[NixOS friendly hosters|cloud]] environments or on specialized server infrastructure may find it helpful to begin with the concepts and practices introduced here, as they provide a useful foundation for working within the broader [[Nix ecosystem]].&lt;br /&gt;
&lt;br /&gt;
== Installation == &amp;lt;!--T:2--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:4--&amp;gt;&lt;br /&gt;
Refer to [[NixOS Installation Guide]] to get started. Keep in mind that, for a desktop installation, you will probably want to make sure you start with at least 30 GiB of available disk space to allow for the [[:Category:Desktop environment|desktop environments]], [[:Category:Web Browser|web browsers]], and other [[:Category:Applications|graphical applications]], that would be typical of daily use. 15 GiB might be enough for a fairly bare-bones setup.&lt;br /&gt;
&lt;br /&gt;
== Managing your configuration == &amp;lt;!--T:7--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:8--&amp;gt;&lt;br /&gt;
As described in the [[Overview of the NixOS Linux distribution#Declarative Configuration]], NixOS is designed to be configured declaratively. This means the entire system configuration, including installed packages, system services, kernel parameters, and user accounts is defined in configuration files, typically in &amp;lt;code&amp;gt;/etc/nixos/configuration.nix&amp;lt;/code&amp;gt;. These settings can then be applied consistently and reproducibly across machines.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:28--&amp;gt;&lt;br /&gt;
The process for managing your configuration is documented in the {{NixOS Manual|name=NixOS official manual|anchor=#ch-configuration}}.&lt;br /&gt;
&lt;br /&gt;
=== System Configuration === &amp;lt;!--T:29--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:30--&amp;gt;&lt;br /&gt;
{{main|NixOS system configuration}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:31--&amp;gt;&lt;br /&gt;
The primary configuration file, &amp;lt;code&amp;gt;/etc/nixos/configuration.nix&amp;lt;/code&amp;gt;, defines system-wide settings. This includes options like enabling services, managing system users, setting hardware options, and specifying installed packages. Changes are applied with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:32--&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
# nixos-rebuild switch&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== User configuration with Home Manager === &amp;lt;!--T:33--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:34--&amp;gt;&lt;br /&gt;
For managing per-user configurations such as application preferences, command-line tools, and dotfiles, [[Home Manager]] provides a convenient, declarative approach. It allows users to define which programs should be installed and how they should be configured, without needing to include those settings in the system-wide [https://nixos.org/manual/nixos/stable/#sec-changing-config configuration.nix].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:35--&amp;gt;&lt;br /&gt;
Home Manager can be used independently of the system configuration and works with both traditional setups and newer [[Flakes]]-based configurations.&lt;br /&gt;
&lt;br /&gt;
=== With Flakes === &amp;lt;!--T:17--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:18--&amp;gt;&lt;br /&gt;
For users looking for a more streamlined and reproducible way to manage NixOS configurations, the [[Flakes]] feature has been gaining popularity within the community. While Flakes introduce some new concepts compared to traditional workflows, many users find them a convenient and organized approach to managing system and development configurations.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:36--&amp;gt;&lt;br /&gt;
Refer to [[NixOS system configuration#Defining NixOS as a flake]] for details on getting started.&lt;br /&gt;
&lt;br /&gt;
== Beyond initial setup == &amp;lt;!--T:21--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:22--&amp;gt;&lt;br /&gt;
Once your basic NixOS installation is complete and functional, you can further customize your system with a variety of optional configurations tailored for desktop use. For a list of recommended initial system configurations, see [[NixOS Installation Guide#NixOS configuration]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:37--&amp;gt;&lt;br /&gt;
Common configuration areas include:&lt;br /&gt;
&lt;br /&gt;
==== Desktop Environments ==== &amp;lt;!--T:38--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:39--&amp;gt;&lt;br /&gt;
Install and configure full-featured environments such as [[GNOME]], [[KDE Plasma]], or [[Xfce]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:40--&amp;gt;&lt;br /&gt;
See [[:Category:Desktop environment]] for a full list.&lt;br /&gt;
&lt;br /&gt;
==== Window Managers ==== &amp;lt;!--T:41--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:42--&amp;gt;&lt;br /&gt;
Set up lightweight or tiling window managers like [[i3]], [[Sway]], [[Hyprland]], or [[XMonad]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:43--&amp;gt;&lt;br /&gt;
See [[:Category:Window managers]] for a full list.&lt;br /&gt;
&lt;br /&gt;
==== Display Managers (Login Managers) ==== &amp;lt;!--T:44--&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:45--&amp;gt;&lt;br /&gt;
Configure graphical session managers such as [[Gnome|GDM]], [[KDE|SDDM]], or [[LightDM]].&lt;br /&gt;
&lt;br /&gt;
==== Audio Setup ==== &amp;lt;!--T:46--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:47--&amp;gt;&lt;br /&gt;
Enable and configure [[:Category:Audio|audio]] systems like [[PipeWire]], [[PulseAudio]], or [[ALSA]].&lt;br /&gt;
&lt;br /&gt;
==== Network Management ==== &amp;lt;!--T:48--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:49--&amp;gt;&lt;br /&gt;
Use tools such as [[NetworkManager]] or [[systemd-networkd]] for managing [[Networking|network]] connections.&lt;br /&gt;
&lt;br /&gt;
==== Bluetooth Support ==== &amp;lt;!--T:50--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:51--&amp;gt;&lt;br /&gt;
Set up [[Bluetooth]] with blueman or other management tools.&lt;br /&gt;
&lt;br /&gt;
==== Power Management ==== &amp;lt;!--T:52--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:53--&amp;gt;&lt;br /&gt;
Configure [[laptop]] [[Power Management|battery management]], suspend, and hibernation with tools like [[Laptop#tlp|tlp]] or [[systemd]] services.&lt;br /&gt;
&lt;br /&gt;
==== Printing and Scanning ==== &amp;lt;!--T:54--&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:55--&amp;gt;&lt;br /&gt;
Enable [[Cups]] for printer support and tools like Sane for [[Scanners|scanning]] devices.&lt;br /&gt;
&lt;br /&gt;
== Tips and tricks == &amp;lt;!--T:12--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Modularizing your configuration with modules === &amp;lt;!--T:13--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:56--&amp;gt;&lt;br /&gt;
{{main|NixOS system configuration#Modularizing your configuration with modules}}&lt;br /&gt;
&lt;br /&gt;
== See also == &amp;lt;!--T:23--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:25--&amp;gt;&lt;br /&gt;
* [[Overview of the NixOS Linux distribution]]&lt;br /&gt;
* [[Comparison of NixOS setups]] for a table comparing some popular choices.&lt;br /&gt;
* [[Configuration Collection]] for a long list within the wiki.&lt;br /&gt;
* [https://github.com/topics/nix-flake nix-flake], [https://github.com/topics/nixos-configuration nixos-configuration], [https://github.com/topics/nixos-dotfiles nixos-dotfiles] Github topics&lt;br /&gt;
* [[Wil T Nix Guides]] Youtube video format guide&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:57--&amp;gt;&lt;br /&gt;
[[Category:Desktop]]&lt;br /&gt;
[[Category:Guide]]&lt;br /&gt;
[[Category:NixOS]]&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=Sway&amp;diff=29373</id>
		<title>Sway</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=Sway&amp;diff=29373"/>
		<updated>2026-01-05T18:31:44Z</updated>

		<summary type="html">&lt;p&gt;Pigs: add crosslinking in opening header&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[https://swaywm.org/ Sway] is a tiling [[Wayland]] compositor and a drop-in replacement for the [[i3]] window manager for X11. It can work with an existing i3 configuration and supports most of i3&#039;s features, plus a few extras. For users migrating from i3, see the [https://github.com/swaywm/sway/wiki/i3-Migration-Guide i3 migration guide].&lt;br /&gt;
&lt;br /&gt;
== Setup ==&lt;br /&gt;
You can install Sway by enabling it in NixOS directly, or by using [[Home Manager]], or both.&lt;br /&gt;
&lt;br /&gt;
=== Using NixOS ===&lt;br /&gt;
Here is a minimal configuration:&lt;br /&gt;
&lt;br /&gt;
{{File|3={ config, pkgs, lib, ... }:&lt;br /&gt;
{&lt;br /&gt;
  environment.systemPackages = with pkgs; [&lt;br /&gt;
    grim # screenshot functionality&lt;br /&gt;
    slurp # screenshot functionality&lt;br /&gt;
    wl-clipboard # wl-copy and wl-paste for copy/paste from stdin / stdout&lt;br /&gt;
    mako # notification system developed by swaywm maintainer&lt;br /&gt;
  ];&lt;br /&gt;
&lt;br /&gt;
  # Enable the gnome-keyring secrets vault. &lt;br /&gt;
  # Will be exposed through DBus to programs willing to store secrets.&lt;br /&gt;
  services.gnome.gnome-keyring.enable = true;&lt;br /&gt;
&lt;br /&gt;
  # enable Sway window manager&lt;br /&gt;
  programs.sway = {&lt;br /&gt;
    enable = true;&lt;br /&gt;
    wrapperFeatures.gtk = true;&lt;br /&gt;
  };&lt;br /&gt;
}|name=/etc/nixos/configuration.nix|lang=nix}}&lt;br /&gt;
&lt;br /&gt;
By default, the Sway module in NixOS comes with a set of extra packages, including [https://codeberg.org/dnkl/foot/ Foot] terminal, [[Swayidle]], [[Swaylock]], and [https://codeberg.org/adnano/wmenu/ wmenu], which may be configured under the &amp;lt;code&amp;gt;[https://search.nixos.org/options?show=programs.sway.extraPackages programs.sway.extraPackages]&amp;lt;/code&amp;gt; option. You may also want to include &amp;lt;code&amp;gt;wl-clipboard&amp;lt;/code&amp;gt; for clipboard functionality, as well as a screenshot utility such as [https://github.com/emersion/slurp Slurp] or [[Flameshot]] for screenshot region selection. &lt;br /&gt;
&lt;br /&gt;
Additionally, for a more customizable bar implementation than &amp;lt;code&amp;gt;sway-bar&amp;lt;/code&amp;gt;, [[Waybar]] may be enabled with &amp;lt;code&amp;gt;programs.waybar.enable&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The default Sway configuration is symlinked to &amp;lt;code&amp;gt;/etc/sway/config&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;/etc/sway/config.d/nixos.conf&amp;lt;/code&amp;gt;. The latter file contains dbus and systemd configuration that is critical to using apps that depend on XDG desktop portals with Sway, and should be included in any custom configuration files.&lt;br /&gt;
&lt;br /&gt;
A few general comments:&lt;br /&gt;
* There is some friction between GTK theming and Sway. Currently the Sway developers suggest using gsettings to set gtk theme attributes as described here [https://github.com/swaywm/sway/wiki/GTK-3-settings-on-Wayland]. There is currently a plan to allow GTK theme attributes to be set directly in the Sway config.&lt;br /&gt;
* Running Sway as a systemd user service is not recommended [https://github.com/swaywm/sway/wiki/Systemd-integration#running-sway-itself-as-a---user-service] [https://github.com/swaywm/sway/issues/5160]&lt;br /&gt;
&lt;br /&gt;
=== Using Home Manager ===&lt;br /&gt;
To set up Sway using [[Home Manager]], you must first enable [[Polkit]] in your NixOS configuration.&lt;br /&gt;
{{file|/etc/nixos/configuration.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
security.polkit.enable = true;&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
 &lt;br /&gt;
Then you may enable Sway in your Home Manager configuration. Here is a minimal example:&lt;br /&gt;
&lt;br /&gt;
{{File|3=wayland.windowManager.sway = {&lt;br /&gt;
    enable = true;&lt;br /&gt;
    wrapperFeatures.gtk = true; # Fixes common issues with GTK 3 apps&lt;br /&gt;
    config = rec {&lt;br /&gt;
      modifier = &amp;quot;Mod4&amp;quot;;&lt;br /&gt;
      # Use kitty as default terminal&lt;br /&gt;
      terminal = &amp;quot;kitty&amp;quot;; &lt;br /&gt;
      startup = [&lt;br /&gt;
        # Launch Firefox on start&lt;br /&gt;
        {command = &amp;quot;firefox&amp;quot;;}&lt;br /&gt;
      ];&lt;br /&gt;
    };&lt;br /&gt;
  };|name=/etc/nixos/home.nix|lang=nix}}&lt;br /&gt;
&lt;br /&gt;
See [https://nix-community.github.io/home-manager/options.xhtml#opt-wayland.windowManager.sway.enable Home Manager&#039;s Options for Sway] for a complete list of configuration options.&lt;br /&gt;
&lt;br /&gt;
You may need to activate dbus manually from .zshrc to use i.e: dunst, see [https://discourse.nixos.org/t/dunst-crashes-if-run-as-service/27671/2 Dunst crashes if run as service]&lt;br /&gt;
&lt;br /&gt;
{{Note|&lt;br /&gt;
It&#039;s recommended to enable a [[Secret Service]] provider, like GNOME Keyring:&lt;br /&gt;
{{file|home.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
services.gnome-keyring.enable = true;&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Systemd services ===&lt;br /&gt;
Kanshi is an output configuration daemon. As explained above, we don&#039;t run Sway itself as a systemd service. There are auxiliary daemons that we do want to run as systemd services, for example Kanshi [https://gitlab.freedesktop.org/emersion/kanshi], which implements monitor hot swapping. It would be enabled as follows:&lt;br /&gt;
{{file|/etc/nixos/configuration.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
  # kanshi systemd service&lt;br /&gt;
  systemd.user.services.kanshi = {&lt;br /&gt;
    description = &amp;quot;kanshi daemon&amp;quot;;&lt;br /&gt;
    environment = {&lt;br /&gt;
      WAYLAND_DISPLAY=&amp;quot;wayland-1&amp;quot;;&lt;br /&gt;
      DISPLAY = &amp;quot;:0&amp;quot;;&lt;br /&gt;
    }; &lt;br /&gt;
    serviceConfig = {&lt;br /&gt;
      Type = &amp;quot;simple&amp;quot;;&lt;br /&gt;
      ExecStart = &#039;&#039;${pkgs.kanshi}/bin/kanshi -c kanshi_config_file&#039;&#039;;&lt;br /&gt;
    };&lt;br /&gt;
  };&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
{{file|sway config|bash|&lt;br /&gt;
# give Sway a little time to startup before starting kanshi.&lt;br /&gt;
exec sleep 5; systemctl --user start kanshi.service&lt;br /&gt;
}}&lt;br /&gt;
When you launch Sway, the systemd service is started. &lt;br /&gt;
&lt;br /&gt;
=== Using a greeter ===&lt;br /&gt;
Installing a greeter based on [[greetd]] is the most straightforward way to launch Sway.&lt;br /&gt;
&lt;br /&gt;
==== TUIGreet ====&lt;br /&gt;
Tuigreet is a simple and lightweight option that does not require a separate compositor to launch.&lt;br /&gt;
&lt;br /&gt;
{{file|||&amp;lt;nowiki&amp;gt;&lt;br /&gt;
services.greetd = {                                                      &lt;br /&gt;
  enable = true;                                                         &lt;br /&gt;
  settings = {                                                           &lt;br /&gt;
    default_session = {                                                  &lt;br /&gt;
      command = &amp;quot;${pkgs.tuigreet}/bin/tuigreet --time --cmd sway&amp;quot;;&lt;br /&gt;
      user = &amp;quot;greeter&amp;quot;;                                                  &lt;br /&gt;
    };                                                                   &lt;br /&gt;
  };                                                                     &lt;br /&gt;
};                                                                       &lt;br /&gt;
&amp;lt;/nowiki&amp;gt;|name=/etc/nixos/configuration.nix|lang=nix}}&lt;br /&gt;
&lt;br /&gt;
==== Regreet ====&lt;br /&gt;
[https://github.com/rharish101/ReGreet Regreet] is a clean and customizable GTK-based greeter written in Rust. It will automatically find Sway and remembers the last picked option. Additional configuration options may be found under [https://search.nixos.org/options?&amp;amp;query=regreet programs.regreet].&lt;br /&gt;
{{File|3=programs.regreet.enable = true;|name=/etc/nixos/configuration.nix|lang=nix}}&lt;br /&gt;
&lt;br /&gt;
=== Automatic startup on boot ===&lt;br /&gt;
The snippet below will start Sway immediately on startup, without a greeter and &#039;&#039;&#039;without a login prompt&#039;&#039;&#039;. Only consider using this in conjunction with [[Full Disk Encryption]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
services.getty = {&lt;br /&gt;
  autologinUser = &amp;quot;your_username&amp;quot;;&lt;br /&gt;
  autologinOnce = true;&lt;br /&gt;
};&lt;br /&gt;
environment.loginShellInit = &#039;&#039;&lt;br /&gt;
    [[ &amp;quot;$(tty)&amp;quot; == /dev/tty1 ]] &amp;amp;&amp;amp; sway&lt;br /&gt;
&#039;&#039;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;When launched directly from the TTY, Sway will not inherit the user environment. This may cause issues with systemd user services such as application launchers or [[Swayidle]]. To fix this, add the following to your Home Manager configuration:{{file|home.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
 wayland.windowManager.sway.systemd.variables = [&amp;quot;--all&amp;quot;];&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
== Configuration ==&lt;br /&gt;
Sway may be configured for specific users using Home Manager or manually through configuration files. The default location is &amp;lt;code&amp;gt;/etc/sway/config&amp;lt;/code&amp;gt;, and custom user configuration in &amp;lt;code&amp;gt;~/.config/sway/config&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Keyboard layout ===&lt;br /&gt;
Changing layout for all keyboards to German (de):&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
input * xkb_layout &amp;quot;de&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;The same thing accomplished in Home Manager:&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
wayland.windowManager.sway.input.&amp;quot;*&amp;quot;.xkb_layout = &amp;quot;de&amp;quot;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== High-DPI scaling ===&lt;br /&gt;
Changing scale for all screens to factor 1.5:&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
output * scale 1.5&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Brightness and volume ===&lt;br /&gt;
You may set the brightness and volume function keys by binding the key codes to their corresponding commands within your sway config. The following configurations accomplish this using &amp;lt;code&amp;gt;light&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pulseaudio&amp;lt;/code&amp;gt;:&lt;br /&gt;
{{file|/etc/nixos/configuration.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
users.users.yourusername.extraGroups = [ &amp;quot;video&amp;quot; ];&lt;br /&gt;
programs.light.enable = true;&lt;br /&gt;
environment.systemPackages = [ pkgs.pulseaudio ];&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
{{file|||&lt;br /&gt;
&lt;br /&gt;
# Brightness&lt;br /&gt;
bindsym XF86MonBrightnessDown exec light -U 10&lt;br /&gt;
bindsym XF86MonBrightnessUp exec light -A 10&lt;br /&gt;
&lt;br /&gt;
# Volume&lt;br /&gt;
bindsym XF86AudioRaiseVolume exec &#039;pactl set-sink-volume @DEFAULT_SINK@ +1%&#039;&lt;br /&gt;
bindsym XF86AudioLowerVolume exec &#039;pactl set-sink-volume @DEFAULT_SINK@ -1%&#039;&lt;br /&gt;
bindsym XF86AudioMute exec &#039;pactl set-sink-mute @DEFAULT_SINK@ toggle&#039;&lt;br /&gt;
|name=Sway Config|lang=bash}}Or alternatively in Home Manager:&lt;br /&gt;
{{File|3=wayland.windowManager.sway = {&lt;br /&gt;
  enable = true;&lt;br /&gt;
  config = {&lt;br /&gt;
    keybindings = {&lt;br /&gt;
      # Brightness Controls&lt;br /&gt;
      &amp;quot;XF86MonBrightnessDown&amp;quot; = &amp;quot;exec light -U 10&amp;quot;;&lt;br /&gt;
      &amp;quot;XF86MonBrightnessUp&amp;quot; = &amp;quot;exec light -A 10&amp;quot;;&lt;br /&gt;
        &lt;br /&gt;
      # Volume Controls&lt;br /&gt;
      &amp;quot;XF86AudioRaiseVolume&amp;quot; = &amp;quot;exec pactl set-sink-volume @DEFAULT_SINK@ +1%&amp;quot;;&lt;br /&gt;
      &amp;quot;XF86AudioLowerVolume&amp;quot; = &amp;quot;exec pactl set-sink-volume @DEFAULT_SINK@ -1%&amp;quot;;&lt;br /&gt;
      &amp;quot;XF86AudioMute&amp;quot; = &amp;quot;exec pactl set-sink-mute @DEFAULT_SINK@ toggle&amp;quot;;&lt;br /&gt;
    };&lt;br /&gt;
  };&lt;br /&gt;
};|name=/etc/nixos/home.nix|lang=nix}}For an on screen display for audio and brightness, check [[swayosd]].&lt;br /&gt;
&lt;br /&gt;
=== Touchpad ===&lt;br /&gt;
See the [https://www.mankier.com/5/sway-input sway-input man page] for options.&lt;br /&gt;
{{File|3=wayland.windowManager.sway = &lt;br /&gt;
  {&lt;br /&gt;
    enable = true;&lt;br /&gt;
    config.input = {&lt;br /&gt;
      &amp;quot;type:touchpad&amp;quot; = {&lt;br /&gt;
        # Enables or disables tap for specified input device.&lt;br /&gt;
        tap = &amp;quot;enabled&amp;quot;;&lt;br /&gt;
        # Enables or disables natural (inverted) scrolling for the specified input device.&lt;br /&gt;
        natural_scroll = &amp;quot;enabled&amp;quot;;&lt;br /&gt;
        # Enables or disables disable-while-typing for the specified input device.&lt;br /&gt;
        dwt = &amp;quot;enabled&amp;quot;;&lt;br /&gt;
      };&lt;br /&gt;
    };&lt;br /&gt;
  };|name=/etc/nixos/home.nix|lang=nix}}&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
=== Cursor is missing icons or too tiny on HiDPI displays ===&lt;br /&gt;
&lt;br /&gt;
==== With programs.sway ====&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  programs.sway.extraPackages = with pkgs; [&lt;br /&gt;
    adwaita-icon-theme # mouse cursor and icons&lt;br /&gt;
    gnome-themes-extra # dark adwaita theme&lt;br /&gt;
    ...&lt;br /&gt;
  ];&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In ~/.config/sway/config&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;seat &amp;quot;*&amp;quot; xcursor_theme Adwaita 32&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== With Home Manager ====&lt;br /&gt;
&lt;br /&gt;
Using [[Home Manager]] you may configure the mouse cursor size and theme. The reason that your cursor might be missing in some applications, is because &amp;lt;code&amp;gt;XCURSOR_THEME&amp;lt;/code&amp;gt; is missing, which will cause applications relying on &amp;lt;code&amp;gt;XWAYLAND&amp;lt;/code&amp;gt; to misbehave. Setting &amp;lt;code&amp;gt;sway.enable = true&amp;lt;/code&amp;gt;, combined with the &amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;package&amp;lt;/code&amp;gt; and size will set the correct environment variables, which sway will then use.&lt;br /&gt;
&lt;br /&gt;
{{File|3=home.pointerCursor = {&lt;br /&gt;
    name = &amp;quot;Adwaita&amp;quot;;&lt;br /&gt;
    package = pkgs.adwaita-icon-theme;&lt;br /&gt;
    size = 24;&lt;br /&gt;
    x11 = {&lt;br /&gt;
      enable = true;&lt;br /&gt;
      defaultCursor = &amp;quot;Adwaita&amp;quot;;&lt;br /&gt;
    };&lt;br /&gt;
&lt;br /&gt;
  sway.enable = true;&lt;br /&gt;
&lt;br /&gt;
};|name=/etc/nixos/home.nix|lang=nix}}&lt;br /&gt;
&lt;br /&gt;
=== Missing fonts in Xorg applications ===&lt;br /&gt;
&lt;br /&gt;
If fonts for certain languages are missing in Xorg applications (e.g. Japanese fonts don&#039;t appear in Discord)  even though they&#039;re in the system, you can set them as default fonts in your configuration file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  fonts = {&lt;br /&gt;
    packages = with pkgs; [&lt;br /&gt;
      noto-fonts&lt;br /&gt;
      noto-fonts-cjk&lt;br /&gt;
      noto-fonts-emoji&lt;br /&gt;
      font-awesome&lt;br /&gt;
      source-han-sans&lt;br /&gt;
      source-han-sans-japanese&lt;br /&gt;
      source-han-serif-japanese&lt;br /&gt;
    ];&lt;br /&gt;
    fontconfig.defaultFonts = {&lt;br /&gt;
      serif = [ &amp;quot;Noto Serif&amp;quot; &amp;quot;Source Han Serif&amp;quot; ];&lt;br /&gt;
      sansSerif = [ &amp;quot;Noto Sans&amp;quot; &amp;quot;Source Han Sans&amp;quot; ];&lt;br /&gt;
    };&lt;br /&gt;
  };&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Swaylock cannot be unlocked with the correct password ===&lt;br /&gt;
&lt;br /&gt;
Add the following to your NixOS configuration.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;gt;&lt;br /&gt;
  security.pam.services.swaylock = {};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;programs.sway.enable&amp;lt;/code&amp;gt; option does this automatically.&lt;br /&gt;
&lt;br /&gt;
=== Inferior performance compared to other distributions ===&lt;br /&gt;
&lt;br /&gt;
Enabling realtime may improve latency and reduce stuttering, specially in high load scenarios.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
security.pam.loginLimits = [&lt;br /&gt;
  { domain = &amp;quot;@users&amp;quot;; item = &amp;quot;rtprio&amp;quot;; type = &amp;quot;-&amp;quot;; value = 1; }&lt;br /&gt;
];&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Enabling this option allows any program run by the &amp;quot;users&amp;quot; group to request real-time priority.&lt;br /&gt;
&lt;br /&gt;
=== WLR Error when trying to launch Sway ===&lt;br /&gt;
&lt;br /&gt;
When this happens on a new NixOS system, enabling OpenGL in configuration.nix may fix this issue.  &lt;br /&gt;
&lt;br /&gt;
{{Note|&amp;lt;code&amp;gt;hardware.opengl&amp;lt;/code&amp;gt; was renamed to &amp;lt;code&amp;gt;hardware.graphics&amp;lt;/code&amp;gt; in NixOS 24.11.}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
hardware.graphics.enable = true;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Systemd user services missing environment variables (PATH, etc) ===&lt;br /&gt;
When sway is launched with out display manager systemd won&#039;t inherit the users environment variables. To fix this add the following to your home-manager configuration:&lt;br /&gt;
{{File|3=wayland.windowManager.sway.systemd.variables = [&amp;quot;--all&amp;quot;];|name=home.nix|lang=nix}}&lt;br /&gt;
&lt;br /&gt;
=== Touchscreen input bound to the wrong monitor in multi-monitor setups ===&lt;br /&gt;
&lt;br /&gt;
See this [https://github.com/swaywm/sway/issues/6590#issue-1021207180 GitHub issue for Sway] and the solution give in [https://github.com/swaywm/sway/issues/6590#issuecomment-938724355 this response].&lt;br /&gt;
&lt;br /&gt;
Using [[Home Manager]] add the following to your Sway configuration:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
   wayland.windowManager.sway = {&lt;br /&gt;
     [...]&lt;br /&gt;
     config = {&lt;br /&gt;
       [...]&lt;br /&gt;
       input = {&lt;br /&gt;
         [...]&lt;br /&gt;
         &amp;quot;type:touch&amp;quot; = {&lt;br /&gt;
           # Replace touchscreen_output_identifier with the identifier of your touchscreen.&lt;br /&gt;
           map_to_output = touchscreen_output_identifier;&lt;br /&gt;
         };&lt;br /&gt;
       };&lt;br /&gt;
     };&lt;br /&gt;
   };&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GTK apps take an exceptionally long time to start ===&lt;br /&gt;
This occurs because GTK apps make blocking calls to freedesktop portals to be displayed. If Sway is not integrated with dbus and systemd, it will not be able to communicate via the &amp;lt;code&amp;gt;org.freedesktop.portal.Desktop&amp;lt;/code&amp;gt; portal. To fix this, see the [[Sway#Using NixOS|description]] of default Sway configurations earlier. Adding the following to your sway configuration, if it is not already present, may resolve the issue:&lt;br /&gt;
 include /etc/sway/config.d/*&lt;br /&gt;
&lt;br /&gt;
===dbus-issues: no icons in tray, can&#039;t open files from Nautilus with the right program===&lt;br /&gt;
&lt;br /&gt;
If you&#039;re using Gnome-Apps like Nautilus on NixOS with Sway, you might run into issue with settings standard applications to open files from Nautilus (e.g. there being no way of linking PDF to your preferred PDF-reader). You might  also experience tray icons not showing up in your bar.&lt;br /&gt;
&lt;br /&gt;
This is fixed by running &amp;lt;code&amp;gt;dbus-update-activation-environment --all&amp;lt;/code&amp;gt; after starting your session. Make it permanent by adding &amp;lt;code&amp;gt;exec dbus-update-activation-environment --all&amp;lt;/code&amp;gt; to your sway config file.&lt;br /&gt;
&lt;br /&gt;
== Tips and tricks ==&lt;br /&gt;
&lt;br /&gt;
=== Toggle monitor modes script ===&lt;br /&gt;
Following script toggles screen / monitor modes if executed. It can also be mapped to a specific key in Sway.&lt;br /&gt;
&lt;br /&gt;
First add the Flake input required for the script&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  inputs = {&lt;br /&gt;
    [...]&lt;br /&gt;
    wl-togglescreens.url = &amp;quot;git+https://git.project-insanity.org/onny/wl-togglescreens.git?ref=main&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
&lt;br /&gt;
  outputs = {self, nixpkgs, ...}@inputs: {&lt;br /&gt;
    nixosConfigurations.myhost = inputs.nixpkgs.lib.nixosSystem {&lt;br /&gt;
      system = &amp;quot;x86_64-linux&amp;quot;;&lt;br /&gt;
      specialArgs.inputs = inputs;&lt;br /&gt;
      [...]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;Map the script binary to a specific key&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
{ config, pkgs, lib, inputs, ... }:{&lt;br /&gt;
  home-manager.users.onny = {&lt;br /&gt;
    programs = {&lt;br /&gt;
      [...]&lt;br /&gt;
      wayland.windowManager.sway = {&lt;br /&gt;
        enable = true;&lt;br /&gt;
        config = {&lt;br /&gt;
          [...]&lt;br /&gt;
          keybindings = lib.mkOptionDefault{&lt;br /&gt;
            [...]&lt;br /&gt;
            &amp;quot;XF86Display&amp;quot; = &amp;quot;exec ${inputs.wl-togglescreens.packages.x86_64-linux.wl-togglescreens}/bin/wl-togglescreens&amp;quot;;&lt;br /&gt;
          };&lt;br /&gt;
        };&lt;br /&gt;
      };&lt;br /&gt;
    };&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Screen sharing ===&lt;br /&gt;
{{File|3={ pkgs, ... }:&lt;br /&gt;
{&lt;br /&gt;
  # xdg portal + pipewire = screensharing&lt;br /&gt;
  xdg.portal = {&lt;br /&gt;
    enable = true;&lt;br /&gt;
    wlr.enable = true;&lt;br /&gt;
  };&lt;br /&gt;
  services.pipewire = {&lt;br /&gt;
    enable = true;&lt;br /&gt;
    alsa.enable = true;&lt;br /&gt;
    pulse.enable = true;&lt;br /&gt;
  };&lt;br /&gt;
}|name=/etc/nixos/configuration.nix|lang=nix}}{{Tip|Make sure that you do not have conflicting definitions for xdg.portal in Home Manager.}}&lt;br /&gt;
&lt;br /&gt;
=== Auto mounting USB storage devices (e.g. Flash Drives) ===&lt;br /&gt;
You can use [https://github.com/coldfix/udiskie udiskie] to automatically mount external storage medias.&lt;br /&gt;
&lt;br /&gt;
You will need to install and enable [https://www.freedesktop.org/wiki/Software/udisks/ udisks2].&lt;br /&gt;
{{File|3=services.udisks2.enable = true;|name=/etc/nixos/configuration.nix|lang=nix}}&lt;br /&gt;
Then, in Home Manager you can enable udiskie.&lt;br /&gt;
{{File|3=services.udiskie.enable = true;|name=/etc/nixos/home.nix|lang=nix}}&lt;br /&gt;
Udiskie will automatically mount attached USB storage media.&lt;br /&gt;
&lt;br /&gt;
See related info on [[USB storage devices]].&lt;br /&gt;
&lt;br /&gt;
=== Screen dimming with wl-gammarelay-rs ===&lt;br /&gt;
Add &amp;lt;code&amp;gt;wl-gammarelay-rs&amp;lt;/code&amp;gt; to programs.sway.extraPackages, then add the following to sway config:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# start daemon&lt;br /&gt;
exec wl-gammarelay-rs&lt;br /&gt;
&lt;br /&gt;
# bind shortcut to reset brightness&lt;br /&gt;
bindsym $mod+Control+0 exec busctl --user set-property rs.wl-gammarelay / rs.wl.gammarelay Brightness d 1&lt;br /&gt;
&lt;br /&gt;
# bind shortcut to dim screen for a particular output&lt;br /&gt;
bindsym $mod+Control+Underscore exec busctl --user set-property rs.wl-gammarelay /outputs/DP_1 rs.wl.gammarelay Brightness d 0.5&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Inhibit swayidle/suspend when fullscreen ===&lt;br /&gt;
Add to sway config:&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
# When you use `for_window` the command you give is not executed&lt;br /&gt;
# immediately. It is stored in a list and the command is executed&lt;br /&gt;
# every time a window opens or changes (eg. title) in a way that&lt;br /&gt;
# matches the criteria.&lt;br /&gt;
&lt;br /&gt;
# inhibit idle for fullscreen apps&lt;br /&gt;
for_window [app_id=&amp;quot;^.*&amp;quot;] inhibit_idle fullscreen&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
[[Category:Window managers]]&lt;br /&gt;
[[Category:Applications]]&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=NTFS&amp;diff=29336</id>
		<title>NTFS</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=NTFS&amp;diff=29336"/>
		<updated>2026-01-02T04:03:57Z</updated>

		<summary type="html">&lt;p&gt;Pigs: /* Troubleshooting */ adds section on dirty flag&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;New Technology File System (NTFS) is a proprietary journaling [[Filesystems|file system]] developed by Microsoft. It is still in use by modern Windows systems, although NTFS has not evolved since the release of version 3.1 in 2001.&lt;br /&gt;
&lt;br /&gt;
== Mount NTFS filesystem on boot ==&lt;br /&gt;
&lt;br /&gt;
Using [[nixos-generate-config]] to automatically generate Nix config is the recommended way to setup filesystems.&lt;br /&gt;
&lt;br /&gt;
1. Run {{ic|lsblk}} to list device names.&lt;br /&gt;
{{code|&lt;br /&gt;
sd...&lt;br /&gt;
└─sdX&lt;br /&gt;
}}&lt;br /&gt;
2. Mount the device using [https://man7.org/linux/man-pages/man8/mount.8.html {{ic|mount}}], where {{ic|/dev/sdX}} replaced with your device name and {{ic|/mnt/sdX}} replaced with an existing folder path to mount your drive.&lt;br /&gt;
{{code|&amp;lt;nowiki&amp;gt;mount /dev/sdX /mnt/sdX -t ntfs3 -o uid=$UID&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
3. Run {{ic|nixos-generate-config --dir .}} to generate hardware configuration. This will &amp;lt;strong&amp;gt;automatically&amp;lt;/strong&amp;gt; add all currently mounted devices to {{ic|hardware-configuration.nix}}.&lt;br /&gt;
{{file|/etc/nixos/hardware-configuration.nix|diff|3=&lt;br /&gt;
+  boot.supportedFilesystems = [ &amp;quot;ntfs&amp;quot; ];&lt;br /&gt;
+  fileSystems.&amp;quot;/mnt/sdX&amp;quot; = {&lt;br /&gt;
+    device = &amp;quot;/dev/disk/by-uuid/F258FB9E58FB5FB1&amp;quot;;&lt;br /&gt;
+    fsType = &amp;quot;ntfs3&amp;quot;;&lt;br /&gt;
+  };&lt;br /&gt;
}}&lt;br /&gt;
4. Add {{ic|&amp;lt;nowiki&amp;gt;&amp;quot;uid=$UID&amp;quot;&amp;lt;/nowiki&amp;gt;}} to {{nixos:option|fileSystems.*.options|fileSystems.&amp;lt;name&amp;gt;.options}} to get write access, where {{ic|&amp;lt;nowiki&amp;gt;$UID&amp;lt;/nowiki&amp;gt;}} &amp;lt;strong&amp;gt;replaced with your UID&amp;lt;/strong&amp;gt;:&lt;br /&gt;
{{file|/etc/nixos/configuration.nix|nix|3=&lt;br /&gt;
fileSystems =&lt;br /&gt;
  let&lt;br /&gt;
    ntfs-drives = [&lt;br /&gt;
      &amp;quot;/mnt/sdX&amp;quot;&lt;br /&gt;
    ];&lt;br /&gt;
  in&lt;br /&gt;
  lib.genAttrs ntfs-drives (path: {&lt;br /&gt;
    options = [&lt;br /&gt;
      &amp;quot;uid=$UID&amp;quot; # REPLACE &amp;quot;$UID&amp;quot; WITH YOUR ACTUAL UID!&lt;br /&gt;
      # &amp;quot;nofail&amp;quot;&lt;br /&gt;
    ];&lt;br /&gt;
  });&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{note|You may find your UID by running {{ic|echo $UID}}.}}&lt;br /&gt;
{{aside|It is not recommended to manually edit {{ic|hardware-configuration.nix}}.}}&lt;br /&gt;
5. {{evaluate}}&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
=== Read-only file system ===&lt;br /&gt;
&lt;br /&gt;
This is most likely caused by Windows not marking the disk as &amp;quot;clean&amp;quot; and unmounted.&lt;br /&gt;
&lt;br /&gt;
To verify:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
journalctl -b0 | grep -i &amp;quot;The disk contains an unclean file system&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It should return a similar message to what follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
The disk contains an unclean file system (0,0). Metadata&lt;br /&gt;
kept in Windows cache, refused to mount. Falling back to&lt;br /&gt;
read-only mount because the NTFS partition is in an unsafe&lt;br /&gt;
state. Please resume and shutdown Windows fully (no&lt;br /&gt;
hibernation or fast restarting.)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you have shutdown Windows fully, and not used hibernation, it may be caused by the &amp;lt;em&amp;gt;fast startup&amp;lt;/em&amp;gt; or &amp;lt;em&amp;gt;fast boot&amp;lt;/em&amp;gt; feature of Windows. It has been reported that major Windows updates may reset this setting to &amp;lt;strong&amp;gt;on&amp;lt;/strong&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[https://social.technet.microsoft.com/wiki/contents/articles/25908.fast-startup-how-to-disable-if-it-s-causing-problems.aspx This TechNet entry] explains how to disable fast startup. Additionally, [https://www.howtogeek.com/243901/the-pros-and-cons-of-windows-10s-fast-startup-mode/ this blog post on howtogeek.com] explains how the fast startup mode works, and how to disable it.&lt;br /&gt;
&lt;br /&gt;
=== Unable to mount ntfs3 with dirty volume ===&lt;br /&gt;
&lt;br /&gt;
When attempting to mount an &amp;lt;code&amp;gt;NTFS&amp;lt;/code&amp;gt; partition using the &amp;lt;code&amp;gt;ntfs3&amp;lt;/code&amp;gt; filesystem driver via the {{nixos:package|ntfs3g}} package, the mount operation may fail:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
# mount /dev/sda1 /mnt -t ntfs3&lt;br /&gt;
mount: /mnt: wrong fs type, bad option, bad superblock on /dev/sda1, missing codepage or helper program, or other error.&lt;br /&gt;
       dmesg(1) may have more information after failed mount system call.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With the resulting dmesg output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
# dmesg&lt;br /&gt;
...&lt;br /&gt;
[168659.819978] ntfs3: sda1: It is recommened to use chkdsk.&lt;br /&gt;
[168659.820833] ntfs3: sda1: volume is dirty and &amp;quot;force&amp;quot; flag is not set!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This indicates that the NTFS volume has the “dirty” flag set. In this state, the &amp;lt;code&amp;gt;ntfs3&amp;lt;/code&amp;gt; driver refuses to mount the filesystem.&lt;br /&gt;
&lt;br /&gt;
To clear the dirty flag, run &amp;lt;code&amp;gt;ntfsfix&amp;lt;/code&amp;gt; on the affected partition:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
# ntfsfix --clear-dirty /dev/sda1&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If &amp;lt;code&amp;gt;ntfsfix&amp;lt;/code&amp;gt; fails with an error &amp;lt;code&amp;gt;Windows is hibernated, refused to mount&amp;lt;/code&amp;gt;, the partition can be mounted using &amp;lt;code&amp;gt;ntfs-3g&amp;lt;/code&amp;gt; with the hibernation file removed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
# ntfs-3g -o remove_hiberfile /dev/sda1 /mnt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Filesystem]]&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=AMD_GPU&amp;diff=29309</id>
		<title>AMD GPU</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=AMD_GPU&amp;diff=29309"/>
		<updated>2025-12-31T06:46:05Z</updated>

		<summary type="html">&lt;p&gt;Pigs: combine problems section with troubleshooting&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[https://en.wikipedia.org/wiki/AMDgpu_(Linux_kernel_module) AMDGPU] is an open source graphics driver for AMD Radeon graphics cards. It supports AMD GPUs based on the [https://en.wikipedia.org/wiki/Graphics_Core_Next GCN architecture Graphics Core Next (GCN)] architecture and later, covering hardware released from approximately 2012 onward. This guide is about configuration of NixOS to correctly use AMD GPUs supported by the AMDGPU driver.&lt;br /&gt;
&lt;br /&gt;
== Basic Setup ==&lt;br /&gt;
For ordinary desktop / gaming usage, AMD GPUs are expected to work out of the box. As with any desktop configuration though, graphics acceleration does need to be enabled.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;hardware.graphics = {&lt;br /&gt;
  enable = true;&lt;br /&gt;
  enable32Bit = true;&lt;br /&gt;
};&amp;lt;/syntaxhighlight&amp;gt;There is also the [https://search.nixos.org/options?channel=unstable&amp;amp;query=hardware.amdgpu amdgpu nixos module available for common configuration options], such as enabling opencl, legacy support, overdrive/overclocking and loading during initrd.&lt;br /&gt;
&lt;br /&gt;
== Special Configuration ==&lt;br /&gt;
The following configurations are only required if you have a specific reason for needing them. They are not expected to be necessary for a typical desktop / gaming setup.&lt;br /&gt;
&lt;br /&gt;
=== Enable Southern Islands (SI) and Sea Islands (CIK) support (eg. HD 7000/8000) ===&lt;br /&gt;
The oldest architectures that AMDGPU supports are [[wikipedia:Radeon_HD_7000_series|Southern Islands (SI, i.e. GCN 1)]] and [[wikipedia:Radeon_HD_8000_series|Sea Islands (CIK, i.e. GCN 2)]], but support for them is disabled by default. To use AMDGPU instead of the &amp;lt;code&amp;gt;radeon&amp;lt;/code&amp;gt; driver, you can set the legacySupport option in the amdgpu module.&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
hardware.amdgpu.legacySupport.enable = true;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;This will set the kernel parameters as follows (this is redundant if you set the above option)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
boot.kernelParams = [&lt;br /&gt;
    # For Southern Islands (SI i.e. GCN 1) cards&lt;br /&gt;
    &amp;quot;amdgpu.si_support=1&amp;quot;&lt;br /&gt;
    &amp;quot;radeon.si_support=0&amp;quot;&lt;br /&gt;
    # For Sea Islands (CIK i.e. GCN 2) cards&lt;br /&gt;
    &amp;quot;amdgpu.cik_support=1&amp;quot;&lt;br /&gt;
    &amp;quot;radeon.cik_support=0&amp;quot;&lt;br /&gt;
];&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Doing this is required to use [[#Vulkan|Vulkan]] on these cards, as the &amp;lt;code&amp;gt;radeon&amp;lt;/code&amp;gt; driver doesn&#039;t support it.&lt;br /&gt;
&lt;br /&gt;
Please note this also removes support for analog video outputs, which is only available with the &amp;lt;code&amp;gt;radeon&amp;lt;/code&amp;gt; driver.&lt;br /&gt;
&lt;br /&gt;
=== HIP ===&lt;br /&gt;
Most software has the HIP libraries hard-coded. You can work around it on NixOS by using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
  systemd.tmpfiles.rules = &lt;br /&gt;
  let&lt;br /&gt;
    rocmEnv = pkgs.symlinkJoin {&lt;br /&gt;
      name = &amp;quot;rocm-combined&amp;quot;;&lt;br /&gt;
      paths = with pkgs.rocmPackages; [&lt;br /&gt;
        rocblas&lt;br /&gt;
        hipblas&lt;br /&gt;
        clr&lt;br /&gt;
      ];&lt;br /&gt;
    };&lt;br /&gt;
  in [&lt;br /&gt;
    &amp;quot;L+    /opt/rocm   -    -    -     -    ${rocmEnv}&amp;quot;&lt;br /&gt;
  ];&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Blender ====&lt;br /&gt;
Hardware accelerated rendering can be achieved by using the package &amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot; inline=&amp;quot;&amp;quot;&amp;gt;blender-hip&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Currently, you need to [[Linux kernel|use the latest kernel]] for &amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot; inline=&amp;quot;&amp;quot;&amp;gt;blender-hip&amp;lt;/syntaxhighlight&amp;gt; to work.&lt;br /&gt;
&lt;br /&gt;
=== OpenCL ===&lt;br /&gt;
OpenCL support using the ROCM runtime library can be enabled via the amdgpu module.&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
hardware.amdgpu.opencl.enable = true;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should also install the &amp;lt;code&amp;gt;clinfo&amp;lt;/code&amp;gt; package to verify that OpenCL is correctly setup (or check in the program you use to see if it is now available, such as in Darktable).&lt;br /&gt;
&lt;br /&gt;
==== Radeon 500 series (aka Polaris) ====&lt;br /&gt;
As of [https://github.com/ROCm/ROCm/issues/1659 ROCm 4.5], AMD has disabled OpenCL on Polaris-based cards. This can be re-enabled by setting the environment variable &amp;lt;code&amp;gt;ROC_ENABLE_PRE_VEGA=1&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
environment.variables = {&lt;br /&gt;
  ROC_ENABLE_PRE_VEGA = &amp;quot;1&amp;quot;;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Older GPUs (TeraScale) ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- FIXME this should be moved to a dedicated page for the &amp;quot;radeon&amp;quot; driver or OpenCL, if either of those are created at some point in the future --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For graphics cards older than GCN 1 — or for any GCN using the &amp;quot;radeon&amp;quot; driver — enable OpenCL by adding Clover &#039;&#039;instead of&#039;&#039; the ROCm ICD:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
hardware.opengl.extraPackages = with pkgs; [&lt;br /&gt;
  # OpenCL support for the older Radeon R300, R400, R500,&lt;br /&gt;
  # R600, R700, Evergreen, Northern Islands,&lt;br /&gt;
  # Southern Islands (radeon), and Sea Islands (radeon)&lt;br /&gt;
  # GPU families&lt;br /&gt;
  mesa.opencl&lt;br /&gt;
  # NOTE: at some point GPUs in the R600 family and newer&lt;br /&gt;
  # may need to replace this with the &amp;quot;rusticl&amp;quot; ICD;&lt;br /&gt;
  # and GPUs in the R500-family and older may need to&lt;br /&gt;
  # pin the package version or backport Clover&lt;br /&gt;
  # - https://www.phoronix.com/news/Mesa-Delete-Clover-Discussion&lt;br /&gt;
  # - https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19385&lt;br /&gt;
];&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Merely installing &amp;lt;code&amp;gt;mesa.opencl&amp;lt;/code&amp;gt; with &amp;lt;code&amp;gt;nix-shell -p&amp;lt;/code&amp;gt; will not work; it needs to be present at build-time for the OpenCL ICD loader, which only searches static paths.&lt;br /&gt;
&lt;br /&gt;
=== Vulkan ===&lt;br /&gt;
Vulkan is already enabled by default (using Mesa RADV) on 64 bit applications. The settings to control it are now the same as those shown in the basic setup:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;hardware.graphics.enable = true;&lt;br /&gt;
hardware.graphics.enable32Bit = true; # Replaced &#039;driSupport32Bit&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AMDVLK ====&lt;br /&gt;
&lt;br /&gt;
{{Warning|1=AMDVLK is being discontinued, so the only reason you may want to use it is if you have issues with RADV. See: https://github.com/GPUOpen-Drivers/AMDVLK/discussions/416.}}&lt;br /&gt;
&lt;br /&gt;
The AMDVLK drivers can be used in addition to the Mesa RADV drivers. The program will choose which one to use (mostly defaulting to AMDVLK):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
#24.11 &lt;br /&gt;
hardware.graphics.extraPackages = with pkgs; [&lt;br /&gt;
  amdvlk&lt;br /&gt;
];&lt;br /&gt;
# For 32 bit applications &lt;br /&gt;
hardware.graphics.extraPackages32 = with pkgs; [&lt;br /&gt;
  driversi686Linux.amdvlk&lt;br /&gt;
];&lt;br /&gt;
&lt;br /&gt;
#24.05 and below&lt;br /&gt;
hardware.opengl.extraPackages = with pkgs; [&lt;br /&gt;
  amdvlk&lt;br /&gt;
];&lt;br /&gt;
# For 32 bit applications &lt;br /&gt;
hardware.opengl.extraPackages32 = with pkgs; [&lt;br /&gt;
  driversi686Linux.amdvlk&lt;br /&gt;
];&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More information can be found here: https://nixos.org/manual/nixos/unstable/index.html#sec-gpu-accel-vulkan&lt;br /&gt;
&lt;br /&gt;
One way to avoid installing it system-wide, is creating a wrapper like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
with pkgs; writeShellScriptBin &amp;quot;amdvlk-run&amp;quot; &#039;&#039;&lt;br /&gt;
  export VK_DRIVER_FILES=&amp;quot;${amdvlk}/share/vulkan/icd.d/amd_icd64.json:${pkgsi686Linux.amdvlk}/share/vulkan/icd.d/amd_icd32.json&amp;quot;&lt;br /&gt;
  exec &amp;quot;$@&amp;quot;&lt;br /&gt;
&#039;&#039;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This wrapper can be used per-game inside Steam (&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot; inline&amp;gt;amdvlk-run %command%&amp;lt;/syntaxhighlight&amp;gt;) and lets RADV to be the system&#039;s default.&lt;br /&gt;
&lt;br /&gt;
===== Performance Issues with AMDVLK =====&lt;br /&gt;
Some games choose AMDVLK over RADV, which can cause noticeable performance issues (e.g. &amp;lt;50% less FPS in games)&lt;br /&gt;
&lt;br /&gt;
To force RADV&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
environment.variables.AMD_VULKAN_ICD = &amp;quot;RADV&amp;quot;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GUI tools ===&lt;br /&gt;
&lt;br /&gt;
==== LACT - Linux AMDGPU Controller ====&lt;br /&gt;
&lt;br /&gt;
This application allows you to overclock, undervolt, set fans curves of AMD GPUs on a Linux system.&lt;br /&gt;
&lt;br /&gt;
In order to install the daemon service you need to add the package to &amp;lt;code&amp;gt;systemd.packages&amp;lt;/code&amp;gt;. Also the &amp;lt;code&amp;gt;wantedBy&amp;lt;/code&amp;gt; field should be set to &amp;lt;code&amp;gt;multi-user.target&amp;lt;/code&amp;gt; to start the service during boot.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
environment.systemPackages = with pkgs; [ lact ];&lt;br /&gt;
systemd.packages = with pkgs; [ lact ];&lt;br /&gt;
systemd.services.lactd.wantedBy = [&amp;quot;multi-user.target&amp;quot;];&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;Simple version is:&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
services.lact.enable = true;&lt;br /&gt;
# https://github.com/NixOS/nixpkgs/blob/nixos-unstable/nixos/modules/services/hardware/lact.nix&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
=== Low resolution during initramfs phase ===&lt;br /&gt;
If you encounter a low resolution output during early boot phases, you can load the amdgpu module in the initial ramdisk&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
hardware.amdgpu.initrd.enable = true; # sets boot.initrd.kernelModules = [&amp;quot;amdgpu&amp;quot;];&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dual Monitors ===&lt;br /&gt;
&lt;br /&gt;
If you encounter problems having multiple monitors connected to your GPU, adding `video` parameters for each connector to the kernel command line sometimes helps.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
boot.kernelParams = [&lt;br /&gt;
  &amp;quot;video=DP-1:2560x1440@144&amp;quot;&lt;br /&gt;
  &amp;quot;video=DP-2:2560x1440@144&amp;quot;&lt;br /&gt;
];&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With the connector names (like `DP-1`), the resolution and frame rate adjusted accordingly.&lt;br /&gt;
&lt;br /&gt;
To figure out the connector names, execute the following command while your monitors are connected:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
head /sys/class/drm/*/status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== System Hang with Vega Graphics (and select GPUs) ===&lt;br /&gt;
&lt;br /&gt;
Currently on the latest kernel/mesa (currently 6.13 and 24.3.4 respectively), Vega integrated graphics (and other GPUs like the RX 6600&amp;lt;ref&amp;gt;https://bbs.archlinux.org/viewtopic.php?pid=2224147#p2224147&amp;lt;/ref&amp;gt;) will have a possibility to hang due to context-switching between Graphics and Compute.&amp;lt;ref&amp;gt;https://bbs.archlinux.org/viewtopic.php?id=301798&amp;lt;/ref&amp;gt; There are currently two sets of patches to choose between stability or speed that can be applied: [https://github.com/SeryogaBrigada/linux/commits/v6.13-amdgpu amdgpu-stable] and [https://github.com/SeryogaBrigada/linux/commits/v6.13-amdgpu-testing amdgpu-testing].&lt;br /&gt;
&lt;br /&gt;
See [[Linux Kernel#Patching a single In-tree kernel module]], keep in mind how to make [https://stackoverflow.com/a/23525893 patch diffs from commits from GitHub], and consider this example configuration:&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
{ config, pkgs, ... }:&lt;br /&gt;
let&lt;br /&gt;
  amdgpu-kernel-module = pkgs.callPackage ./packages/amdgpu-kernel-module.nix {&lt;br /&gt;
    # Make sure the module targets the same kernel as your system is using.&lt;br /&gt;
    kernel = config.boot.kernelPackages.kernel;&lt;br /&gt;
  };&lt;br /&gt;
  # linuxPackages_latest 6.13 (or linuxPackages_zen 6.13)&lt;br /&gt;
  amdgpu-stability-patch = pkgs.fetchpatch {&lt;br /&gt;
    name = &amp;quot;amdgpu-stability-patch&amp;quot;;&lt;br /&gt;
    url = &amp;quot;https://github.com/torvalds/linux/compare/ffd294d346d185b70e28b1a28abe367bbfe53c04...SeryogaBrigada:linux:4c55a12d64d769f925ef049dd6a92166f7841453.diff&amp;quot;;&lt;br /&gt;
    hash = &amp;quot;sha256-q/gWUPmKHFBHp7V15BW4ixfUn1kaeJhgDs0okeOGG9c=&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
  /*&lt;br /&gt;
  # linuxPackages_zen 6.12&lt;br /&gt;
  amdgpu-stability-patch = pkgs.fetchpatch {&lt;br /&gt;
    name = &amp;quot;amdgpu-stability-patch-zen&amp;quot;;&lt;br /&gt;
    url = &amp;quot;https://github.com/zen-kernel/zen-kernel/compare/fd00d197bb0a82b25e28d26d4937f917969012aa...WhiteHusky:zen-kernel:f4c32ca166ad55d7e2bbf9adf121113500f3b42b.diff&amp;quot;;&lt;br /&gt;
    hash = &amp;quot;sha256-bMT5OqBCyILwspWJyZk0j0c8gbxtcsEI53cQMbhbkL8=&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
  */&lt;br /&gt;
in&lt;br /&gt;
{&lt;br /&gt;
  # amdgpu instability with context switching between compute and graphics&lt;br /&gt;
  # https://bbs.archlinux.org/viewtopic.php?id=301798&lt;br /&gt;
  # side-effects: plymouth fails to show at boot, but does not interfere with booting&lt;br /&gt;
  boot.extraModulePackages = [&lt;br /&gt;
    (amdgpu-kernel-module.overrideAttrs (_: {&lt;br /&gt;
      patches = [&lt;br /&gt;
        amdgpu-stability-patch&lt;br /&gt;
      ];&lt;br /&gt;
    }))&lt;br /&gt;
  ];&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sporadic Crashes ===&lt;br /&gt;
&lt;br /&gt;
If getting error messages in &amp;lt;code&amp;gt;dmesg&amp;lt;/code&amp;gt; with &amp;lt;code&amp;gt;page fault&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;GCVM_L2_PROTECTION_FAULT_STATUS&amp;lt;/code&amp;gt; it might be from AMD GPU boosting too high without enough voltage&lt;br /&gt;
&lt;br /&gt;
Use a tool like LACT to increase power usage limit to 15%, undervolt by moderate amount (e.g. -50mV for 7900 XTX) and optionally decrease maximum GPU clock.&lt;br /&gt;
&lt;br /&gt;
* https://wiki.gentoo.org/wiki/AMDGPU#Frequent_and_Sporadic_Crashes&lt;br /&gt;
* https://gitlab.freedesktop.org/mesa/mesa/-/issues/11532&lt;br /&gt;
* https://gitlab.freedesktop.org/drm/amd/-/issues/3067&lt;br /&gt;
&lt;br /&gt;
=== Error: &amp;lt;code&amp;gt;amdgpu: Failed to get gpu_info firmware&amp;lt;/code&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
Solution:&lt;br /&gt;
 hardware.firmware = [ pkgs.linux-firmware ];&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
* https://wiki.archlinux.org/title/AMDGPU&lt;br /&gt;
* https://wiki.gentoo.org/wiki/AMDGPU&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Video]]&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=AMD_GPU&amp;diff=29308</id>
		<title>AMD GPU</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=AMD_GPU&amp;diff=29308"/>
		<updated>2025-12-31T06:34:03Z</updated>

		<summary type="html">&lt;p&gt;Pigs: clean up opening statement&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[https://en.wikipedia.org/wiki/AMDgpu_(Linux_kernel_module) AMDGPU] is an open source graphics driver for AMD Radeon graphics cards. It supports AMD GPUs based on the [https://en.wikipedia.org/wiki/Graphics_Core_Next GCN architecture Graphics Core Next (GCN)] architecture and later, covering hardware released from approximately 2012 onward. This guide is about configuration of NixOS to correctly use AMD GPUs supported by the AMDGPU driver.&lt;br /&gt;
&lt;br /&gt;
== Basic Setup ==&lt;br /&gt;
For ordinary desktop / gaming usage, AMD GPUs are expected to work out of the box. As with any desktop configuration though, graphics acceleration does need to be enabled.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;hardware.graphics = {&lt;br /&gt;
  enable = true;&lt;br /&gt;
  enable32Bit = true;&lt;br /&gt;
};&amp;lt;/syntaxhighlight&amp;gt;There is also the [https://search.nixos.org/options?channel=unstable&amp;amp;query=hardware.amdgpu amdgpu nixos module available for common configuration options], such as enabling opencl, legacy support, overdrive/overclocking and loading during initrd.&lt;br /&gt;
&lt;br /&gt;
== Problems ==&lt;br /&gt;
&lt;br /&gt;
=== Low resolution during initramfs phase ===&lt;br /&gt;
If you encounter a low resolution output during early boot phases, you can load the amdgpu module in the initial ramdisk&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
hardware.amdgpu.initrd.enable = true; # sets boot.initrd.kernelModules = [&amp;quot;amdgpu&amp;quot;];&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dual Monitors ===&lt;br /&gt;
&lt;br /&gt;
If you encounter problems having multiple monitors connected to your GPU, adding `video` parameters for each connector to the kernel command line sometimes helps.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
boot.kernelParams = [&lt;br /&gt;
  &amp;quot;video=DP-1:2560x1440@144&amp;quot;&lt;br /&gt;
  &amp;quot;video=DP-2:2560x1440@144&amp;quot;&lt;br /&gt;
];&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
With the connector names (like `DP-1`), the resolution and frame rate adjusted accordingly.&lt;br /&gt;
&lt;br /&gt;
To figure out the connector names, execute the following command while your monitors are connected:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
head /sys/class/drm/*/status&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== System Hang with Vega Graphics (and select GPUs) ===&lt;br /&gt;
&lt;br /&gt;
Currently on the latest kernel/mesa (currently 6.13 and 24.3.4 respectively), Vega integrated graphics (and other GPUs like the RX 6600&amp;lt;ref&amp;gt;https://bbs.archlinux.org/viewtopic.php?pid=2224147#p2224147&amp;lt;/ref&amp;gt;) will have a possibility to hang due to context-switching between Graphics and Compute.&amp;lt;ref&amp;gt;https://bbs.archlinux.org/viewtopic.php?id=301798&amp;lt;/ref&amp;gt; There are currently two sets of patches to choose between stability or speed that can be applied: [https://github.com/SeryogaBrigada/linux/commits/v6.13-amdgpu amdgpu-stable] and [https://github.com/SeryogaBrigada/linux/commits/v6.13-amdgpu-testing amdgpu-testing].&lt;br /&gt;
&lt;br /&gt;
See [[Linux Kernel#Patching a single In-tree kernel module]], keep in mind how to make [https://stackoverflow.com/a/23525893 patch diffs from commits from GitHub], and consider this example configuration:&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
{ config, pkgs, ... }:&lt;br /&gt;
let&lt;br /&gt;
  amdgpu-kernel-module = pkgs.callPackage ./packages/amdgpu-kernel-module.nix {&lt;br /&gt;
    # Make sure the module targets the same kernel as your system is using.&lt;br /&gt;
    kernel = config.boot.kernelPackages.kernel;&lt;br /&gt;
  };&lt;br /&gt;
  # linuxPackages_latest 6.13 (or linuxPackages_zen 6.13)&lt;br /&gt;
  amdgpu-stability-patch = pkgs.fetchpatch {&lt;br /&gt;
    name = &amp;quot;amdgpu-stability-patch&amp;quot;;&lt;br /&gt;
    url = &amp;quot;https://github.com/torvalds/linux/compare/ffd294d346d185b70e28b1a28abe367bbfe53c04...SeryogaBrigada:linux:4c55a12d64d769f925ef049dd6a92166f7841453.diff&amp;quot;;&lt;br /&gt;
    hash = &amp;quot;sha256-q/gWUPmKHFBHp7V15BW4ixfUn1kaeJhgDs0okeOGG9c=&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
  /*&lt;br /&gt;
  # linuxPackages_zen 6.12&lt;br /&gt;
  amdgpu-stability-patch = pkgs.fetchpatch {&lt;br /&gt;
    name = &amp;quot;amdgpu-stability-patch-zen&amp;quot;;&lt;br /&gt;
    url = &amp;quot;https://github.com/zen-kernel/zen-kernel/compare/fd00d197bb0a82b25e28d26d4937f917969012aa...WhiteHusky:zen-kernel:f4c32ca166ad55d7e2bbf9adf121113500f3b42b.diff&amp;quot;;&lt;br /&gt;
    hash = &amp;quot;sha256-bMT5OqBCyILwspWJyZk0j0c8gbxtcsEI53cQMbhbkL8=&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
  */&lt;br /&gt;
in&lt;br /&gt;
{&lt;br /&gt;
  # amdgpu instability with context switching between compute and graphics&lt;br /&gt;
  # https://bbs.archlinux.org/viewtopic.php?id=301798&lt;br /&gt;
  # side-effects: plymouth fails to show at boot, but does not interfere with booting&lt;br /&gt;
  boot.extraModulePackages = [&lt;br /&gt;
    (amdgpu-kernel-module.overrideAttrs (_: {&lt;br /&gt;
      patches = [&lt;br /&gt;
        amdgpu-stability-patch&lt;br /&gt;
      ];&lt;br /&gt;
    }))&lt;br /&gt;
  ];&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sporadic Crashes ===&lt;br /&gt;
&lt;br /&gt;
If getting error messages in &amp;lt;code&amp;gt;dmesg&amp;lt;/code&amp;gt; with &amp;lt;code&amp;gt;page fault&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;GCVM_L2_PROTECTION_FAULT_STATUS&amp;lt;/code&amp;gt; it might be from AMD GPU boosting too high without enough voltage&lt;br /&gt;
&lt;br /&gt;
Use a tool like LACT to increase power usage limit to 15%, undervolt by moderate amount (e.g. -50mV for 7900 XTX) and optionally decrease maximum GPU clock.&lt;br /&gt;
&lt;br /&gt;
* https://wiki.gentoo.org/wiki/AMDGPU#Frequent_and_Sporadic_Crashes&lt;br /&gt;
* https://gitlab.freedesktop.org/mesa/mesa/-/issues/11532&lt;br /&gt;
* https://gitlab.freedesktop.org/drm/amd/-/issues/3067&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Special Configuration ==&lt;br /&gt;
The following configurations are only required if you have a specific reason for needing them. They are not expected to be necessary for a typical desktop / gaming setup.&lt;br /&gt;
&lt;br /&gt;
=== Enable Southern Islands (SI) and Sea Islands (CIK) support (eg. HD 7000/8000) ===&lt;br /&gt;
The oldest architectures that AMDGPU supports are [[wikipedia:Radeon_HD_7000_series|Southern Islands (SI, i.e. GCN 1)]] and [[wikipedia:Radeon_HD_8000_series|Sea Islands (CIK, i.e. GCN 2)]], but support for them is disabled by default. To use AMDGPU instead of the &amp;lt;code&amp;gt;radeon&amp;lt;/code&amp;gt; driver, you can set the legacySupport option in the amdgpu module.&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
hardware.amdgpu.legacySupport.enable = true;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;This will set the kernel parameters as follows (this is redundant if you set the above option)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
boot.kernelParams = [&lt;br /&gt;
    # For Southern Islands (SI i.e. GCN 1) cards&lt;br /&gt;
    &amp;quot;amdgpu.si_support=1&amp;quot;&lt;br /&gt;
    &amp;quot;radeon.si_support=0&amp;quot;&lt;br /&gt;
    # For Sea Islands (CIK i.e. GCN 2) cards&lt;br /&gt;
    &amp;quot;amdgpu.cik_support=1&amp;quot;&lt;br /&gt;
    &amp;quot;radeon.cik_support=0&amp;quot;&lt;br /&gt;
];&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Doing this is required to use [[#Vulkan|Vulkan]] on these cards, as the &amp;lt;code&amp;gt;radeon&amp;lt;/code&amp;gt; driver doesn&#039;t support it.&lt;br /&gt;
&lt;br /&gt;
Please note this also removes support for analog video outputs, which is only available with the &amp;lt;code&amp;gt;radeon&amp;lt;/code&amp;gt; driver.&lt;br /&gt;
&lt;br /&gt;
=== HIP ===&lt;br /&gt;
Most software has the HIP libraries hard-coded. You can work around it on NixOS by using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
  systemd.tmpfiles.rules = &lt;br /&gt;
  let&lt;br /&gt;
    rocmEnv = pkgs.symlinkJoin {&lt;br /&gt;
      name = &amp;quot;rocm-combined&amp;quot;;&lt;br /&gt;
      paths = with pkgs.rocmPackages; [&lt;br /&gt;
        rocblas&lt;br /&gt;
        hipblas&lt;br /&gt;
        clr&lt;br /&gt;
      ];&lt;br /&gt;
    };&lt;br /&gt;
  in [&lt;br /&gt;
    &amp;quot;L+    /opt/rocm   -    -    -     -    ${rocmEnv}&amp;quot;&lt;br /&gt;
  ];&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Blender ====&lt;br /&gt;
Hardware accelerated rendering can be achieved by using the package &amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot; inline=&amp;quot;&amp;quot;&amp;gt;blender-hip&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Currently, you need to [[Linux kernel|use the latest kernel]] for &amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot; inline=&amp;quot;&amp;quot;&amp;gt;blender-hip&amp;lt;/syntaxhighlight&amp;gt; to work.&lt;br /&gt;
&lt;br /&gt;
=== OpenCL ===&lt;br /&gt;
OpenCL support using the ROCM runtime library can be enabled via the amdgpu module.&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
hardware.amdgpu.opencl.enable = true;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You should also install the &amp;lt;code&amp;gt;clinfo&amp;lt;/code&amp;gt; package to verify that OpenCL is correctly setup (or check in the program you use to see if it is now available, such as in Darktable).&lt;br /&gt;
&lt;br /&gt;
==== Radeon 500 series (aka Polaris) ====&lt;br /&gt;
As of [https://github.com/ROCm/ROCm/issues/1659 ROCm 4.5], AMD has disabled OpenCL on Polaris-based cards. This can be re-enabled by setting the environment variable &amp;lt;code&amp;gt;ROC_ENABLE_PRE_VEGA=1&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
environment.variables = {&lt;br /&gt;
  ROC_ENABLE_PRE_VEGA = &amp;quot;1&amp;quot;;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Older GPUs (TeraScale) ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- FIXME this should be moved to a dedicated page for the &amp;quot;radeon&amp;quot; driver or OpenCL, if either of those are created at some point in the future --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For graphics cards older than GCN 1 — or for any GCN using the &amp;quot;radeon&amp;quot; driver — enable OpenCL by adding Clover &#039;&#039;instead of&#039;&#039; the ROCm ICD:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
hardware.opengl.extraPackages = with pkgs; [&lt;br /&gt;
  # OpenCL support for the older Radeon R300, R400, R500,&lt;br /&gt;
  # R600, R700, Evergreen, Northern Islands,&lt;br /&gt;
  # Southern Islands (radeon), and Sea Islands (radeon)&lt;br /&gt;
  # GPU families&lt;br /&gt;
  mesa.opencl&lt;br /&gt;
  # NOTE: at some point GPUs in the R600 family and newer&lt;br /&gt;
  # may need to replace this with the &amp;quot;rusticl&amp;quot; ICD;&lt;br /&gt;
  # and GPUs in the R500-family and older may need to&lt;br /&gt;
  # pin the package version or backport Clover&lt;br /&gt;
  # - https://www.phoronix.com/news/Mesa-Delete-Clover-Discussion&lt;br /&gt;
  # - https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19385&lt;br /&gt;
];&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Merely installing &amp;lt;code&amp;gt;mesa.opencl&amp;lt;/code&amp;gt; with &amp;lt;code&amp;gt;nix-shell -p&amp;lt;/code&amp;gt; will not work; it needs to be present at build-time for the OpenCL ICD loader, which only searches static paths.&lt;br /&gt;
&lt;br /&gt;
=== Vulkan ===&lt;br /&gt;
Vulkan is already enabled by default (using Mesa RADV) on 64 bit applications. The settings to control it are now the same as those shown in the basic setup:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;hardware.graphics.enable = true;&lt;br /&gt;
hardware.graphics.enable32Bit = true; # Replaced &#039;driSupport32Bit&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== AMDVLK ====&lt;br /&gt;
&lt;br /&gt;
{{Warning|1=AMDVLK is being discontinued, so the only reason you may want to use it is if you have issues with RADV. See: https://github.com/GPUOpen-Drivers/AMDVLK/discussions/416.}}&lt;br /&gt;
&lt;br /&gt;
The AMDVLK drivers can be used in addition to the Mesa RADV drivers. The program will choose which one to use (mostly defaulting to AMDVLK):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
#24.11 &lt;br /&gt;
hardware.graphics.extraPackages = with pkgs; [&lt;br /&gt;
  amdvlk&lt;br /&gt;
];&lt;br /&gt;
# For 32 bit applications &lt;br /&gt;
hardware.graphics.extraPackages32 = with pkgs; [&lt;br /&gt;
  driversi686Linux.amdvlk&lt;br /&gt;
];&lt;br /&gt;
&lt;br /&gt;
#24.05 and below&lt;br /&gt;
hardware.opengl.extraPackages = with pkgs; [&lt;br /&gt;
  amdvlk&lt;br /&gt;
];&lt;br /&gt;
# For 32 bit applications &lt;br /&gt;
hardware.opengl.extraPackages32 = with pkgs; [&lt;br /&gt;
  driversi686Linux.amdvlk&lt;br /&gt;
];&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More information can be found here: https://nixos.org/manual/nixos/unstable/index.html#sec-gpu-accel-vulkan&lt;br /&gt;
&lt;br /&gt;
One way to avoid installing it system-wide, is creating a wrapper like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
with pkgs; writeShellScriptBin &amp;quot;amdvlk-run&amp;quot; &#039;&#039;&lt;br /&gt;
  export VK_DRIVER_FILES=&amp;quot;${amdvlk}/share/vulkan/icd.d/amd_icd64.json:${pkgsi686Linux.amdvlk}/share/vulkan/icd.d/amd_icd32.json&amp;quot;&lt;br /&gt;
  exec &amp;quot;$@&amp;quot;&lt;br /&gt;
&#039;&#039;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This wrapper can be used per-game inside Steam (&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot; inline&amp;gt;amdvlk-run %command%&amp;lt;/syntaxhighlight&amp;gt;) and lets RADV to be the system&#039;s default.&lt;br /&gt;
&lt;br /&gt;
===== Performance Issues with AMDVLK =====&lt;br /&gt;
Some games choose AMDVLK over RADV, which can cause noticeable performance issues (e.g. &amp;lt;50% less FPS in games)&lt;br /&gt;
&lt;br /&gt;
To force RADV&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
environment.variables.AMD_VULKAN_ICD = &amp;quot;RADV&amp;quot;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GUI tools ===&lt;br /&gt;
&lt;br /&gt;
==== LACT - Linux AMDGPU Controller ====&lt;br /&gt;
&lt;br /&gt;
This application allows you to overclock, undervolt, set fans curves of AMD GPUs on a Linux system.&lt;br /&gt;
&lt;br /&gt;
In order to install the daemon service you need to add the package to &amp;lt;code&amp;gt;systemd.packages&amp;lt;/code&amp;gt;. Also the &amp;lt;code&amp;gt;wantedBy&amp;lt;/code&amp;gt; field should be set to &amp;lt;code&amp;gt;multi-user.target&amp;lt;/code&amp;gt; to start the service during boot.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
environment.systemPackages = with pkgs; [ lact ];&lt;br /&gt;
systemd.packages = with pkgs; [ lact ];&lt;br /&gt;
systemd.services.lactd.wantedBy = [&amp;quot;multi-user.target&amp;quot;];&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;Simple version is:&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
services.lact.enable = true;&lt;br /&gt;
# https://github.com/NixOS/nixpkgs/blob/nixos-unstable/nixos/modules/services/hardware/lact.nix&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
==== Error: &amp;lt;code&amp;gt;amdgpu: Failed to get gpu_info firmware&amp;lt;/code&amp;gt; ====&lt;br /&gt;
Solution:&lt;br /&gt;
 hardware.firmware = [ pkgs.linux-firmware ];&lt;br /&gt;
&lt;br /&gt;
=== Links ===&lt;br /&gt;
&lt;br /&gt;
* https://wiki.archlinux.org/title/AMDGPU&lt;br /&gt;
* https://wiki.gentoo.org/wiki/AMDGPU&lt;br /&gt;
&lt;br /&gt;
=== References ===&lt;br /&gt;
&lt;br /&gt;
[[Category:Video]]&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=Steam&amp;diff=29299</id>
		<title>Steam</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=Steam&amp;diff=29299"/>
		<updated>2025-12-30T07:18:15Z</updated>

		<summary type="html">&lt;p&gt;Pigs: formatting and hyperlinking&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;languages/&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:1--&amp;gt;&lt;br /&gt;
[https://store.steampowered.com/ Steam] is a digital distribution platform for video games, offering a vast library for purchase, download, and management. On NixOS, Steam is generally easy to install and use, often working &amp;quot;out-of-the-box&amp;quot;. It supports running many Windows games on Linux through its compatibility layer, [[#Proton|Proton]].&amp;lt;ref&amp;gt;https://store.steampowered.com/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
== Installation == &amp;lt;!--T:2--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== Shell ==== &amp;lt;!--T:3--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:4--&amp;gt;&lt;br /&gt;
To temporarily use Steam-related tools like &amp;lt;code&amp;gt;steam-run&amp;lt;/code&amp;gt; (for FHS environments) or &amp;lt;code&amp;gt;steamcmd&amp;lt;/code&amp;gt; (for server management or tools like steam-tui setup) in a shell environment, you can run:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
$ nix-shell -p steam-run # For FHS environment&lt;br /&gt;
$ nix-shell -p steamcmd  # For steamcmd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:5--&amp;gt;&lt;br /&gt;
This provides the tools in your current shell without adding them to your system configuration. For &amp;lt;code&amp;gt;steamcmd&amp;lt;/code&amp;gt; to work correctly for some tasks (like initializing for steam-tui), you might need to run it once to generate necessary files, as shown in the [[#steam-tui| steam-tui section]].&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== System setup ==== &amp;lt;!--T:6--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:7--&amp;gt;&lt;br /&gt;
To install the [[Steam]] package and enable all the system options necessary to allow it to run, add the following to your system configuration:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
{{file|/etc/nixos/configuration.nix|nix|&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
programs.steam = {&lt;br /&gt;
  enable = true;&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
# Optional: If you encounter amdgpu issues with newer kernels (e.g., 6.10+ reported issues),&lt;br /&gt;
# you might consider using the LTS kernel or a known stable version.&lt;br /&gt;
# boot.kernelPackages = pkgs.linuxPackages_lts; # Example for LTS&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:8--&amp;gt;&lt;br /&gt;
[https://news.ycombinator.com/item?id=41549030 Anecdata on kernel 6.10 issues]&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{note|Enabling [[steam]] installs several [[unfree software|unfree packages]]. If you are using &amp;lt;code&amp;gt;allowUnfreePredicate&amp;lt;/code&amp;gt; you will need to ensure that your configurations permit all of them.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
  nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [&lt;br /&gt;
    &amp;quot;steam&amp;quot;&lt;br /&gt;
    &amp;quot;steam-unwrapped&amp;quot;&lt;br /&gt;
  ];&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
== Configuration == &amp;lt;!--T:9--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:10--&amp;gt;&lt;br /&gt;
Basic Steam features can be enabled directly within the {{nixos:option|programs.steam}} attribute set:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
{{file|/etc/nixos/configuration.nix|nix|&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
programs.steam = {&lt;br /&gt;
  enable = true; # Master switch, already covered in installation&lt;br /&gt;
  remotePlay.openFirewall = true;  # Open ports in the firewall for Steam Remote Play&lt;br /&gt;
  dedicatedServer.openFirewall = true; # Open ports for Source Dedicated Server hosting&lt;br /&gt;
  # Other general flags if available can be set here.&lt;br /&gt;
};&lt;br /&gt;
# Tip: For improved gaming performance, you can also enable GameMode:&lt;br /&gt;
# programs.gamemode.enable = true;&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:11--&amp;gt;&lt;br /&gt;
{{note|If you are using a Steam Controller or a Valve Index, Steam hardware support is implicitly enabled by &amp;lt;code&amp;gt;programs.steam.enable {{=}} true;&amp;lt;/code&amp;gt; which sets {{nixos:option|hardware.steam-hardware.enable}} to true.}}&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
== Tips and tricks == &amp;lt;!--T:12--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Gamescope Compositor / &amp;quot;Boot to Steam Deck&amp;quot; === &amp;lt;!--T:13--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:14--&amp;gt;&lt;br /&gt;
Gamescope can function as a minimal desktop environment, meaning you can launch it from a TTY and have an experience very similar to the Steam Deck hardware console.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
# Clean Quiet Boot&lt;br /&gt;
boot.kernelParams = [ &amp;quot;quiet&amp;quot; &amp;quot;splash&amp;quot; &amp;quot;console=/dev/null&amp;quot; ];&lt;br /&gt;
boot.plymouth.enable = true;&lt;br /&gt;
&lt;br /&gt;
programs.gamescope = {&lt;br /&gt;
  enable = true;&lt;br /&gt;
  capSysNice = true;&lt;br /&gt;
};&lt;br /&gt;
programs.steam.gamescopeSession.enable = true; # Integrates with programs.steam&lt;br /&gt;
&lt;br /&gt;
# Gamescope Auto Boot from TTY (example)&lt;br /&gt;
services.xserver.enable = false; # Assuming no other Xserver needed&lt;br /&gt;
services.getty.autologinUser = &amp;quot;USERNAME_HERE&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
services.greetd = {&lt;br /&gt;
  enable = true;&lt;br /&gt;
  settings = {&lt;br /&gt;
    default_session = {&lt;br /&gt;
      command = &amp;quot;${pkgs.gamescope}/bin/gamescope -W 1920 -H 1080 -f -e --xwayland-count 2 --hdr-enabled --hdr-itm-enabled -- steam -pipewire-dmabuf -gamepadui -steamdeck -steamos3 &amp;gt; /dev/null 2&amp;gt;&amp;amp;1&amp;quot;;&lt;br /&gt;
      user = &amp;quot;USERNAME_HERE&amp;quot;;&lt;br /&gt;
    };&lt;br /&gt;
  };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Gamescope HDR ===&lt;br /&gt;
In order for HDR to work within gamescope, you need to separately install the &amp;lt;code&amp;gt;gamescope-wsi&amp;lt;/code&amp;gt; package alongside enabling the &amp;lt;code&amp;gt;gamescope&amp;lt;/code&amp;gt; program.&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
programs.gamescope = {&lt;br /&gt;
  enable = true;&lt;br /&gt;
  capSysNice = false;&lt;br /&gt;
};&lt;br /&gt;
environment.systemPackages = with pkgs; [&lt;br /&gt;
  gamescope-wsi # HDR won&#039;t work without this&lt;br /&gt;
];&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;Additionally, it may be necessary to force HDR in gamescope with the argument &amp;lt;code&amp;gt;--hdr-debug-force-output&amp;lt;/code&amp;gt; when configuring your game&#039;s launch options in steam (see the example below).&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
gamescope -W 3840 -H 2160 -r 120 -f --adaptive-sync --hdr-enabled --hdr-debug-force-output --mangoapp -- %command%&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== steam-tui === &amp;lt;!--T:15--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:16--&amp;gt;&lt;br /&gt;
If you want the steam-tui client, you&#039;ll have to install it. It relies on &amp;lt;code&amp;gt;steamcmd&amp;lt;/code&amp;gt; being set up, so you&#039;ll need to run &amp;lt;code&amp;gt;steamcmd&amp;lt;/code&amp;gt; once to generate the necessary configuration files.&lt;br /&gt;
First, ensure &amp;lt;code&amp;gt;steamcmd&amp;lt;/code&amp;gt; is available (e.g., via &amp;lt;code&amp;gt;nix-shell -p steamcmd&amp;lt;/code&amp;gt; or by adding it to &amp;lt;code&amp;gt;environment.systemPackages&amp;lt;/code&amp;gt;), then run:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
steamcmd +quit # This initializes steamcmd&#039;s directory structure&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:17--&amp;gt;&lt;br /&gt;
Then install and run `steam-tui`. You may need to log in within `steamcmd` first if `steam-tui` has issues:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# (Inside steamcmd prompt, if needed for full login before steam-tui)&lt;br /&gt;
# login &amp;lt;username&amp;gt; &amp;lt;password&amp;gt; &amp;lt;steam_2fa_code&amp;gt;&lt;br /&gt;
# quit&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:18--&amp;gt;&lt;br /&gt;
After setup, &amp;lt;code&amp;gt;steam-tui&amp;lt;/code&amp;gt; (if installed e.g. via &amp;lt;code&amp;gt;home.packages&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;environment.systemPackages&amp;lt;/code&amp;gt;) should start fine.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== FHS environment only === &amp;lt;!--T:19--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:20--&amp;gt;&lt;br /&gt;
To run proprietary games or software downloaded from the internet that expect a typical Linux Filesystem Hierarchy Standard (FHS), you can use &amp;lt;code&amp;gt;steam-run&amp;lt;/code&amp;gt;. This provides an FHS-like environment without needing to patch the software.&lt;br /&gt;
Note that this is not necessary for clients installed from Nixpkgs (like Minigalaxy or Itch), which already use the FHS environment as needed.&lt;br /&gt;
There are two options to make &amp;lt;code&amp;gt;steam-run&amp;lt;/code&amp;gt; available:&lt;br /&gt;
1. Install &amp;lt;code&amp;gt;steam-run&amp;lt;/code&amp;gt; system-wide or user-specifically:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
# In /etc/nixos/configuration.nix&lt;br /&gt;
environment.systemPackages = with pkgs; [&lt;br /&gt;
  steam-run&lt;br /&gt;
];&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:21--&amp;gt;&lt;br /&gt;
2. If you need more flexibility or want to use an overridden Steam package&#039;s FHS environment:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
# In /etc/nixos/configuration.nix&lt;br /&gt;
environment.systemPackages = with pkgs; [&lt;br /&gt;
  (steam.override { /* Your overrides here */ }).run&lt;br /&gt;
];&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Proton === &amp;lt;!--T:22--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:23--&amp;gt;&lt;br /&gt;
You should be able to play most Windows games using Proton. If a game has a native Linux version that causes issues on NixOS, you can force the use of Proton by selecting a specific Proton version in the game&#039;s compatibility settings in Steam.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:24--&amp;gt;&lt;br /&gt;
By default, Steam also looks for custom Proton versions in &amp;lt;code&amp;gt;~/.steam/root/compatibilitytools.d&amp;lt;/code&amp;gt;. The environment variable &amp;lt;code&amp;gt;STEAM_EXTRA_COMPAT_TOOLS_PATHS&amp;lt;/code&amp;gt; can be set to add other search paths.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:25--&amp;gt;&lt;br /&gt;
Declarative install of custom Proton versions (e.g. GE-Proton):&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
programs.steam.extraCompatPackages = with pkgs; [&lt;br /&gt;
  proton-ge-bin&lt;br /&gt;
];&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:26--&amp;gt;&lt;br /&gt;
Manual management of multiple Proton versions can be done with ProtonUp-Qt:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
environment.systemPackages = with pkgs; [&lt;br /&gt;
  protonup-qt&lt;br /&gt;
];&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Overriding the Steam package === &amp;lt;!--T:27--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:28--&amp;gt;&lt;br /&gt;
In some cases, you may need to override the default Steam package to provide missing dependencies or modify its build. Use the &amp;lt;code&amp;gt;programs.steam.package&amp;lt;/code&amp;gt; option for this. Steam on NixOS runs many games in an FHS environment, but the Steam client itself or certain tools might need extra libraries.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:29--&amp;gt;&lt;br /&gt;
Example: Adding Bumblebee and Primus (for NVIDIA Optimus):&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
programs.steam.package = pkgs.steam.override {&lt;br /&gt;
  extraPkgs = pkgs&#039;: with pkgs&#039;; [ bumblebee primus ];&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
# For 32-bit applications with Steam, if using steamFull:&lt;br /&gt;
# programs.steam.package = pkgs.steamFull.override { extraPkgs = pkgs&#039;: with pkgs&#039;; [ bumblebee primus ]; };&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:30--&amp;gt;&lt;br /&gt;
Example: Adding Xorg libraries for Gamescope (when used within Steam):&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
programs.steam.package = pkgs.steam.override {&lt;br /&gt;
  extraPkgs = pkgs&#039;: with pkgs&#039;; [&lt;br /&gt;
    xorg.libXcursor&lt;br /&gt;
    xorg.libXi&lt;br /&gt;
    xorg.libXinerama&lt;br /&gt;
    xorg.libXScrnSaver&lt;br /&gt;
    libpng&lt;br /&gt;
    libpulseaudio&lt;br /&gt;
    libvorbis&lt;br /&gt;
    stdenv.cc.cc.lib # Provides libstdc++.so.6&lt;br /&gt;
    libkrb5&lt;br /&gt;
    keyutils&lt;br /&gt;
    # Add other libraries as needed&lt;br /&gt;
  ];&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Fix missing icons for games in GNOME dock and activities overview === &amp;lt;!--T:56--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:57--&amp;gt;&lt;br /&gt;
GNOME uses the window class to determine the icon associated with a window. Steam currently doesn&#039;t set the required key for this in its .desktop files&amp;lt;ref&amp;gt;https://github.com/ValveSoftware/steam-for-linux/issues/12207&amp;lt;/ref&amp;gt;, but you can fix this manually by editing the &amp;lt;code&amp;gt;StartupWMClass&amp;lt;/code&amp;gt; key for each game&#039;s .desktop file, found under &amp;lt;code&amp;gt;~/.local/share/applications/&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:58--&amp;gt;&lt;br /&gt;
For games running through Proton, the value should be &amp;lt;code&amp;gt;steam_app_&amp;lt;game_id&amp;gt;&amp;lt;/code&amp;gt; (where &amp;lt;code&amp;gt;&amp;lt;game_id&amp;gt;&amp;lt;/code&amp;gt; matches the value after steam://rungameid/ on the &amp;lt;code&amp;gt;Exec&amp;lt;/code&amp;gt; line).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:59--&amp;gt;&lt;br /&gt;
For games running natively, the value should match the game&#039;s main executable.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:60--&amp;gt;&lt;br /&gt;
For example, the modified .desktop file for Valheim looks like this:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;desktop&amp;quot;&amp;gt;&lt;br /&gt;
[Desktop Entry]&lt;br /&gt;
Name=Valheim&lt;br /&gt;
Comment=Play this game on Steam&lt;br /&gt;
Exec=steam steam://rungameid/892970&lt;br /&gt;
Icon=steam_icon_892970&lt;br /&gt;
Terminal=false&lt;br /&gt;
Type=Application&lt;br /&gt;
Categories=Game;&lt;br /&gt;
StartupWMClass=valheim.x86_64&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
== Troubleshooting == &amp;lt;!--T:31--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:32--&amp;gt;&lt;br /&gt;
For all issues: first run &amp;lt;code&amp;gt;steam -dev -console&amp;lt;/code&amp;gt; through the terminal and read the output.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Steam fails to start. What do I do? === &amp;lt;!--T:33--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:34--&amp;gt;&lt;br /&gt;
Run &amp;lt;code&amp;gt;strace steam -dev -console 2&amp;gt; steam.logs&amp;lt;/code&amp;gt; in the terminal. If &amp;lt;code&amp;gt;strace&amp;lt;/code&amp;gt; is not installed, temporarily install it using &amp;lt;code&amp;gt;nix-shell -p strace&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;nix run nixpkgs#strace -- steam -dev -console 2&amp;gt; steam.logs&amp;lt;/code&amp;gt; (if using Flakes). After that, create a bug report. &amp;lt;!-- This is vague. Where should the user create a bug report?  --&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Steam is not updated === &amp;lt;!--T:35--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:36--&amp;gt;&lt;br /&gt;
When you restart [[Steam]] after an update, it starts the old version. ([https://github.com/NixOS/nixpkgs/issues/181904 #181904])&lt;br /&gt;
A workaround is to remove the user files in &amp;lt;code&amp;gt;/home/&amp;amp;lt;USER&amp;amp;gt;/.local/share/Steam/userdata&amp;lt;/code&amp;gt;. This can be done with &amp;lt;code&amp;gt;rm -rf /home/&amp;amp;lt;USER&amp;amp;gt;/.local/share/Steam/userdata&amp;lt;/code&amp;gt; in the terminal or with your file manager. After that, Steam can be set up again by restarting.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Game fails to start === &amp;lt;!--T:37--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:38--&amp;gt;&lt;br /&gt;
Games may fail to start because they lack dependencies (this should be added to the script, for now), or because they cannot be patched. The steps to launch a game directly are:&lt;br /&gt;
* Patch the script/binary if you can&lt;br /&gt;
* Add a file named steam_appid.txt in the binary folder, with the appid as contents (it can be found in the stdout from steam)&lt;br /&gt;
* Using the LD_LIBRARY_PATH from the nix/store steam script, with some additions, launch the game binary&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
LD_LIBRARY_PATH=~/.steam/bin32:$LD_LIBRARY_PATH:/nix/store/pfsa... blabla ...curl-7.29.0/lib:. ./Osmos.bin32 (if you could not patchelf the game, call ld.so directly with the binary as parameter)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:39--&amp;gt;&lt;br /&gt;
Note: If a game gets stuck on Installing scripts, check for a DXSETUP.EXE process and run it manually, then restart the game launch.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== Changing the driver on AMD GPUs &amp;lt;!-- this is not recommended due radv drivers performing better and generally more stable than amdvlk. My suggestion remove this section. source: https://forums.guru3d.com/threads/the-mesa-radv-amdvlk-thread.449774/ --&amp;gt;==== &amp;lt;!--T:40--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
{{note|This is not recommended because radv drivers tend to perform better and are generally more stable than amdvlk.}}&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:41--&amp;gt;&lt;br /&gt;
Sometimes, changing the driver on AMD GPUs helps. To try this, first, install multiple drivers such as radv and amdvlk:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
hardware.graphics = {&lt;br /&gt;
  ## radv: an open-source Vulkan driver from freedesktop&lt;br /&gt;
  enable32Bit = true;&lt;br /&gt;
&lt;br /&gt;
  ## amdvlk: an open-source Vulkan driver from AMD&lt;br /&gt;
  extraPackages = [ pkgs.amdvlk ];&lt;br /&gt;
  extraPackages32 = [ pkgs.driversi686Linux.amdvlk ];&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:42--&amp;gt;&lt;br /&gt;
In the presence of both drivers, [[Steam]] will default to amdvlk. The amdvlk driver can be considered more correct regarding Vulkan specification implementation, but less performant than radv. However, this tradeoff between correctness and performance can sometimes make or break the gaming experience.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:43--&amp;gt;&lt;br /&gt;
To &amp;quot;reset&amp;quot; your driver to radv when both radv and amdvlk are installed, set either &amp;lt;code&amp;gt;AMD_VULKAN_ICD = &amp;quot;RADV&amp;quot;&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;VK_ICD_FILENAMES = &amp;quot;/run/opengl-driver/share/vulkan/icd.d/radeon_icd.x86_64.json&amp;quot;&amp;lt;/code&amp;gt; environment variable. For example, if you start [[Steam]] from the shell, you can enable radv for the current session by running &amp;lt;code&amp;gt;AMD_VULKAN_ICD=&amp;quot;RADV&amp;quot; steam&amp;lt;/code&amp;gt;. If you are unsure which driver you currently use, you can launch a game with [https://github.com/flightlessmango/MangoHud MangoHud] enabled, which has the capability to show what driver is currently in use.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== SteamVR === &amp;lt;!--T:44--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:45--&amp;gt;&lt;br /&gt;
The setcap issue at SteamVR start can be fixed with:&lt;br /&gt;
&amp;lt;code&amp;gt;sudo setcap CAP_SYS_NICE+ep ~/.local/share/Steam/steamapps/common/SteamVR/bin/linux64/vrcompositor-launcher&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Gamescope fails to launch when used within Steam === &amp;lt;!--T:46--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:47--&amp;gt;&lt;br /&gt;
Gamescope may fail to start due to missing Xorg libraries. ([https://github.com/NixOS/nixpkgs/issues/214275 #214275]) To resolve this override the steam package to add them:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
programs.steam.package = pkgs.steam.override {&lt;br /&gt;
  extraPkgs = pkgs&#039;: with pkgs&#039;; [&lt;br /&gt;
    xorg.libXcursor&lt;br /&gt;
    xorg.libXi&lt;br /&gt;
    xorg.libXinerama&lt;br /&gt;
    xorg.libXScrnSaver&lt;br /&gt;
    libpng&lt;br /&gt;
    libpulseaudio&lt;br /&gt;
    libvorbis&lt;br /&gt;
    stdenv.cc.cc.lib # Provides libstdc++.so.6&lt;br /&gt;
    libkrb5&lt;br /&gt;
    keyutils&lt;br /&gt;
    # Add other libraries as needed&lt;br /&gt;
  ];&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Udev rules for additional Gamepads === &amp;lt;!--T:48--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:49--&amp;gt;&lt;br /&gt;
In specific scenarios gamepads, might require some additional configuration in order to function properly in the form of udev rules. This can be achieved with &amp;lt;code&amp;gt;services.udev.extraRules&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:50--&amp;gt;&lt;br /&gt;
The following example is for the 8bitdo Ultimate Bluetooth controller, different controllers will require knowledge of the vendor and product ID for the device:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
  services.udev.extraRules = &#039;&#039;&lt;br /&gt;
    SUBSYSTEM==&amp;quot;input&amp;quot;, ATTRS{idVendor}==&amp;quot;2dc8&amp;quot;, ATTRS{idProduct}==&amp;quot;3106&amp;quot;, MODE=&amp;quot;0660&amp;quot;, GROUP=&amp;quot;input&amp;quot;&lt;br /&gt;
  &#039;&#039;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:51--&amp;gt;&lt;br /&gt;
To find the vendor and product ID of a device [https://search.nixos.org/packages?channel=unstable&amp;amp;show=usbutils&amp;amp;from=0&amp;amp;size=50&amp;amp;sort=relevance&amp;amp;type=packages&amp;amp;query=usbutils usbutils] might be useful&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Known issues === &amp;lt;!--T:52--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:53--&amp;gt;&lt;br /&gt;
&amp;quot;Project Zomboid&amp;quot; may report &amp;quot;couldn&#039;t determine 32/64 bit of java&amp;quot;. This is not related to java at all, it carries its own outdated java binary that refuses to start if path contains non-Latin characters. Check for errors by directly starting local java binary within &amp;lt;code&amp;gt;steam-run bash&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:55--&amp;gt;&lt;br /&gt;
Resetting your password through the [[Steam]] app may fail at the CAPTCHA step repeatedly, with [[Steam]] itself reporting that the CAPTCHA was not correct, even though the CAPTCHA UI shows success. Resetting password through the [[Steam]] website should work around that.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
== References == &amp;lt;!--T:54--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Applications]]&lt;br /&gt;
[[Category:Gaming]]&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=Kind&amp;diff=29234</id>
		<title>Kind</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=Kind&amp;diff=29234"/>
		<updated>2025-12-26T19:18:57Z</updated>

		<summary type="html">&lt;p&gt;Pigs: Create page, detail installation and getting started&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[https://kind.sigs.k8s.io/ Kind] (Kubernetes in Docker) is a tool for running local [[Kubernetes]] clusters using [[Docker]] containers as nodes. It is commonly used for development, testing, and CI environments.&lt;br /&gt;
&lt;br /&gt;
= Installation =&lt;br /&gt;
&lt;br /&gt;
Kind is available in nixpkgs:&lt;br /&gt;
&lt;br /&gt;
{{file|/etc/nixos/configuration.nix|nix|&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
  environment.systemPackages = with pkgs; [&lt;br /&gt;
    kind&lt;br /&gt;
    kubectl&lt;br /&gt;
  ];&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
= Container runtime configuration =&lt;br /&gt;
&lt;br /&gt;
Enable [[Docker]] in the NixOS Configuration:&lt;br /&gt;
&lt;br /&gt;
{{file|/etc/nixos/configuration.nix|nix|&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
  virtualisation.docker.enable = true;&lt;br /&gt;
  users.users.&amp;lt;/nowiki&amp;gt;&amp;lt;&amp;lt;nowiki&amp;gt;username&amp;lt;/nowiki&amp;gt;&amp;gt;&amp;lt;nowiki&amp;gt;.extraGroups = [ &amp;quot;docker&amp;quot; ];&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Log out and back in for group membership to take effect.&lt;br /&gt;
&lt;br /&gt;
{{note|Running Docker in rootless mode may cause permission issues.}}&lt;br /&gt;
&lt;br /&gt;
= Managing clusters =&lt;br /&gt;
&lt;br /&gt;
To create a default cluster:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxHighlight lang=console&amp;gt;&lt;br /&gt;
$ kind create cluster&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This creates a single node Kubernetes cluster running inside a Docker container.&lt;br /&gt;
&lt;br /&gt;
To list existing Kind clusters:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxHighlight lang=console&amp;gt;&lt;br /&gt;
$ kind get clusters&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To delete the cluster:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxHighlight lang=console&amp;gt;&lt;br /&gt;
$ kind delete cluster&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= See Also =&lt;br /&gt;
&lt;br /&gt;
* [[Kubernetes]]&lt;br /&gt;
* [[Docker]]&lt;br /&gt;
* [[k3s]]&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=Git&amp;diff=29163</id>
		<title>Git</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=Git&amp;diff=29163"/>
		<updated>2025-12-21T17:33:38Z</updated>

		<summary type="html">&lt;p&gt;Pigs: improve wording, add additional information on git installation and configuring&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[https://en.wikipedia.org/wiki/Git_(software) Git] is the version control system (VCS) developed by Junio C Hamano and designed by Linus Torvalds (creator of linux kernel). Git is used to maintain NixOS packages, as well as many other projects, including sources for the Linux kernel. &lt;br /&gt;
&lt;br /&gt;
== Installing and configuring Git ==&lt;br /&gt;
&lt;br /&gt;
On NixOS, Git can be installed and configured at either the system level or the user level with [[Home Manager]].&lt;br /&gt;
&lt;br /&gt;
=== System-wide installation ===&lt;br /&gt;
&lt;br /&gt;
Git can be installed system-wide either by adding it to the list of system environment packages:&lt;br /&gt;
&lt;br /&gt;
{{file|/etc/nixos/configuration.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
  environment.systemPackages = with pkgs; [ &lt;br /&gt;
    git &lt;br /&gt;
  ];&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Or by enabling the NixOS Git module:&lt;br /&gt;
&lt;br /&gt;
{{file|/etc/nixos/configuration.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
  programs.git.enable = true;&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Additional Git module configuration options can be found at {{nixos:option|programs.git}}.&lt;br /&gt;
&lt;br /&gt;
{{note|Configuration options provided by this module are applied at the system level and therefore apply to all users on the system.}}&lt;br /&gt;
&lt;br /&gt;
=== User-level configuration with Home Manager ===&lt;br /&gt;
&lt;br /&gt;
Git can be configured using [[Home Manager]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
  programs.git = {&lt;br /&gt;
    enable = true;&lt;br /&gt;
    settings.user = {&lt;br /&gt;
        name  = &amp;quot;John Doe&amp;quot;;&lt;br /&gt;
        email = &amp;quot;johndoe@example.com&amp;quot;;&lt;br /&gt;
    };&lt;br /&gt;
  };&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Aliases can be added with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
  programs.git = {&lt;br /&gt;
    enable = true;&lt;br /&gt;
    settings.alias = {&lt;br /&gt;
      ci = &amp;quot;commit&amp;quot;;&lt;br /&gt;
      co = &amp;quot;checkout&amp;quot;;&lt;br /&gt;
      s = &amp;quot;status&amp;quot;;&lt;br /&gt;
    };&lt;br /&gt;
  };&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Git [https://git-lfs.com/ LFS] can be enabled with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
  programs.git = {&lt;br /&gt;
    enable = true;&lt;br /&gt;
    lfs.enable = true;&lt;br /&gt;
  };&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Configure git-credential-helper with libsecret:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;{ pkgs, ... }:&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  programs.git = {&lt;br /&gt;
    enable = true;&lt;br /&gt;
    package = pkgs.git.override { withLibsecret = true; };&lt;br /&gt;
    settings = {&lt;br /&gt;
      credential.helper = &amp;quot;libsecret&amp;quot;;&lt;br /&gt;
    };&lt;br /&gt;
  };&lt;br /&gt;
}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To add additional configuration you can specify options in an attribute set, so to add something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;ini&amp;quot;&amp;gt;&lt;br /&gt;
[push]&lt;br /&gt;
        autoSetupRemote = true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To your &amp;lt;code&amp;gt;~/.config/git/config&amp;lt;/code&amp;gt;, you can add the below to &amp;lt;code&amp;gt;extraConfig&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
{ pkgs, ... }:&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  programs.git = {&lt;br /&gt;
    enable = true;&lt;br /&gt;
    settings = {&lt;br /&gt;
      push = { autoSetupRemote = true; };&lt;br /&gt;
    };&lt;br /&gt;
  };&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Using your public SSH key as a signing key ====&lt;br /&gt;
&lt;br /&gt;
To configure git to automatically sign your commits using your public SSH key like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  programs.git = {&lt;br /&gt;
    enable = true;&lt;br /&gt;
    signing = {&lt;br /&gt;
      key = &amp;quot;ssh-ed25519 AAAAAAAAAAAA...AA username@hostname&amp;quot;;&lt;br /&gt;
      signByDefault = true;&lt;br /&gt;
    };&lt;br /&gt;
    settings = {&lt;br /&gt;
      gpg = {&lt;br /&gt;
        format = &amp;quot;ssh&amp;quot;;&lt;br /&gt;
      };&lt;br /&gt;
    };&lt;br /&gt;
  };&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However, note that this will also require Home Manager to manage your SSH configuration:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;{    &lt;br /&gt;
  programs.ssh = {&lt;br /&gt;
    enable = true;&lt;br /&gt;
    addKeysToAgent = &amp;quot;yes&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enabling Git UI ===&lt;br /&gt;
&lt;br /&gt;
Install &amp;lt;code&amp;gt;tk&amp;lt;/code&amp;gt; to use the git gui:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=console&amp;gt;&lt;br /&gt;
$ git citool&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or you may wish to install the &amp;lt;code&amp;gt;gitFull&amp;lt;/code&amp;gt; package, which includes &amp;lt;code&amp;gt;git gui&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;gitk&amp;lt;/code&amp;gt;, etc. This can be installed either through system environment packages or by setting the package module option:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
  programs.git = {&lt;br /&gt;
    enable = true;&lt;br /&gt;
    package = pkgs.gitFull;&lt;br /&gt;
  };&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Management of the &amp;lt;code&amp;gt;nixpkgs&amp;lt;/code&amp;gt; git repository ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;nixpkgs&amp;lt;/code&amp;gt; has become a git repository of quite substantial size with &amp;gt; 889 000 commits (as of late 2025). This brings many unoptimized tools to their limits, leading to long waiting times on certain operations. Here we’ll collect useful info on how to manage that.&lt;br /&gt;
&lt;br /&gt;
=== Garbage collecting ===&lt;br /&gt;
&lt;br /&gt;
Normal &amp;lt;code&amp;gt;git gc&amp;lt;/code&amp;gt; should work as usual, but you should force a full garbage collect every half a year or so. &amp;lt;code&amp;gt;git gc --aggressive&amp;lt;/code&amp;gt; is the command for that. For the author it did not work on the first try, since their laptop’s memory was too small and it went out of memory. According to [https://stackoverflow.com/a/4829883/1382925|this StackOverflow] answer it suffices to set some local repository config variables.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=console&amp;gt;&lt;br /&gt;
$ git config pack.windowMemory 2g&lt;br /&gt;
$ git config pack.packSizeLimit 1g&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
worked well on a machine with about 6–8 GB of free RAM and two processor threads, and reduced the size of the &amp;lt;code&amp;gt;nixpkgs&amp;lt;/code&amp;gt; checkout from ~1.3 GB to ~0.95 GB.&lt;br /&gt;
&lt;br /&gt;
= Serve Git repos via SSH =&lt;br /&gt;
&lt;br /&gt;
This section implements [https://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server Git on the Server - Setting Up the Server] on NixOS.&lt;br /&gt;
&lt;br /&gt;
See also: [[gitolite]].&lt;br /&gt;
&lt;br /&gt;
== Configuration ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
{ config, pkgs, ... }: {&lt;br /&gt;
  users.users.git = {&lt;br /&gt;
    isSystemUser = true;&lt;br /&gt;
    group = &amp;quot;git&amp;quot;;&lt;br /&gt;
    home = &amp;quot;/var/lib/git-server&amp;quot;;&lt;br /&gt;
    createHome = true;&lt;br /&gt;
    shell = &amp;quot;${pkgs.git}/bin/git-shell&amp;quot;;&lt;br /&gt;
    openssh.authorizedKeys.keys = [&lt;br /&gt;
      # FIXME: Add pubkeys of authorized users&lt;br /&gt;
      &amp;quot;ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIF38sHxXn/r7KzWL1BVCqcKqmZA/V76N/y5p52UQghw7 example&amp;quot;&lt;br /&gt;
    ];&lt;br /&gt;
  };&lt;br /&gt;
&lt;br /&gt;
  users.groups.git = {};&lt;br /&gt;
&lt;br /&gt;
  services.openssh = {&lt;br /&gt;
    enable = true;&lt;br /&gt;
    extraConfig = &#039;&#039;&lt;br /&gt;
      Match user git&lt;br /&gt;
        AllowTcpForwarding no&lt;br /&gt;
        AllowAgentForwarding no&lt;br /&gt;
        PasswordAuthentication no&lt;br /&gt;
        PermitTTY no&lt;br /&gt;
        X11Forwarding no&lt;br /&gt;
    &#039;&#039;;&lt;br /&gt;
  };&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
&lt;br /&gt;
1. Run this on the server to create repo &amp;lt;code&amp;gt;myproject&amp;lt;/code&amp;gt; accessible by user &amp;lt;code&amp;gt;git&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo -u git bash -c &amp;quot;git init --bare ~/myproject.git&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
(&amp;lt;code&amp;gt;~&amp;lt;/code&amp;gt; here is the home of the user &amp;lt;code&amp;gt;git&amp;lt;/code&amp;gt;, which is &amp;lt;code&amp;gt;/var/lib/git-server&amp;lt;/code&amp;gt;)&lt;br /&gt;
&lt;br /&gt;
2. Push to the server repo from another system &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mkdir myproject&lt;br /&gt;
cd myproject&lt;br /&gt;
echo hello &amp;gt; a&lt;br /&gt;
git init&lt;br /&gt;
git add .&lt;br /&gt;
git commit -m init&lt;br /&gt;
git remote add origin git@myserver:myproject.git&lt;br /&gt;
git push origin master&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Clone and edit the server repo from another system&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
git clone git@myserver:myproject.git&lt;br /&gt;
cd myproject&lt;br /&gt;
cat a&lt;br /&gt;
echo world &amp;gt;&amp;gt; a&lt;br /&gt;
git commit -am hello&lt;br /&gt;
git push origin master&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Bisecting Nix regressions ==&lt;br /&gt;
&lt;br /&gt;
{{main|bisecting}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Applications]]&lt;br /&gt;
[[Category:CLI Applications]]&lt;br /&gt;
[[Category:Version control]]&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=JAX&amp;diff=28935</id>
		<title>JAX</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=JAX&amp;diff=28935"/>
		<updated>2025-12-09T19:11:28Z</updated>

		<summary type="html">&lt;p&gt;Pigs: /* Example shell.nix with GPU support */ syntax highlight code block, additional crosslinking and formatting&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[https://github.com/google/jax JAX] is a framework for program transformation, esp. for automatic differentiation and machine learning. It&#039;s available in [[Nixpkgs]] in the &amp;lt;code&amp;gt;python3Packages.{{{nixos:package|python3Packages.jax|jax}}, {{nixos:package|python3%20jaxlib|jaxlib}}, {{nixos:package|python3*.jaxlibWithCuda|jaxlibWithCuda}}}&amp;lt;/code&amp;gt; packages.&lt;br /&gt;
&lt;br /&gt;
{{tip|1=&#039;&#039;&#039;Cache&#039;&#039;&#039;: Using the [https://app.cachix.org/cache/nix-community nix-community cache] is recommended! It will save you valuable time and electrons. Getting set up should be as simple as &amp;lt;code&amp;gt;cachix use nix-community&amp;lt;/code&amp;gt;. See the [[CUDA]] wiki page for more info.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Example shell.nix, CPU only ==&lt;br /&gt;
&amp;lt;syntaxHighlight lang=nix&amp;gt;&lt;br /&gt;
let&lt;br /&gt;
  # Last updated 01/31/2022. Check status.nixos.org for updates.&lt;br /&gt;
  pkgs = import (fetchTarball(&amp;quot;https://github.com/NixOS/nixpkgs/archive/376934f4b7ca6910b243be5fabcf3f4228043725.tar.gz&amp;quot;)) {};&lt;br /&gt;
in pkgs.mkShell {&lt;br /&gt;
  buildInputs = with pkgs; [&lt;br /&gt;
    python3&lt;br /&gt;
    python3Packages.jax&lt;br /&gt;
    python3Packages.jaxlib&lt;br /&gt;
  ];&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example shell.nix with GPU support ==&lt;br /&gt;
JAX defers execution to the jaxlib library for execution. In order to use GPU support you&#039;ll need a [[NVIDIA]] GPU and [[OpenGL]]. In your &amp;lt;code&amp;gt;/etc/nixos/configuration.nix&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;syntaxHighlight lang=nix&amp;gt;&lt;br /&gt;
# NVIDIA drivers are unfree&lt;br /&gt;
nixpkgs.config.allowUnfree = true;&lt;br /&gt;
services.xserver.videoDrivers = [ &amp;quot;nvidia&amp;quot; ];&lt;br /&gt;
hardware.opengl.enable = true;&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
Then you can use the &amp;lt;code&amp;gt;jaxlibWithCuda&amp;lt;/code&amp;gt; package (equivalent to setting the &amp;lt;code&amp;gt;cudaSupport&amp;lt;/code&amp;gt; parameter):&lt;br /&gt;
&amp;lt;syntaxHighlight lang=nix&amp;gt;&lt;br /&gt;
let&lt;br /&gt;
  # Last updated 01/31/2022. Check status.nixos.org for updates.&lt;br /&gt;
  pkgs = import (fetchTarball(&amp;quot;https://github.com/NixOS/nixpkgs/archive/376934f4b7ca6910b243be5fabcf3f4228043725.tar.gz&amp;quot;)) {};&lt;br /&gt;
in pkgs.mkShell {&lt;br /&gt;
  buildInputs = with pkgs; [&lt;br /&gt;
    python3&lt;br /&gt;
    python3Packages.jax&lt;br /&gt;
    python3Packages.jaxlibWithCuda&lt;br /&gt;
  ];&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
You can test that JAX is using the GPU as intended with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxHighlight lang=bash&amp;gt;&lt;br /&gt;
# after version 0.8.0&lt;br /&gt;
python -c &amp;quot;import jax.extend as ex; print(ex.backend.get_backend().platform)&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
# before version 0.8.0&lt;br /&gt;
python -c &amp;quot;from jax.lib import xla_bridge; print(xla_bridge.get_backend().platform)&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It should print either &amp;lt;code&amp;gt;cpu&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;gpu&amp;lt;/code&amp;gt;, or &amp;lt;code&amp;gt;tpu&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{Note| [[Hydra]] may not cache &amp;lt;code&amp;gt;jaxlibWithCuda&amp;lt;/code&amp;gt; builds on cache.nixos.org since CUDA is [[unfree software]]. @samuela publishes builds on a public cachix [https://app.cachix.org/cache/ploop#pull ploop] cache. These are periodically built and pushed from [https://github.com/samuela/nixpkgs-upkeep/ nixpkgs-upkeep].}}&lt;br /&gt;
&lt;br /&gt;
== FAQ ==&lt;br /&gt;
=== How do I package JAX libraries? ===&lt;br /&gt;
Never ever ever put &amp;lt;code&amp;gt;jaxlib&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;propagatedBuildInputs&amp;lt;/code&amp;gt;. However, it may live happily in &amp;lt;code&amp;gt;buildInputs&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;checkInputs&amp;lt;/code&amp;gt;. See https://github.com/NixOS/nixpkgs/pull/156808 for context.&lt;br /&gt;
&lt;br /&gt;
=== RuntimeError: Unknown: no kernel image is available for execution on the device ===&lt;br /&gt;
This usually indicates that you have a driver version that is too old for the CUDA toolkit version the package is built with. The easiest fix is to set the environment variable &amp;lt;code&amp;gt;XLA_FLAGS=&amp;quot;--xla_gpu_force_compilation_parallelism=1&amp;quot;&amp;lt;/code&amp;gt;. Also consider upgrading your CUDA driver. &lt;br /&gt;
&lt;br /&gt;
See https://github.com/google/jax/issues/5723#issuecomment-913038780.&lt;br /&gt;
&lt;br /&gt;
[[Category:Applications]]&lt;br /&gt;
[[Category:Python]]&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=Talk:Libvirt&amp;diff=28837</id>
		<title>Talk:Libvirt</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=Talk:Libvirt&amp;diff=28837"/>
		<updated>2025-12-04T05:02:03Z</updated>

		<summary type="html">&lt;p&gt;Pigs: /* Libvirt&amp;#039;s extra group */ Reply&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Watch for SPICE support in Apache Guacamole ==&lt;br /&gt;
&lt;br /&gt;
https://issues.apache.org/jira/browse/GUACAMOLE-261 If this comes to fruition, this could streamline the guide to setting up SPICE via web browser, probably reduces attack surface area a lot.  (Could be a risky proposition to expose SPICE to the internet directly, via websocket...) &amp;amp;mdash; [[User:Winny|Winny]] ([[User talk:Winny|talk]]) 18:31, 20 April 2023 (UTC)&lt;br /&gt;
&lt;br /&gt;
== Libvirt&#039;s extra group ==&lt;br /&gt;
&lt;br /&gt;
Shouldn&#039;t extraGroups = [ &amp;quot;libvirt&amp;quot; ] instead of &amp;quot;libvirtd&amp;quot;?&lt;br /&gt;
&lt;br /&gt;
Ref: https://wiki.archlinux.org/title/Libvirt#Using_libvirt_group, https://askubuntu.com/questions/930491/group-libvirtd-does-not-exist-while-installing-qemu-kvm. [[User:Daanturo|Daanturo]] ([[User talk:Daanturo|talk]]) 03:43, 4 December 2025 (UTC)&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;code&amp;gt;libvirtd&amp;lt;/code&amp;gt; is correct, different Linux distros have different naming conventions. &lt;br /&gt;
:See https://github.com/NixOS/nixpkgs/blob/8bb5646e0bed5dbd3ab08c7a7cc15b75ab4e1d0f/nixos/modules/virtualisation/libvirtd.nix#L429C1-L429C58 for the source [[User:Pigs|Pigs]] ([[User talk:Pigs|talk]]) 05:02, 4 December 2025 (UTC)&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=Locales&amp;diff=27979</id>
		<title>Locales</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=Locales&amp;diff=27979"/>
		<updated>2025-10-30T18:09:39Z</updated>

		<summary type="html">&lt;p&gt;Pigs: fix broken supportedLocales to extraLocales&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;NixOS allows to set the default [https://en.wikipedia.org/wiki/Locale_(computer_software) locale] as well as individual locales in the system configuration file:&lt;br /&gt;
&lt;br /&gt;
{{file|/etc/nixos/configuration.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
  # Mandatory&lt;br /&gt;
  i18n.defaultLocale = &amp;quot;en_US.UTF-8&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
  # Optionally (BEWARE: requires a different format with the added /UTF-8)&lt;br /&gt;
  i18n.extraLocales = [&amp;quot;es_VE.UTF-8/UTF-8&amp;quot;];&lt;br /&gt;
&lt;br /&gt;
  # Optionally&lt;br /&gt;
  i18n.extraLocaleSettings = {&lt;br /&gt;
    # LC_ALL = &amp;quot;en_US.UTF-8&amp;quot;; # This overrides all other LC_* settings.&lt;br /&gt;
    LC_CTYPE = &amp;quot;en_US.UTF8&amp;quot;;&lt;br /&gt;
    LC_ADDRESS = &amp;quot;es_VE.UTF-8&amp;quot;;&lt;br /&gt;
    LC_MEASUREMENT = &amp;quot;es_VE.UTF-8&amp;quot;;&lt;br /&gt;
    LC_MESSAGES = &amp;quot;en_US.UTF-8&amp;quot;;&lt;br /&gt;
    LC_MONETARY = &amp;quot;es_VE.UTF-8&amp;quot;;&lt;br /&gt;
    LC_NAME = &amp;quot;es_VE.UTF-8&amp;quot;;&lt;br /&gt;
    LC_NUMERIC = &amp;quot;en_US.UTF-8&amp;quot;;&lt;br /&gt;
    LC_PAPER = &amp;quot;es_VE.UTF-8&amp;quot;;&lt;br /&gt;
    LC_TELEPHONE = &amp;quot;es_VE.UTF-8&amp;quot;;&lt;br /&gt;
    LC_TIME = &amp;quot;es_VE.UTF-8&amp;quot;;&lt;br /&gt;
    LC_COLLATE = &amp;quot;es_VE.UTF-8&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{nixos:option|i18n.defaultLocale}} will set the language and the character set systemwide to the desired value. Specifically, defaultLocale will define the &amp;lt;code&amp;gt;LANG&amp;lt;/code&amp;gt; environment variable.&lt;br /&gt;
&lt;br /&gt;
In addition, with {{nixos:option|i18n.extraLocales}}, the system will also support Venezuelan Spanish. The value &amp;lt;code&amp;gt;&amp;quot;all&amp;quot;&amp;lt;/code&amp;gt; means that all locales supported by Glibc will be installed. A full list of supported locales can be found at https://sourceware.org/git/?p=glibc.git;a=blob;f=localedata/SUPPORTED.&lt;br /&gt;
&lt;br /&gt;
And in the {{nixos:option|i18n.extraLocaleSettings}}, it is possible to set the LC locales individually. This does allow fine-grained adjustments of the used locales. In the above example a mix of American English and Venezuelan Spanish is used. It is also possible to find these settings at [https://search.nixos.org/options NixOS options]. Just search for i18 locale.&lt;br /&gt;
&lt;br /&gt;
{{note|The setting &amp;lt;code&amp;gt;i18n.extraLocales&amp;lt;/code&amp;gt; requires a different format to &amp;lt;code&amp;gt;i18n.extraLocaleSettings&amp;lt;/code&amp;gt;  with the added &amp;lt;code&amp;gt;/UTF-8&amp;lt;/code&amp;gt;. Otherwise, your locale settings will likely not work.}}&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting when using nix on non-NixOS linux distributions ==&lt;br /&gt;
&lt;br /&gt;
You may need to set the environmental variable LOCALE_ARCHIVE to point to your system&#039;s locale-archive. The following can be added to your .zshenv (zsh) or .profile (bash) and applies to Debian, Red Hat, and Arch derivatives:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
export LOCALE_ARCHIVE=/usr/lib/locale/locale-archive&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And if that file from the local system is somehow broken:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# May require a one-time installation with:&lt;br /&gt;
nix profile install nixpkgs#glibcLocales&lt;br /&gt;
# Using nix profile&lt;br /&gt;
export LOCALE_ARCHIVE=&amp;quot;$(nix profile list --json | jq &#039;.elements[] | select(.attrPath? and (.attrPath | type == &amp;quot;string&amp;quot;) and (.attrPath | endswith(&amp;quot;glibcLocales&amp;quot;))) | .storePaths[0]&#039;)/lib/locale/locale-archive&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Legacy usage with `nix-env`: May require a one-time installation with: nix-env -iA nixpkgs.glibcLocales&lt;br /&gt;
export LOCALE_ARCHIVE=&amp;quot;$(nix-env --installed --no-name --out-path --query glibc-locales)/lib/locale/locale-archive&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Enable locale support in Nix shell ==&lt;br /&gt;
&lt;br /&gt;
To support locales within a Nix shell, for example to get localised command output, you need to do something similar:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=bash&amp;gt;&lt;br /&gt;
pkgs.mkShell {&lt;br /&gt;
  # [other code omitted]&lt;br /&gt;
  LOCALE_ARCHIVE = &amp;quot;${pkgs.glibcLocales}/lib/locale/locale-archive&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Configuration]]&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=KSMBD&amp;diff=26475</id>
		<title>KSMBD</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=KSMBD&amp;diff=26475"/>
		<updated>2025-09-21T16:43:33Z</updated>

		<summary type="html">&lt;p&gt;Pigs: Remove nonexistent configuration options&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[https://docs.kernel.org/next/filesystems/cifs/ksmbd.html KSMBD] is a Linux kernel server which implements SMB3 protocol in kernel space for sharing files over network.&lt;br /&gt;
&lt;br /&gt;
Userspace utilities for the KSMBD kernel SMB server are provided by the {{nixos:package|ksmbd-tools}}.&lt;br /&gt;
&lt;br /&gt;
[[Category:Filesystem]]&lt;br /&gt;
[[Category:Networking]]&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=User:Pigs/NixOS_Wiki&amp;diff=23254</id>
		<title>User:Pigs/NixOS Wiki</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=User:Pigs/NixOS_Wiki&amp;diff=23254"/>
		<updated>2025-06-28T03:07:59Z</updated>

		<summary type="html">&lt;p&gt;Pigs: testing out changes on my page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;languages/&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:1--&amp;gt;&lt;br /&gt;
&amp;lt;span style=&amp;quot;height: 4px;&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
__NOTOC__&lt;br /&gt;
&amp;lt;!-- NOTE: Please don&#039;t change the layout/categorizing without first coordinating with the other editors. --&amp;gt;&lt;br /&gt;
&amp;lt;!-- NOTE: Feel free to add/edit content though! --&amp;gt;&lt;br /&gt;
&amp;lt;!-- NOTE: This page is affected by special CSS rules that alter the brightness of images in dark mode.&lt;br /&gt;
     Please do not add images here unless you understand the rules in MediaWiki:Common.css and have&lt;br /&gt;
     tested how this page looks in both light and dark mode. --&amp;gt;&lt;br /&gt;
&amp;lt;!-- NOTE: Removing those notes and/or disregarding this is not only rude, but should be considered defacement. --&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;row home-panes&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;div class=&amp;quot;col-md-7&amp;quot;&amp;gt;&lt;br /&gt;
{{home:box|get-started|icon=clarifications|Getting started|&lt;br /&gt;
Welcome to the official NixOS Wiki!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:2--&amp;gt;&lt;br /&gt;
NixOS is a [https://kernel.org/ Linux] operating system based on the Nix package manager and the Nixpkgs package repository.&lt;br /&gt;
&lt;br /&gt;
This wiki complements the [https://nixos.org/nixos/manual NixOS Manual] with user guides, configuration examples, troubleshooting tips, and community knowledge.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:3--&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;New to Nix? Start here:&#039;&#039;&#039;&lt;br /&gt;
* [[Nix Ecosystem|Overview of the Nix Core Ecosystem]] - for a broad orientation  &lt;br /&gt;
* [[Overview_of_the_NixOS_Linux_distribution|NixOS]] - the operating system  &lt;br /&gt;
* [[Nix package manager]] - the core tool  &lt;br /&gt;
* [[Nixpkgs|Nixpkgs]] - package repository&lt;br /&gt;
* [[Overview of the Nix Language|Nix Language]] - the domain specific language behind configurations  &lt;br /&gt;
&lt;br /&gt;
To get started with Nix on another OS, visit [https://nix.dev nix.dev] for guides on using Nix on other Linux distributions or macOS. &lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:5--&amp;gt;&lt;br /&gt;
{{home:box|hosting|icon=cloud|Setting up NixOS|&lt;br /&gt;
To install NixOS, start with the [[NixOS Installation Guide]].&lt;br /&gt;
&lt;br /&gt;
Guides for specific environments:&lt;br /&gt;
* [[NixOS as a desktop]] - personal computers&lt;br /&gt;
* [[NixOS as a server]] - server environments&lt;br /&gt;
* [[NixOS on ARM]] - ARM devices&lt;br /&gt;
* [[NixOS friendly hosters|NixOS in the cloud]] - cloud hosting options&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:6--&amp;gt;&lt;br /&gt;
{{home:box|doctopics|icon=manual|Documentation &amp;amp; topics|&lt;br /&gt;
Visit the [[Resources]] page for links to essential Nix documentation. Notable examples:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:7--&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Essential nix manuals:&#039;&#039;&#039;&lt;br /&gt;
* [https://nixos.org/nixos/manual/ NixOS manual]&lt;br /&gt;
* [https://nixos.org/nix/manual/ Nix manual]&lt;br /&gt;
* [https://nixos.org/nixpkgs/manual/ Nixpkgs manual]&lt;br /&gt;
* [https://nixos.org/hydra/manual/ Hydra manual]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Explore by category:&#039;&#039;&#039;&lt;br /&gt;
* [[:{{ns:14}}:Software|Software]]&lt;br /&gt;
* [[:{{ns:14}}:Hardware|Hardware]]&lt;br /&gt;
* [[:{{ns:14}}:Desktop|Desktop]]&lt;br /&gt;
* [[:{{ns:14}}:Server|Server]]&lt;br /&gt;
* [[:{{ns:14}}:Community|Community]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:9--&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Helpful pages:&#039;&#039;&#039;&lt;br /&gt;
* [[FAQ]]&lt;br /&gt;
* [[Cheatsheet]]&lt;br /&gt;
* [[Nix vs. Linux Standard Base]]&lt;br /&gt;
* [[Terms and Definitions in Nix Project]]&lt;br /&gt;
* [[Ubuntu vs. NixOS|Comparison between Ubuntu and NixOS]]&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;/div&amp;gt;&lt;br /&gt;
    &amp;lt;div class=&amp;quot;col-md-5&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{home:box|get-in-touch|icon=dialog-hi|Get in touch|&lt;br /&gt;
&amp;lt;b&amp;gt;With the community&amp;lt;/b&amp;gt;&lt;br /&gt;
* [https://nixos.org/ Official NixOS website]&lt;br /&gt;
* [https://nixos.org/community/#governance-teams Official Teams]&lt;br /&gt;
* [[Nix Community|Community overview]]&lt;br /&gt;
* [[Get In Touch|Chats and forums]]&lt;br /&gt;
* [[Support|Get support]]&lt;br /&gt;
* [[Get In Touch#Events|Events]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:11--&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;About the Wiki&amp;lt;/b&amp;gt;&lt;br /&gt;
* Matrix chat for Wiki contributors [https://matrix.to/#/#wiki:nixos.org #wiki:nixos.org]&lt;br /&gt;
* Email [mailto:wiki@nixos.org wiki@nixos.org] for contacting wiki.nixos.org regarding any wiki operational topics or requests&lt;br /&gt;
* [[Contributing|Contribute to wiki and NixOS]]&lt;br /&gt;
* [[Manual of Style]]&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{home:box|news|News|{{NixOS_Wiki:News}}&lt;br /&gt;
[[NixOS_Wiki:News{{!}}... all news articles &amp;amp;rarr;]]&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:10--&amp;gt;&lt;br /&gt;
{{home:box|wikipages|Special pages|3=&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[{{fullurl:Special:SpecialPages}} Overview of special pages]&amp;lt;/span&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;span class=&amp;quot;plainlinks&amp;quot;&amp;gt;[{{fullurl:Special:AllPages|hideredirects=1}} All pages of {{SERVERNAME}}]&amp;lt;/span&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[[Special:Categories|All categories of {{SERVERNAME}}]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;[{{fullurl:Special:RecentChanges|hidebots=1&amp;amp;reviewStatus=unpatrolled}} Unpatrolled changes of {{SERVERNAME}}]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=User:Pigs&amp;diff=23182</id>
		<title>User:Pigs</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=User:Pigs&amp;diff=23182"/>
		<updated>2025-06-15T18:14:08Z</updated>

		<summary type="html">&lt;p&gt;Pigs: Created page with &amp;quot;Hello,  You can see my contributions here: https://wiki.nixos.org/wiki/Special:Contributions/Pigs  My blog post is at https://pigs.dev&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Hello,&lt;br /&gt;
&lt;br /&gt;
You can see my contributions here: https://wiki.nixos.org/wiki/Special:Contributions/Pigs&lt;br /&gt;
&lt;br /&gt;
My blog post is at https://pigs.dev&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=NixOS_as_a_server&amp;diff=23180</id>
		<title>NixOS as a server</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=NixOS_as_a_server&amp;diff=23180"/>
		<updated>2025-06-15T17:38:22Z</updated>

		<summary type="html">&lt;p&gt;Pigs: Create initial page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[NixOS]] is well-suited for server deployments, offering declarative, reproducible system configurations and atomic system upgrades and rollbacks. This page provides an overview of configuring, deploying, and maintaining NixOS systems in server environments. &lt;br /&gt;
&lt;br /&gt;
== Initial setup ==&lt;br /&gt;
&lt;br /&gt;
Refer to the [[NixOS Installation Guide]] for detailed installation instructions.&lt;br /&gt;
&lt;br /&gt;
For setting up NixOS in the cloud, refer to the [[NixOS friendly hosters]].&lt;br /&gt;
&lt;br /&gt;
For guidance on defining and maintaining your system configuration, consult [[NixOS system configuration]].&lt;br /&gt;
&lt;br /&gt;
== NixOS infrastructure tools ==&lt;br /&gt;
&lt;br /&gt;
=== Deployment orchestration ===&lt;br /&gt;
&lt;br /&gt;
* [[nixos-anywhere]] - Install NixOS everywhere via SSH&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/zhaofengli/colmena Colmena] - A simple, stateless NixOS deployment tool modeled after NixOps and morph, written in Rust&lt;br /&gt;
&lt;br /&gt;
* [[Morph]] - NixOS deployment tool&lt;br /&gt;
&lt;br /&gt;
* [[Clan]] - Peer-to-peer computer management framework for NixOS&lt;br /&gt;
&lt;br /&gt;
* [[Krops]] - Lightweight  toolkit to deploy NixOS systems&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/serokell/deploy-rs deploy-rs] - A simple, multi-profile Nix-flake deploy tool&lt;br /&gt;
&lt;br /&gt;
* [[NixOps]] - Native NixOS deployment tool for cloud and virtual infrastructure (not currently recommended)&lt;br /&gt;
&lt;br /&gt;
=== Binary cache and CI ===&lt;br /&gt;
&lt;br /&gt;
See the main pages, [[Binary Cache]] and [[Continuous Integration (CI)]].&lt;br /&gt;
&lt;br /&gt;
* [https://www.cachix.org/ Cachix] - Share binaries between CI, development and deployment environments&lt;br /&gt;
&lt;br /&gt;
* [https://github.com/zhaofengli/attic Attic] - Self-hostable Nix Binary Cache server backed by an S3-compatible storage provider&lt;br /&gt;
&lt;br /&gt;
* [[Hydra]] - Tool for continuous integration testing and software release&lt;br /&gt;
&lt;br /&gt;
=== Secrets management ===&lt;br /&gt;
&lt;br /&gt;
* [[Agenix]] - commandline tool for managing secrets in your Nix configuration&lt;br /&gt;
* [https://github.com/Mic92/sops-nix sops-nix] - Atomic, declarative, and reproducible secret provisioning for NixOS based on sops&lt;br /&gt;
&lt;br /&gt;
Refer to [[Comparison of secret managing schemes]] for additional tools and in-depth comparisions&lt;br /&gt;
&lt;br /&gt;
== Common server configurations ==&lt;br /&gt;
&lt;br /&gt;
=== Web servers ===&lt;br /&gt;
&lt;br /&gt;
* [[Nginx]] - Web server that can also be used as a reverse proxy, load balancer, mail proxy and HTTP cache.&lt;br /&gt;
* [[Apache]] - Free and open-source cross-platform web server&lt;br /&gt;
* [[Caddy]] - Extensible, cross-platform, open-source web server written in Go&lt;br /&gt;
&lt;br /&gt;
=== File sharing and storage ===&lt;br /&gt;
&lt;br /&gt;
* [[NFS]] - Unix-based network file sharing&lt;br /&gt;
* [[Samba]] - Windows-compatible file and printer sharing&lt;br /&gt;
&lt;br /&gt;
=== Backup and replication ===&lt;br /&gt;
&lt;br /&gt;
* [[ZFS]] - With native snapshots and replication&lt;br /&gt;
* [[Syncthing]] - Decentralized file synchronization application&lt;br /&gt;
* [[Restic]] - Fast and secure backup program&lt;br /&gt;
* [[BorgBackup]] - Deduplicating incremental backup program for local and remote data&lt;br /&gt;
* [[Rclone]] - Command-line program that synchronizes files and directories between different cloud storage services&lt;br /&gt;
&lt;br /&gt;
=== VPN and networking ===&lt;br /&gt;
&lt;br /&gt;
* [[WireGuard]] - Fast, modern, secure VPN tunnel&lt;br /&gt;
&lt;br /&gt;
* [[OpenVPN]] - Flexible VPN implementation for secure networking&lt;br /&gt;
&lt;br /&gt;
* [[Firewall]] - NixOS has an integrated firewall based on iptables or nftables&lt;br /&gt;
&lt;br /&gt;
* [[SSH]] - secure remote administration.&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
* [[NixOS friendly hosters]] - Guides on setting up NixOS with various cloud providers&lt;br /&gt;
&lt;br /&gt;
* [[NixOS Installation Guide]]&lt;br /&gt;
&lt;br /&gt;
* [[NixOS as a desktop]] - Desktop counterpart to this article&lt;br /&gt;
&lt;br /&gt;
* [[NixOS system configuration]] &lt;br /&gt;
&lt;br /&gt;
[[Category:NixOS]]&lt;br /&gt;
[[Category:Server]]&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=Talk:Nix_ecosystem&amp;diff=23179</id>
		<title>Talk:Nix ecosystem</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=Talk:Nix_ecosystem&amp;diff=23179"/>
		<updated>2025-06-15T17:28:05Z</updated>

		<summary type="html">&lt;p&gt;Pigs: /* Is this an official term? */ Reply&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Is this an official term? ==&lt;br /&gt;
&lt;br /&gt;
I see the [[Nix ecosystem]] referenced in different parts of the wiki, however, is it an &#039;official&#039; term? Or rather, does it have a formal definition in the documentation?&lt;br /&gt;
&lt;br /&gt;
I&#039;m not necessarily proposing changing the page, rather, I am wondering whether this terminology is the best way to define the set of tools we use. To be clear, it might be, I&#039;m simply trying to construct a Nix learning journey from [[:Wikipedia:First principle|first principles]], and to figure out the most natural way all the tools we use come together. [[User:DoggoBit|DoggoBit]] ([[User talk:DoggoBit|talk]]) 23:43, 14 June 2025 (UTC)&lt;br /&gt;
&lt;br /&gt;
:I don&#039;t think it has a formal term but I do see it places such as the opening statement on https://nix.dev/index.html: &amp;quot;nix.dev is the home of official documentation for the Nix ecosystem&amp;quot;. So therefore I would take that to mean anything mentioned on nix.dev is considered to be in the Nix ecosystem. [[User:Pigs|Pigs]] ([[User talk:Pigs|talk]]) 17:21, 15 June 2025 (UTC)&lt;br /&gt;
::Maybe a looser definition is anything mentioned in https://github.com/NixOS or https://github.com/nix-community [[User:Pigs|Pigs]] ([[User talk:Pigs|talk]]) 17:28, 15 June 2025 (UTC)&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=Talk:Nix_ecosystem&amp;diff=23178</id>
		<title>Talk:Nix ecosystem</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=Talk:Nix_ecosystem&amp;diff=23178"/>
		<updated>2025-06-15T17:21:07Z</updated>

		<summary type="html">&lt;p&gt;Pigs: /* Is this an official term? */ Reply&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Is this an official term? ==&lt;br /&gt;
&lt;br /&gt;
I see the [[Nix ecosystem]] referenced in different parts of the wiki, however, is it an &#039;official&#039; term? Or rather, does it have a formal definition in the documentation?&lt;br /&gt;
&lt;br /&gt;
I&#039;m not necessarily proposing changing the page, rather, I am wondering whether this terminology is the best way to define the set of tools we use. To be clear, it might be, I&#039;m simply trying to construct a Nix learning journey from [[:Wikipedia:First principle|first principles]], and to figure out the most natural way all the tools we use come together. [[User:DoggoBit|DoggoBit]] ([[User talk:DoggoBit|talk]]) 23:43, 14 June 2025 (UTC)&lt;br /&gt;
&lt;br /&gt;
:I don&#039;t think it has a formal term but I do see it places such as the opening statement on https://nix.dev/index.html: &amp;quot;nix.dev is the home of official documentation for the Nix ecosystem&amp;quot;. So therefore I would take that to mean anything mentioned on nix.dev is considered to be in the Nix ecosystem. [[User:Pigs|Pigs]] ([[User talk:Pigs|talk]]) 17:21, 15 June 2025 (UTC)&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=Template_talk:NixOS_Manual&amp;diff=23177</id>
		<title>Template talk:NixOS Manual</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=Template_talk:NixOS_Manual&amp;diff=23177"/>
		<updated>2025-06-15T17:00:34Z</updated>

		<summary type="html">&lt;p&gt;Pigs: /* {{Manual }}does not work for nixos manual */ Reply&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== {{{{:manual}} }}does not work for nixos manual ==&lt;br /&gt;
&lt;br /&gt;
Currently, {{:manual}} only links to https://nix.dev, the nix language reference material and does not have capabilities to link to https://nixos.org/manual/nixos where the nixos manual lives. &lt;br /&gt;
&lt;br /&gt;
Until {{:manual}} can link to the nixos manual, I don&#039;t think marking this page for removal is appropriate. [[User:Pigs|Pigs]] ([[User talk:Pigs|talk]]) 06:31, 9 June 2025 (UTC)&lt;br /&gt;
&lt;br /&gt;
:Oh yeah, that is a given. I will improve {{tl|manual}} before proceeding. Thanks for pointing it out! [[User:DoggoBit|DoggoBit]] ([[User talk:DoggoBit|talk]]) 13:26, 9 June 2025 (UTC)&lt;br /&gt;
:I have updated {{tl|manual}}, it should now support all 3 use cases, as well as subsections within the Nix reference manual. Would appreciate a double check to make sure I didn&#039;t miss anything. [[User:DoggoBit|DoggoBit]] ([[User talk:DoggoBit|talk]]) 11:35, 15 June 2025 (UTC)&lt;br /&gt;
::Looks good to me [[User:Pigs|Pigs]] ([[User talk:Pigs|talk]]) 17:00, 15 June 2025 (UTC)&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=Swap&amp;diff=23176</id>
		<title>Swap</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=Swap&amp;diff=23176"/>
		<updated>2025-06-15T16:38:28Z</updated>

		<summary type="html">&lt;p&gt;Pigs: /* Zswap swap cache */ add note of needing to enable systemd for using lz4&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Configuration]]&lt;br /&gt;
&lt;br /&gt;
Swap provides additional virtual memory by extending physical RAM. This can be accomplished by using space on disk, such as [[#Swap file|swap file]] or [[#Swap partition|swap partition]], or through compression based methods like [[#Zram swap|zram]]. Additionally, [[#Zswap swap cache|zswap]] can act as a RAM-based compressed cache sitting in front of a traditional disk-based swap device.&lt;br /&gt;
&lt;br /&gt;
= Configuration =&lt;br /&gt;
&lt;br /&gt;
The following sections describe how to configure and manage swap on NixOS.&lt;br /&gt;
&lt;br /&gt;
To check your current swap setup and usage, you can use the following command: &amp;lt;code&amp;gt;swapon --show&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{note| &amp;lt;code&amp;gt;nixos-generate-config&amp;lt;/code&amp;gt; does not automatically generate a &amp;lt;code&amp;gt;swapDevices&amp;lt;/code&amp;gt; entry if your system uses a swap file or &amp;lt;code&amp;gt;/dev/zram&amp;lt;/code&amp;gt; for swap. For details, see the [https://github.com/NixOS/nixpkgs/pull/63083 discussion on GitHub]}}&lt;br /&gt;
&lt;br /&gt;
{{note|It&#039;s generally recommended to use either zram or zswap, but not both simultaneously, as they serve overlapping roles and may lead to suboptimal memory management behavior.}}&lt;br /&gt;
&lt;br /&gt;
== Swap file ==&lt;br /&gt;
&lt;br /&gt;
A swap file provides swap space using a regular file on your filesystem, offering greater flexibility compared to a dedicated swap partition.&lt;br /&gt;
&lt;br /&gt;
To add a swap file in NixOS, add the following:&lt;br /&gt;
&lt;br /&gt;
{{file|/etc/nixos/configuration.nix|nix|&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
swapDevices = [{&lt;br /&gt;
  device = &amp;quot;/var/lib/swapfile&amp;quot;;&lt;br /&gt;
  size = 16*1024; # 16 GB&lt;br /&gt;
}];&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
This will create a 16GB swapfile at &amp;lt;code&amp;gt;/var/lib/swapfile&amp;lt;/code&amp;gt;. The &amp;lt;code&amp;gt;size&amp;lt;/code&amp;gt; value [https://search.nixos.org/options?show=swapDevices.*.size is specified in megabytes]&lt;br /&gt;
&lt;br /&gt;
== Swap partition ==&lt;br /&gt;
&lt;br /&gt;
Swap partitions are typically created during the initial disk partitioning phase of a NixOS installation. For instructions on creating swap partitions, see the relevant NixOS manual sections for [https://nixos.org/manual/nixos/stable/#sec-installation-manual-partitioning-UEFI UEFI]/[https://nixos.org/manual/nixos/stable/#sec-installation-manual-partitioning-MBR MBR] partition schemes and [https://nixos.org/manual/nixos/stable/#sec-installation-manual-partitioning-formatting formatting].&lt;br /&gt;
&lt;br /&gt;
== Zram swap ==&lt;br /&gt;
&lt;br /&gt;
Zram is a kernel module for creating a compressed block device in RAM.&lt;br /&gt;
&lt;br /&gt;
{{file|/etc/nixos/configuration.nix|nix|&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
zramSwap.enable = true; # Creates a zram block device and uses it as a swap device&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
It is an alternative or complementary approach to swap disks, suitable for systems with enough RAM. In the event the system needs to swap it will move uncompressed RAM contents into the compressed area, saving RAM space while effectively increasing the available RAM at the cost of computational power for compression and decompression.&lt;br /&gt;
&lt;br /&gt;
See [https://search.nixos.org/options?query=zramSwap zramSwap] for a full list of available options and their descriptions.&lt;br /&gt;
&lt;br /&gt;
=== Zram writeback ===&lt;br /&gt;
&lt;br /&gt;
Zram supports writeback functionality, allowing idle or incompressible pages to be moved to a backing storage device rather than keeping it in memory. Currently, writeback can only use block storage devices (such as partitions) and does not support swap files. The backing partition must be manually created first, but does not require formatting.&lt;br /&gt;
&lt;br /&gt;
An example configuration:&lt;br /&gt;
&lt;br /&gt;
{{file|/etc/nixos/configuration.nix|nix|&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
zramSwap = {&lt;br /&gt;
  enable = true; &lt;br /&gt;
  writebackDevice = &amp;quot;/dev/sda1&amp;quot;&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
To verify the block storage device is being used:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cat /sys/block/zram0/backing_dev&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Zswap swap cache == &lt;br /&gt;
&lt;br /&gt;
[https://docs.kernel.org/admin-guide/mm/zswap.html Zswap] is a compress RAM cache for swap pages. It acts as a middle layer between system memory and a traditional disk-based swap device, storing compressed pages in RAM before optionally writing them out to disk-based swap if necessary.&lt;br /&gt;
&lt;br /&gt;
Unlike zram, zswap requires a disk-based swap device to back it.&lt;br /&gt;
&lt;br /&gt;
Zswap is controlled by kernel parameters and can be enabled in your NixOS configuration by setting appropriate options through &amp;lt;code&amp;gt;boot.kernelParams&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{file|/etc/nixos/configuration.nix|nix|&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
  boot.kernelParams = [&lt;br /&gt;
    &amp;quot;zswap.enabled=1&amp;quot; # enables zswap&lt;br /&gt;
    &amp;quot;zswap.compressor=lz4&amp;quot; # compression algorithm&lt;br /&gt;
    &amp;quot;zswap.max_pool_percent=20&amp;quot; # maximum percentage of RAM that zswap is allowed to use&lt;br /&gt;
  ];&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{note|If you use the &amp;lt;code&amp;gt;lz4&amp;lt;/code&amp;gt; algorithm, you will also need to set {{nixos:option|boot.initrd.systemd.enable}} to true}}&lt;br /&gt;
&lt;br /&gt;
You can verify zswap&#039;s runtime status via &amp;lt;code&amp;gt;cat /sys/module/zswap/parameters/enabled&amp;lt;/code&amp;gt; and inspect usage statistics with &amp;lt;code&amp;gt;# grep -r . /sys/kernel/debug/zswap/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Disable swap ==&lt;br /&gt;
&lt;br /&gt;
To remove all swap devices from NixOS, set the following to remove the swap partition or file from being included in &amp;lt;code&amp;gt;/etc/fstab&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
swapDevices = lib.mkForce [ ];&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you are using GPT partitioning tables, &amp;lt;code&amp;gt;systemd-gpt-auto-generator(8)&amp;lt;/code&amp;gt; will still mount your swap partition automatically. You must therefore turn on attribute 63 on your partition in the partition table. This can be done with gptfdisk or similar:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
gdisk /dev/sda&lt;br /&gt;
x&lt;br /&gt;
a&lt;br /&gt;
&amp;lt;partition number&amp;gt;&lt;br /&gt;
63&lt;br /&gt;
&amp;lt;enter&amp;gt;&lt;br /&gt;
w&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Tips and Tricks =&lt;br /&gt;
&lt;br /&gt;
== Encrypt swap with random key ==&lt;br /&gt;
&lt;br /&gt;
Swap can be automatically encrypted with a new key on every boot.  This can be used to simplify certain disk layouts, such as securing a swap file on a filesystem partition without  an encryption container (such as LUKS).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
swapDevices = [{&lt;br /&gt;
  device = &amp;quot;/dev/sdXY&amp;quot;;&lt;br /&gt;
  randomEncryption.enable = true; &lt;br /&gt;
}];&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Adjusting swap usage behaviour ==&lt;br /&gt;
&lt;br /&gt;
[https://docs.kernel.org/admin-guide/sysctl/vm.html#swappiness Swappiness] controls how aggressibely swap space is used. By default, Linux uses a swappiness value of 60. Higher values will make the kernel prefer swapping out idle processes sooner. Conversely lower values will try to avoid swapping as much as possible, keeping processes in RAM unless absolutely necessary. An optimal value is workload dependent and will will require experimentation.&lt;br /&gt;
&lt;br /&gt;
{{file|/etc/nixos/configuration.nix|nix|&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
boot.kernel.sysctl = {&lt;br /&gt;
  &amp;quot;vm.swappiness&amp;quot; = 10;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
You can see your current swappiness level by &amp;lt;code&amp;gt;cat /proc/sys/vm/swappiness&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== ZFS and swap ==&lt;br /&gt;
&lt;br /&gt;
OpenZFS does not support swap on zvols nor do they support swap files on a ZFS dataset.&lt;br /&gt;
&lt;br /&gt;
Instead you should set up a swap partition or swap file on a non-ZFS filesystem.&amp;lt;ref&amp;gt;https://utcc.utoronto.ca/~cks/space/blog/solaris/ZFSForSwapMyViews&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using swap files on Btrfs ==&lt;br /&gt;
&lt;br /&gt;
For Btrfs file system-specific considerations, see the [[Btrfs#Swap file|Btrfs swap file section]].&lt;br /&gt;
&lt;br /&gt;
== Swapspace ==&lt;br /&gt;
&lt;br /&gt;
[https://github.com/Tookmund/Swapspace Swapspace] is a dynamic swap space manager for GNU/Linux. i.e. it allows unused disk space to be utilised as swap to handle the occasional memory-intensive task, and frees the disk space once done.&lt;br /&gt;
&lt;br /&gt;
Enable it via &amp;lt;code&amp;gt;services.swapspace.enable = true;&amp;lt;/code&amp;gt; in your nixos configuration. And after switching, check that &amp;lt;code&amp;gt;systemctl status swapspace.service&amp;lt;/code&amp;gt; is green, that&#039;s all, swapspace will auto manage swap for you.&lt;br /&gt;
&lt;br /&gt;
See all the options it supports here, [https://search.nixos.org/options?query=swapspace search.nixos.org]&lt;br /&gt;
&lt;br /&gt;
You can also use zramSwap along with this service.&lt;br /&gt;
&lt;br /&gt;
See your active swap partitions/files with &amp;lt;code&amp;gt;swapon&amp;lt;/code&amp;gt;. For eg.&lt;br /&gt;
{{warning|Do not run the following without swapspace active + more than 34GB free disk space (assuming 8GB ram) OR without 42GB+ ram to spare.}}&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
# Read the WARNING above, and adjust 2, 20GB according to your free space&lt;br /&gt;
$ # nix shell nixpkgs#stress.out -c stress --vm 2 --vm-bytes 20G&lt;br /&gt;
$ swapon&lt;br /&gt;
NAME                 TYPE       SIZE  USED PRIO&lt;br /&gt;
/dev/zram0           partition 13.8G  2.6G    5&lt;br /&gt;
/var/lib/swapspace/1 file       5.2G 59.2M   -2&lt;br /&gt;
/var/lib/swapspace/2 file       6.1G 56.4M   -3&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=Flakes&amp;diff=23003</id>
		<title>Flakes</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=Flakes&amp;diff=23003"/>
		<updated>2025-06-14T20:15:56Z</updated>

		<summary type="html">&lt;p&gt;Pigs: add citation to lock file and showing flake inputs&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;languages /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:1--&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Nix flakes&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
A flake is a directory which directly contains a Nix file called &amp;lt;code&amp;gt;flake.nix&amp;lt;/code&amp;gt;, 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 &amp;lt;code&amp;gt;github:NixOS/nixpkgs&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
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}}&lt;br /&gt;
&lt;br /&gt;
=== Enabling flakes ===&lt;br /&gt;
&lt;br /&gt;
====Enable flakes temporarily==== &amp;lt;!--T:5--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:6--&amp;gt;&lt;br /&gt;
When using any [[Nix command|&amp;lt;code&amp;gt;nix&amp;lt;/code&amp;gt; command]], add the following command-line options:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
 --experimental-features &#039;nix-command flakes&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Enable flakes permanently in NixOS==== &amp;lt;!--T:7--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:8--&amp;gt;&lt;br /&gt;
Add the following to the [[Overview_of_the_NixOS_Linux_distribution#Declarative_Configuration system configuration |NixOS configuration]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxHighlight lang=nix&amp;gt;&lt;br /&gt;
  nix.settings.experimental-features = [ &amp;quot;nix-command&amp;quot; &amp;quot;flakes&amp;quot; ];&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====With Home Manager==== &amp;lt;!--T:10--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:11--&amp;gt;&lt;br /&gt;
Add the following to your [[Home Manager|home manager]] config:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
  nix.settings.experimental-features = [ &amp;quot;nix-command&amp;quot; &amp;quot;flakes&amp;quot; ];&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Other Distros, without Home Manager==== &amp;lt;!--T:13--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:14--&amp;gt;&lt;br /&gt;
{{Note | The  [https://github.com/DeterminateSystems/nix-installer Determinate Nix Installer] enables flakes by default.}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:15--&amp;gt;&lt;br /&gt;
Add the following to &amp;lt;code&amp;gt;~/.config/nix/nix.conf&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;/etc/nix/nix.conf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxHighlight lang=text&amp;gt;&lt;br /&gt;
experimental-features = nix-command flakes&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Basic Usage of Flake=== &amp;lt;!--T:17--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:20--&amp;gt;&lt;br /&gt;
{{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]].}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:146--&amp;gt;&lt;br /&gt;
{{Note | For flakes in [[git]] repositories, only files in the working tree will be copied to the store.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:22--&amp;gt;&lt;br /&gt;
Therefore, if you use &amp;lt;code&amp;gt;git&amp;lt;/code&amp;gt; for your flake, ensure to &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; any project files after you first create them.}}&lt;br /&gt;
&lt;br /&gt;
====Generate flake.nix file==== &amp;lt;!--T:24--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:25--&amp;gt;&lt;br /&gt;
To initialize a flake, run the following flake command in the project directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
$ nix flake init&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Common structure====&lt;br /&gt;
&lt;br /&gt;
The above command will provide a very simple flake file looking like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxHighlight lang=nix&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  description = &amp;quot;A very basic flake&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
  inputs = {&lt;br /&gt;
    nixpkgs.url = &amp;quot;github:nixos/nixpkgs?ref=nixos-unstable&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
&lt;br /&gt;
  outputs = { self, nixpkgs }: {&lt;br /&gt;
&lt;br /&gt;
    packages.x86_64-linux.hello = nixpkgs.legacyPackages.x86_64-linux.hello;&lt;br /&gt;
&lt;br /&gt;
    packages.x86_64-linux.default = self.packages.x86_64-linux.hello;&lt;br /&gt;
&lt;br /&gt;
  };&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will then be able to build this flake with &amp;lt;code&amp;gt;nix build&amp;lt;/code&amp;gt; and run it with &amp;lt;code&amp;gt;nix run&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{note|Flakes force you to specify a program for each supported architecture. To avoid this, refer to [[#Defining a flake for multiple architectures]] section of the wiki.}}&lt;br /&gt;
&lt;br /&gt;
==== The nix flakes command ==== &amp;lt;!--T:64--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:65--&amp;gt;&lt;br /&gt;
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}}.&lt;br /&gt;
&lt;br /&gt;
This flake produces a single flake output &amp;lt;code&amp;gt;packages&amp;lt;/code&amp;gt;. And within that, &amp;lt;code&amp;gt;x86_64-linux&amp;lt;/code&amp;gt; is a system-specifc attribute set. And within that, two package [[derivations]] &amp;lt;code&amp;gt;default&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;hello&amp;lt;/code&amp;gt;. 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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
$ nix flake show&lt;br /&gt;
└───packages&lt;br /&gt;
    └───x86_64-linux&lt;br /&gt;
        ├───default: package &#039;hello-2.12.2&#039;&lt;br /&gt;
        └───hello: package &#039;hello-2.12.2&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Development shells ====&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;code&amp;gt;devShell&amp;lt;/code&amp;gt; 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 &amp;lt;code&amp;gt;nix-shell&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  description = &amp;quot;Example flake with a devShell&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
  inputs.nixpkgs.url = &amp;quot;github:nixos/nixpkgs?ref=nixos-unstable&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
  outputs = { self, nixpkgs}:&lt;br /&gt;
    let&lt;br /&gt;
      system = &amp;quot;x86_64-linux&amp;quot;;&lt;br /&gt;
      pkgs = import nixpkgs { inherit system; };&lt;br /&gt;
    in {&lt;br /&gt;
      devShells.x86_64-linux.default = pkgs.mkShell {&lt;br /&gt;
        buildInputs = with pkgs; [&lt;br /&gt;
          hello&lt;br /&gt;
        ];&lt;br /&gt;
        shellHook = &#039;&#039;&lt;br /&gt;
          echo &amp;quot;Welcome to the devShell!&amp;quot;&lt;br /&gt;
        &#039;&#039;;&lt;br /&gt;
      };&lt;br /&gt;
    };&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To enter the development shell environment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
$ nix develop&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{note|You don’t need to define a devShell to enter a development shell using nix develop.&lt;br /&gt;
If no devShell is defined, nix develop will drop you into an environment containing the default build dependencies of the flake (if any).}}&lt;br /&gt;
&lt;br /&gt;
==== Build specific attributes in a flake repository ==== &amp;lt;!--T:102--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:103--&amp;gt;&lt;br /&gt;
Running &amp;lt;code&amp;gt;nix build&amp;lt;/code&amp;gt; will look in the &amp;lt;code&amp;gt;legacyPackages&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;packages&amp;lt;/code&amp;gt; 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 &amp;lt;code&amp;gt;nix build .#&amp;lt;attr&amp;gt;&amp;lt;/code&amp;gt;. In the example above, if you wanted to build the &amp;lt;code&amp;gt;packages.x86_64-linux.hello&amp;lt;/code&amp;gt; attribute, run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxHighlight lang=console&amp;gt;&lt;br /&gt;
$ nix build .#hello&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Likewise, you can specify an attribute with the run command: &amp;lt;code&amp;gt;nix run .#hello&amp;lt;/code&amp;gt; and the develop command: &amp;lt;code&amp;gt;nix develop .#hello&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Flake schema == &amp;lt;!--T:27--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:28--&amp;gt;&lt;br /&gt;
The flake.nix file is a Nix file but that has special restrictions (more on that later).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:29--&amp;gt;&lt;br /&gt;
It has 4 top-level attributes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:30--&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;description&amp;lt;/code&amp;gt; is a string describing the flake.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:147--&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;inputs&amp;lt;/code&amp;gt; is an attribute set of all the dependencies of the flake. The schema is described below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:148--&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;outputs&amp;lt;/code&amp;gt; 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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:149--&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;nixConfig&amp;lt;/code&amp;gt; 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&#039;s nix experience by adding flake-specific configuration, such as a [[Binary Cache|binary cache]].&lt;br /&gt;
&lt;br /&gt;
=== Input schema === &amp;lt;!--T:31--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:32--&amp;gt;&lt;br /&gt;
[https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake.html#flake-inputs The nix flake inputs manual].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:150--&amp;gt;&lt;br /&gt;
[https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake.html#flake-references The nix flake references manual].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:33--&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:34--&amp;gt;&lt;br /&gt;
[[Nixpkgs]] can be defined using the following code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;inputs.nixpkgs.url = &amp;quot;github:NixOS/nixpkgs/&amp;lt;branch name&amp;gt;&amp;quot;;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Nixpkgs can alternatively also point to an url cached by the NixOS organization:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;inputs.nixpkgs.url = &amp;quot;&amp;lt;nowiki&amp;gt;https://nixos.org/channels/nixpkgs-unstable/nixexprs.tar.xz&amp;lt;/nowiki&amp;gt;&amp;quot;;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example the input would point to the `nixpkgs-unstable` channel.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:36--&amp;gt;&lt;br /&gt;
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&#039;s on GitHub is unnecessary.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:37--&amp;gt;&lt;br /&gt;
For example, adding [[Hyprland]] as an input would look something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;inputs.hyprland.url = &amp;quot;github:hyprwm/Hyprland&amp;quot;;&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:39--&amp;gt;&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;inputs.hyprland.inputs.nixpkgs.follows = &amp;quot;nixpkgs&amp;quot;;&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:41--&amp;gt;&lt;br /&gt;
Using curly brackets({}), we can shorten all of this and put it in a table. The code will look something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
inputs = {&lt;br /&gt;
  nixpkgs.url = &amp;quot;github:NixOS/nixpkgs/&amp;lt;branch name&amp;gt;&amp;quot;;&lt;br /&gt;
  hyprland = {&lt;br /&gt;
    url = &amp;quot;github:hyprwm/Hyprland&amp;quot;;&lt;br /&gt;
    inputs.nixpkgs.follows = &amp;quot;nixpkgs&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, Git submodules in package &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt;&#039;s won&#039;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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
  inputs.self.submodules = true;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Output schema === &amp;lt;!--T:42--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:151--&amp;gt;&lt;br /&gt;
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].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:43--&amp;gt;&lt;br /&gt;
Once the inputs are resolved, they&#039;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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:44--&amp;gt;&lt;br /&gt;
Where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:45--&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;&amp;lt;system&amp;gt;&amp;lt;/code&amp;gt; is something like &amp;quot;x86_64-linux&amp;quot;, &amp;quot;aarch64-linux&amp;quot;, &amp;quot;i686-linux&amp;quot;, &amp;quot;x86_64-darwin&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:152--&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;&amp;lt;name&amp;gt;&amp;lt;/code&amp;gt; is an attribute name like &amp;quot;hello&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:153--&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;&amp;lt;flake&amp;gt;&amp;lt;/code&amp;gt; is a flake name like &amp;quot;nixpkgs&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:154--&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;&amp;lt;store-path&amp;gt;&amp;lt;/code&amp;gt; is a &amp;lt;code&amp;gt;/nix/store..&amp;lt;/code&amp;gt; path&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxHighlight lang=nix&amp;gt;&lt;br /&gt;
{ self, ... }@inputs:&lt;br /&gt;
{&lt;br /&gt;
  # Executed by `nix flake check`&lt;br /&gt;
  checks.&amp;quot;&amp;lt;system&amp;gt;&amp;quot;.&amp;quot;&amp;lt;name&amp;gt;&amp;quot; = derivation;&lt;br /&gt;
  # Executed by `nix build .#&amp;lt;name&amp;gt;`&lt;br /&gt;
  packages.&amp;quot;&amp;lt;system&amp;gt;&amp;quot;.&amp;quot;&amp;lt;name&amp;gt;&amp;quot; = derivation;&lt;br /&gt;
  # Executed by `nix build .`&lt;br /&gt;
  packages.&amp;quot;&amp;lt;system&amp;gt;&amp;quot;.default = derivation;&lt;br /&gt;
  # Executed by `nix run .#&amp;lt;name&amp;gt;`&lt;br /&gt;
  apps.&amp;quot;&amp;lt;system&amp;gt;&amp;quot;.&amp;quot;&amp;lt;name&amp;gt;&amp;quot; = {&lt;br /&gt;
    type = &amp;quot;app&amp;quot;;&lt;br /&gt;
    program = &amp;quot;&amp;lt;store-path&amp;gt;&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
  # Executed by `nix run . -- &amp;lt;args?&amp;gt;`&lt;br /&gt;
  apps.&amp;quot;&amp;lt;system&amp;gt;&amp;quot;.default = { type = &amp;quot;app&amp;quot;; program = &amp;quot;...&amp;quot;; };&lt;br /&gt;
&lt;br /&gt;
  # Formatter (alejandra, nixfmt or nixpkgs-fmt)&lt;br /&gt;
  formatter.&amp;quot;&amp;lt;system&amp;gt;&amp;quot; = derivation;&lt;br /&gt;
  # Used for nixpkgs packages, also accessible via `nix build .#&amp;lt;name&amp;gt;`&lt;br /&gt;
  legacyPackages.&amp;quot;&amp;lt;system&amp;gt;&amp;quot;.&amp;quot;&amp;lt;name&amp;gt;&amp;quot; = derivation;&lt;br /&gt;
  # Overlay, consumed by other flakes&lt;br /&gt;
  overlays.&amp;quot;&amp;lt;name&amp;gt;&amp;quot; = final: prev: { };&lt;br /&gt;
  # Default overlay&lt;br /&gt;
  overlays.default = final: prev: { };&lt;br /&gt;
  # Nixos module, consumed by other flakes&lt;br /&gt;
  nixosModules.&amp;quot;&amp;lt;name&amp;gt;&amp;quot; = { config, ... }: { options = {}; config = {}; };&lt;br /&gt;
  # Default module&lt;br /&gt;
  nixosModules.default = { config, ... }: { options = {}; config = {}; };&lt;br /&gt;
  # Used with `nixos-rebuild switch --flake .#&amp;lt;hostname&amp;gt;`&lt;br /&gt;
  # nixosConfigurations.&amp;quot;&amp;lt;hostname&amp;gt;&amp;quot;.config.system.build.toplevel must be a derivation&lt;br /&gt;
  nixosConfigurations.&amp;quot;&amp;lt;hostname&amp;gt;&amp;quot; = {};&lt;br /&gt;
  # Used by `nix develop .#&amp;lt;name&amp;gt;`&lt;br /&gt;
  devShells.&amp;quot;&amp;lt;system&amp;gt;&amp;quot;.&amp;quot;&amp;lt;name&amp;gt;&amp;quot; = derivation;&lt;br /&gt;
  # Used by `nix develop`&lt;br /&gt;
  devShells.&amp;quot;&amp;lt;system&amp;gt;&amp;quot;.default = derivation;&lt;br /&gt;
  # Hydra build jobs&lt;br /&gt;
  hydraJobs.&amp;quot;&amp;lt;attr&amp;gt;&amp;quot;.&amp;quot;&amp;lt;system&amp;gt;&amp;quot; = derivation;&lt;br /&gt;
  # Used by `nix flake init -t &amp;lt;flake&amp;gt;#&amp;lt;name&amp;gt;`&lt;br /&gt;
  templates.&amp;quot;&amp;lt;name&amp;gt;&amp;quot; = {&lt;br /&gt;
    path = &amp;quot;&amp;lt;store-path&amp;gt;&amp;quot;;&lt;br /&gt;
    description = &amp;quot;template description goes here?&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
  # Used by `nix flake init -t &amp;lt;flake&amp;gt;`&lt;br /&gt;
  templates.default = { path = &amp;quot;&amp;lt;store-path&amp;gt;&amp;quot;; description = &amp;quot;&amp;quot;; };&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:48--&amp;gt;&lt;br /&gt;
You can also define additional arbitrary attributes, but these are the outputs that Nix knows about.&lt;br /&gt;
&lt;br /&gt;
== Core usage patterns ==&lt;br /&gt;
&lt;br /&gt;
=== Making your evaluations pure === &amp;lt;!--T:60--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:61--&amp;gt;&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:62--&amp;gt;&lt;br /&gt;
* {{Nixpkgs Manual|name=fetchurl|anchor=#sec-pkgs-fetchers-fetchurl-inputs}} and {{Nixpkgs Manual|name=fetchzip|anchor=#sec-pkgs-fetchers-fetchzip-inputs}} require a &amp;lt;code&amp;gt;sha256&amp;lt;/code&amp;gt; argument to be considered pure.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:156--&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;builtins.currentSystem&amp;lt;/code&amp;gt; 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.&lt;br /&gt;
&lt;br /&gt;
*  &amp;lt;code&amp;gt;builtins.getEnv&amp;lt;/code&amp;gt; is also impure. Avoid reading from environment variables and likewise, do not reference files outside of the flake&#039;s directory.&lt;br /&gt;
&lt;br /&gt;
=== Defining a flake for multiple architectures ===&lt;br /&gt;
&lt;br /&gt;
Flakes force you to specify a program for each supported architecture. An example below shows how to write a flake that targets multiple architectures.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  description = &amp;quot;A flake targeting multiple architectures&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
  inputs = {&lt;br /&gt;
    nixpkgs.url = &amp;quot;github:nixos/nixpkgs?ref=nixos-unstable&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
&lt;br /&gt;
  outputs = { self, nixpkgs }: let&lt;br /&gt;
    systems = [ &amp;quot;x86_64-linux&amp;quot; &amp;quot;aarch64-linux&amp;quot; ];&lt;br /&gt;
    forAllSystems = f: builtins.listToAttrs (map (system: {&lt;br /&gt;
      name = system;&lt;br /&gt;
      value = f system;&lt;br /&gt;
    }) systems);&lt;br /&gt;
  in {&lt;br /&gt;
    packages = forAllSystems (system: let&lt;br /&gt;
      pkgs = nixpkgs.legacyPackages.${system};&lt;br /&gt;
    in {&lt;br /&gt;
      hello = pkgs.hello;&lt;br /&gt;
      default = pkgs.hello;&lt;br /&gt;
    });&lt;br /&gt;
  };&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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]]&lt;br /&gt;
&lt;br /&gt;
=== Using overlays === &lt;br /&gt;
&lt;br /&gt;
To use [[Overlays]] with flakes, refer to [[Overlays#In a Nix flake]] page.&lt;br /&gt;
&lt;br /&gt;
=== Enable unfree software === &amp;lt;!--T:129--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To allow for [[Unfree software|unfree software]] in a flake project, you need to explicitly allow it by setting &amp;lt;code&amp;gt;config.allowUnree = true;&amp;lt;/code&amp;gt; when importing Nixpkgs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  inputs.nixpkgs.url = &amp;quot;github:nixos/nixpkgs?ref=nixos-unstable&amp;quot;;&lt;br /&gt;
  outputs = { self, nixpkgs, flake-compat }:&lt;br /&gt;
    let&lt;br /&gt;
      system = &amp;quot;x86_64-linux&amp;quot;;&lt;br /&gt;
      pkgs = import nixpkgs { inherit system; config.allowUnfree = true;};&lt;br /&gt;
    in {&lt;br /&gt;
      ...&lt;br /&gt;
    };&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
== NixOS configuration with flakes ==&lt;br /&gt;
&lt;br /&gt;
It is possible to manage a [[NixOS]] system configuration using flakes, gaining the benefits of reproducible, declarative inputs and streamlined updates.&lt;br /&gt;
&lt;br /&gt;
For details and examples, see [[NixOS system configuration#Defining NixOS as a flake]].&lt;br /&gt;
&lt;br /&gt;
== Development tricks == &amp;lt;!--T:131--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Automatically switch nix shells with direnv === &amp;lt;!--T:97--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:98--&amp;gt;&lt;br /&gt;
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].&lt;br /&gt;
&lt;br /&gt;
=== Pushing Flakes to Cachix === &amp;lt;!--T:99--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
https://docs.cachix.org/pushing#flakes&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Flake support in projects without flakes === &amp;lt;!--T:50--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:51--&amp;gt;&lt;br /&gt;
The [https://github.com/edolstra/flake-compat flake-compat] library provides a compatibility layer that allows projects using traditional &amp;lt;code&amp;gt;default.nix&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;shell.nix&amp;lt;/code&amp;gt; files to operate with flakes. For more details and usage examples, see the [[Flake Compat]] page.&lt;br /&gt;
&lt;br /&gt;
Another project that allows consuming flakes from non-flake projects is [https://github.com/fricklerhandwerk/flake-inputs flake-inputs].&lt;br /&gt;
&lt;br /&gt;
=== Accessing flakes from Nix expressions === &amp;lt;!--T:58--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:59--&amp;gt;&lt;br /&gt;
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 &amp;lt;code&amp;gt;(builtins.getFlake &amp;quot;/path/to/directory&amp;quot;).packages.x86_64-linux.default&amp;lt;/code&amp;gt;, where &#039;directory&#039; is the directory that contains your &amp;lt;code&amp;gt;flake.nix&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Efficiently build multiple flake outputs ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:101--&amp;gt;&lt;br /&gt;
To push &#039;&#039;all&#039;&#039; flake outputs automatically, checkout [https://github.com/srid/devour-flake#usage devour-flake].&lt;br /&gt;
&lt;br /&gt;
=== Build a package added in a PR === &amp;lt;!--T:161--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxHighlight&amp;gt;&lt;br /&gt;
nix build github:nixos/nixpkgs?ref=pull/&amp;lt;PR_NUMBER&amp;gt;/head#&amp;lt;PACKAGE&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:162--&amp;gt;&lt;br /&gt;
this allows building a package that has not yet been added to nixpkgs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:132--&amp;gt;&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxHighlight&amp;gt;&lt;br /&gt;
git fetch upstream pull/&amp;lt;PR_NUMBER&amp;gt;/head &amp;amp;&amp;amp; git checkout FETCH_HEAD &amp;amp;&amp;amp; nix build .#PACKAGE&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:163--&amp;gt;&lt;br /&gt;
this allows building a package that has not yet been added to nixpkgs.&lt;br /&gt;
&lt;br /&gt;
=== How to add a file locally in git but not include it in commits === &amp;lt;!--T:164--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:133--&amp;gt;&lt;br /&gt;
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 &amp;lt;code&amp;gt;extra/flake.nix&amp;lt;/code&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxHighlight&amp;gt;&lt;br /&gt;
git add --intent-to-add extra/flake.nix&lt;br /&gt;
git update-index --skip-worktree --assume-unchanged extra/flake.nix&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rapid iteration of a direct dependency === &amp;lt;!--T:135--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:165--&amp;gt;&lt;br /&gt;
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 &amp;lt;code&amp;gt;nix develop --redirect &amp;lt;flake&amp;gt; &amp;lt;directory&amp;gt;&amp;lt;/code&amp;gt; command allows you to provide a mutable dependency to your shell as if it were built by Nix.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:136--&amp;gt;&lt;br /&gt;
Consider a situation where your executable, &amp;lt;code&amp;gt;consumexe&amp;lt;/code&amp;gt;, depends on a library, &amp;lt;code&amp;gt;libdep&amp;lt;/code&amp;gt;. You&#039;re trying to work on both at the same time, where changes to &amp;lt;code&amp;gt;libdep&amp;lt;/code&amp;gt; are reflected in real time for &amp;lt;code&amp;gt;consumexe&amp;lt;/code&amp;gt;. This workflow can be achieved like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxHighlight lang=bash&amp;gt;&lt;br /&gt;
cd ~/libdep-src-checkout/&lt;br /&gt;
nix develop # Or `nix-shell` if applicable.&lt;br /&gt;
export prefix=&amp;quot;./install&amp;quot; # configure nix to install it here&lt;br /&gt;
buildPhase   # build it like nix does&lt;br /&gt;
installPhase # install it like nix does&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:166--&amp;gt;&lt;br /&gt;
Now that you&#039;ve built the dependency, &amp;lt;code&amp;gt;consumexe&amp;lt;/code&amp;gt; can take it as an input. &#039;&#039;&#039;In another terminal&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxHighlight lang=bash&amp;gt;&lt;br /&gt;
cd ~/consumexe-src-checkout/&lt;br /&gt;
nix develop --redirect libdep ~/libdep-src-checkout/install&lt;br /&gt;
echo $buildInputs | tr &amp;quot; &amp;quot; &amp;quot;\n&amp;quot; | grep libdep&lt;br /&gt;
# Output should show ~/libdep-src-checkout/ so you know it worked&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:167--&amp;gt;&lt;br /&gt;
If Nix warns you that your redirected flake isn&#039;t actually used as an input to the evaluated flake, try using the &amp;lt;code&amp;gt;--inputs-from .&amp;lt;/code&amp;gt; flag. If all worked well you should be able to &amp;lt;code&amp;gt;buildPhase &amp;amp;&amp;amp; installPhase&amp;lt;/code&amp;gt; when the dependency changes and rebuild your consumer with the new version &#039;&#039;without&#039;&#039; exiting the development shell.&lt;br /&gt;
&lt;br /&gt;
== See also == &amp;lt;!--T:138--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Official sources ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:139--&amp;gt;&lt;br /&gt;
* [https://nix.dev/concepts/flakes Flakes] - nix.dev&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:176--&amp;gt;&lt;br /&gt;
* [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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:178--&amp;gt;&lt;br /&gt;
* [https://github.com/NixOS/nix/blob/master/src/nix/flake.md spec describing flake inputs in more detail]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:168--&amp;gt;&lt;br /&gt;
* [https://github.com/NixOS/rfcs/pull/49 RFC 49] (2019) - Original flakes specification&lt;br /&gt;
&lt;br /&gt;
=== Guides ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:169--&amp;gt;&lt;br /&gt;
* [https://jade.fyi/blog/flakes-arent-real/ Flakes aren&#039;t real and can&#039;t hurt you] (Jade Lovelace, 2024)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:170--&amp;gt;&lt;br /&gt;
* [https://github.com/ryan4yin/nixos-and-flakes-book NixOS &amp;amp; Flakes Book](Ryan4yin, 2023) - 🛠️ ❤️ An unofficial NixOS &amp;amp; Flakes book for beginners.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:171--&amp;gt;&lt;br /&gt;
* [https://xeiaso.net/blog/nix-flakes-1-2022-02-21 Nix Flakes: an Introduction] (Xe Iaso, 2022)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:172--&amp;gt;&lt;br /&gt;
* [https://serokell.io/blog/practical-nix-flakes Practical Nix Flakes] (Alexander Bantyev, 2021) - Intro article on working with Nix and Flakes&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:173--&amp;gt;&lt;br /&gt;
* [https://www.tweag.io/blog/2020-05-25-flakes/ Nix Flakes, Part 1: An introduction and tutorial] (Eelco Dolstra, 2020)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:174--&amp;gt;&lt;br /&gt;
* [https://www.tweag.io/blog/2020-06-25-eval-cache/ Nix Flakes, Part 2: Evaluation caching] (Eelco Dolstra, 2020)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:175--&amp;gt;&lt;br /&gt;
* [https://www.tweag.io/blog/2020-07-31-nixos-flakes/ Nix Flakes, Part 3: Managing NixOS systems] (Eelco Dolstra, 2020)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:177--&amp;gt;&lt;br /&gt;
* [https://www.youtube.com/watch?v=QXUlhnhuRX4&amp;amp;list=PLgknCdxP89RcGPTjngfNR9WmBgvD_xW0l Nix flakes 101: Introduction to nix flakes] (Jörg Thalheim, 2020) YouTube video&lt;br /&gt;
&lt;br /&gt;
=== Useful flake modules === &lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:179--&amp;gt;&lt;br /&gt;
* [[Flake Utils|flake-utils]]: Library to avoid some boiler-code when writing flakes&lt;br /&gt;
&lt;br /&gt;
* [[Flake Parts|flake-parts]]: Library to help write modular and organized flakes&lt;br /&gt;
&lt;br /&gt;
* [[Flake Compat|flake-compat]]: A compatibility layer for flakes&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:181--&amp;gt;&lt;br /&gt;
* [https://github.com/nix-community/todomvc-nix building Rust and Haskell flakes]&lt;br /&gt;
&lt;br /&gt;
{{references}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
[[Category:Software]]&lt;br /&gt;
[[Category:Nix]]&lt;br /&gt;
[[Category:Nix Language]]&lt;br /&gt;
[[Category:Flakes]]&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=Firewall&amp;diff=22978</id>
		<title>Firewall</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=Firewall&amp;diff=22978"/>
		<updated>2025-06-13T17:48:17Z</updated>

		<summary type="html">&lt;p&gt;Pigs: Reword and refactor layout&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[NixOS]] includes an integrated firewall based on [https://www.netfilter.org/ iptables]/[https://www.nftables.org/ nftables], which can be configured declaratively through the [[NixOS system configuration]]. By default, the firewall is enabled and restricts incoming network connections, allowing users to explicitly define which ports and services should be accessible.&lt;br /&gt;
&lt;br /&gt;
== Enable ==&lt;br /&gt;
&lt;br /&gt;
The firewall is enabled by default on NixOS. To explicitly ensure it is enabled, add the following option to your system configuration:&lt;br /&gt;
&lt;br /&gt;
{{file|/etc/nixos/configuration.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
  networking.firewall.enable = true;&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
With the firewall enabled, all local ports and services will be unreachable from external connections unless explicitly allowed.&lt;br /&gt;
&lt;br /&gt;
To use the newer nftables backend instead of iptables, set the option {{nixos:option|networking.nftables.enable}} to true.&lt;br /&gt;
&lt;br /&gt;
== Configuration ==&lt;br /&gt;
&lt;br /&gt;
To allow specific TCP/UDP ports or port ranges on all interfaces, use following syntax:&lt;br /&gt;
&lt;br /&gt;
{{file|/etc/nixos/configuration.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
  networking.firewall = {&lt;br /&gt;
    enable = true;&lt;br /&gt;
    allowedTCPPorts = [ 80 443 ];&lt;br /&gt;
    allowedUDPPortRanges = [&lt;br /&gt;
      { from = 4000; to = 4007; }&lt;br /&gt;
      { from = 8000; to = 8010; }&lt;br /&gt;
    ];&lt;br /&gt;
  };  &lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Refer to {{nixos:option|networking.firewall}} for more firewall module options.&lt;br /&gt;
&lt;br /&gt;
{{note|Many services also provide an option to open the required firewall ports automatically. For example, the media server Jellyfin offers the option &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;services.jellyfin.openFirewall = true;&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; which will open the required TCP ports.}}&lt;br /&gt;
&lt;br /&gt;
{{warning|Firewall rules may be overwritten by [[Docker]], as per https://github.com/NixOS/nixpkgs/issues/111852}}&lt;br /&gt;
&lt;br /&gt;
=== Interface specific rules ===&lt;br /&gt;
&lt;br /&gt;
It is possible to define firewall rules for specific network interfaces. This can be useful for allowing different ports or services on different network connections. Add the following to your system configuration:&lt;br /&gt;
&lt;br /&gt;
{{file|/etc/nixos/configuration.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
  networking.firewall.interfaces.&amp;quot;eth0&amp;quot;.allowedTCPPorts = [ 80 443 ];&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
In this case, ports &amp;lt;code&amp;gt;80&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;443&amp;lt;/code&amp;gt; will be allowed for the interface &amp;lt;code&amp;gt;eth0&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Tips and tricks ==&lt;br /&gt;
&lt;br /&gt;
=== Temporary firewall rules ===&lt;br /&gt;
&lt;br /&gt;
If using iptables, for temporary changes to the firewall rules, you can install the [https://search.nixos.org/packages?query=nixos-firewall-tool &amp;lt;code&amp;gt;nixos-firewall-tool&amp;lt;/code&amp;gt;] package, which is a [https://github.com/NixOS/nixpkgs/blob/7eee17a8a5868ecf596bbb8c8beb527253ea8f4d/pkgs/by-name/ni/nixos-firewall-tool/nixos-firewall-tool.sh thin wrapper] around &amp;lt;code&amp;gt;iptables&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[Category:Server]]&lt;br /&gt;
[[Category:Applications]]&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=Apache_Httpd&amp;diff=22977</id>
		<title>Apache Httpd</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=Apache_Httpd&amp;diff=22977"/>
		<updated>2025-06-13T17:16:08Z</updated>

		<summary type="html">&lt;p&gt;Pigs: Create initial page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[https://httpd.apache.org/ Apache Http Server] is a web server developed by the [https://www.apache.org/ Apache Software Foundation].&lt;br /&gt;
&lt;br /&gt;
== Enabling ==&lt;br /&gt;
&lt;br /&gt;
To enable the Apache HTTP server service on your system, add the following options to your [[NixOS system configuration]]. Additionally, you may wish to open the appropriate ports in the [[firewall]] to allow HTTP and HTTPS traffic.&lt;br /&gt;
&lt;br /&gt;
{{file|/etc/nixos/configuration.nix|nix|&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
  services.httpd.enable = true;&lt;br /&gt;
  networking.firewall.allowedTCPPorts = [ 80 443 ];&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Refer to {{nixos:option|services.httpd}} for more module configuration options.&lt;br /&gt;
&lt;br /&gt;
== Tips and tricks ==&lt;br /&gt;
&lt;br /&gt;
=== Using ACME certificates ===&lt;br /&gt;
&lt;br /&gt;
Refer to  {{NixOS Manual|name=NixOS Manual: Chapter - Package Management|anchor=#module-security-acme-httpd}}.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[Firewall]]&lt;br /&gt;
* [[Nginx]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Server]]&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=Nixpkgs&amp;diff=22973</id>
		<title>Nixpkgs</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=Nixpkgs&amp;diff=22973"/>
		<updated>2025-06-12T17:42:49Z</updated>

		<summary type="html">&lt;p&gt;Pigs: point to status page for current version&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:1--&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Nixpkgs&#039;&#039;&#039; is the largest repository of [[Nix]] packages and [[NixOS]] modules. The repository is [https://github.com/nixos/nixpkgs hosted on GitHub] and maintained by the community, with official backing from the [[NixOS Foundation]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:2--&amp;gt;&lt;br /&gt;
To search among available packages and options, see [[Searching packages]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:3--&amp;gt;&lt;br /&gt;
As highlighted in [https://nixos.org/blog/announcements/2024/nixos-2411/ the announcement] of the NixOS 24.11 release, &#039;&#039;&amp;quot;NixOS is already known as [https://repology.org/repositories/statistics/newest the most up to date distribution] while also being [https://repology.org/repositories/statistics/total the distribution with the most packages].&amp;quot;&#039;&#039; This is thanks to the community&#039;s continued dedication to making Nixpkgs the preeminent Linux package repository.&lt;br /&gt;
&lt;br /&gt;
== Subpages == &amp;lt;!--T:4--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:5--&amp;gt;&lt;br /&gt;
There are a number of articles especially related to working with &amp;lt;tt&amp;gt;nixpkgs&amp;lt;/tt&amp;gt;:&lt;br /&gt;
{{Special:PrefixIndex/{{FULLPAGENAME}}/ |hideredirects=1 |stripprefix=1}}&lt;br /&gt;
&lt;br /&gt;
== Releases == &amp;lt;!--T:6--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:7--&amp;gt;&lt;br /&gt;
{{main|Channel branches}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:8--&amp;gt;&lt;br /&gt;
The packages and modules hosted on Nixpkgs are distributed through various [[channel branches]] intended for particular use-cases. In practice they are differentiated by the level of testing updates must pass on the official [https://nixos.org/hydra/manual/#idm140737315980672 nixos.org Hydra instance] and the number of updates they receive.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:9--&amp;gt;&lt;br /&gt;
For [[NixOS]] users, &amp;lt;code&amp;gt;nixos-unstable&amp;lt;/code&amp;gt; channel branch is the rolling release, where packages pass build tests and [[NixOS VM tests|integration tests on a VM]], and are tested from the perspective of being an operative system (this means things like the [[Xorg|X server]], [[KDE]], various servers, and lower level details like installing [[Bootloader|bootloaders]] and running the NixOS installation steps are also tested).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:10--&amp;gt;&lt;br /&gt;
For standalone [[Nix]] users, &amp;lt;code&amp;gt;nixpkgs-unstable&amp;lt;/code&amp;gt; channel branch is the rolling release, where packages pass only basic build tests and are upgraded continuously.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:11--&amp;gt;&lt;br /&gt;
Both [[NixOS]] and [[Nix]] users can use stable channel branches (see https://status.nixos.org/ for the current channels) to receive only conservative updates for fixing critical bugs and security vulnerabilities. Stable channel branches are released bi-annually at the end of May and the end of November. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:12--&amp;gt;&lt;br /&gt;
Using stable channels on NixOS is comparable to the user experience on other Linux distributions.&lt;br /&gt;
&lt;br /&gt;
== Alternatives == &amp;lt;!--T:13--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:14--&amp;gt;&lt;br /&gt;
Due to the fact that Nixpkgs is &#039;&#039;only&#039;&#039; a Nix expression, it is possible to extend or replace the logic with your own sources.&lt;br /&gt;
In fact, there are a number of extensions as well as complete replacements for Nixpkgs, see the [[Alternative Package Sets]] article.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Pedias]]&lt;br /&gt;
[[Category:Nixpkgs]]&lt;br /&gt;
[[Category:Nix]]&lt;br /&gt;
[[Category:Software]]&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=Updating_NixOS&amp;diff=22972</id>
		<title>Updating NixOS</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=Updating_NixOS&amp;diff=22972"/>
		<updated>2025-06-12T17:39:50Z</updated>

		<summary type="html">&lt;p&gt;Pigs: link to channel branches&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
[[NixOS]] stands out due to its declarative configuration and atomic updates, which ensure that system updates are predictable, reversible, and don’t risk breaking the setup. This approach guarantees consistency across versions, allowing any changes to be easily rolled back. NixOS also offers flexibility, multi-version support, and advanced dependency management, making it an excellent choice for developers and system administrators.&lt;br /&gt;
&lt;br /&gt;
As part of this process, only repository channels are updated or removed during updates. The system &#039;&#039;&#039;requires an internet connection&#039;&#039;&#039; to download the latest changes, and users &#039;&#039;&#039;cannot&#039;&#039;&#039; directly modify the system. For optimal stability, security, and access to new features, regular updates — ideally &#039;&#039;&#039;once a week&#039;&#039;&#039; — are recommended.&lt;br /&gt;
&lt;br /&gt;
== Rebuilding the system after editing configuration.nix file ==&lt;br /&gt;
To apply the configuration changes made in &amp;lt;code&amp;gt;/etc/nixos/configuration.nix&amp;lt;/code&amp;gt; without updating the channels, [[Nixpkgs]] and package versions. This is typically used when you&#039;ve edited the system configuration, and you just want to apply those changes:&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
# nixos-rebuild switch&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== For non-flake configurations ==&lt;br /&gt;
&lt;br /&gt;
=== Updating NixOS channels ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
# nix-channel --update&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information on channels, see the main [[Channel branches]] page. &lt;br /&gt;
&lt;br /&gt;
=== Rebuilding the system after updating channels ===&lt;br /&gt;
If you want to not only apply your configuration changes but also update the packages and system environment to the latest versions available from the Nixpkgs repository. This is typically used when you want to ensure you are using the latest versions of your software and system services:&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
# nixos-rebuild switch --upgrade&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;To apply configuration changes and new package updates only &#039;&#039;&#039;after&#039;&#039;&#039; rebooting the system, use the following command instead:&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
# nixos-rebuild boot --upgrade&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Changing Nixpkgs version ===&lt;br /&gt;
To see what is the latest channel available, see https://channels.nixos.org&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;# nix-channel --add https://channels.nixos.org/nixos-&amp;lt;version&amp;gt; nixos&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Deleting old generations ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
# nix-collect-garbage -d&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Example of a system update ===&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
# nix-channel --update &amp;amp;&amp;amp; nixos-rebuild switch --upgrade &amp;amp;&amp;amp; reboot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== For flake based configurations ==&lt;br /&gt;
&lt;br /&gt;
Because [[Flakes]] do not use channels and instead rely on explicitly defined inputs, updating a configuration involves modifying the system’s &amp;lt;code&amp;gt;flake.nix&amp;lt;/code&amp;gt; to reference the desired versions of inputs. For example:&lt;br /&gt;
&lt;br /&gt;
{{file|flake.nix|nix|&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  inputs = {&lt;br /&gt;
    nixpkgs.url = &amp;quot;github:nixos/nixpkgs/nixos-25.05&amp;quot;; # update version&lt;br /&gt;
    ...&lt;br /&gt;
  };&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Once the input URLs have been updated, refresh the flake lockfile with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
# nix flake update&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, rebuild the system configuration to apply the changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
# nixos-rebuild switch&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Tips and tricks ==&lt;br /&gt;
&lt;br /&gt;
=== Limiting the maximum number of running jobs ===&lt;br /&gt;
&lt;br /&gt;
Sometimes, the update process may hang when the system CPU has a high number of cores. You can limit the maximum number of running jobs:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
# nixos-rebuild switch --option max-jobs 8&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;To make the change permanent, add the following to your configuration.nix:&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
nix = {&lt;br /&gt;
  settings = {&lt;br /&gt;
    max-jobs = 8;&lt;br /&gt;
  };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:NixOS]]&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=NixOS&amp;diff=22971</id>
		<title>NixOS</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=NixOS&amp;diff=22971"/>
		<updated>2025-06-12T17:37:19Z</updated>

		<summary type="html">&lt;p&gt;Pigs: /* Channels */ An overview of channels should not have in-depth usage information, moving to channel branches&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Expansion|Incomplete (reason: it needs to be an easy introduction, because its one of the first articles new users read here. Thats why it needs to be simplified a bit and more complex topics should be moved to other articles))}}&lt;br /&gt;
&lt;br /&gt;
[https://nixos.org/ NixOS] is a Linux distribution based on the [[Nix]] package manager and build system. It supports [https://en.wikipedia.org/wiki/Declarative_programming declarative] system-wide [https://en.wikipedia.org/wiki/Configuration_management configuration management] as well as [https://en.wikipedia.org/wiki/Atomicity_(database_systems) atomic] upgrades and rollbacks, although it can additionally support [https://en.wikipedia.org/wiki/Imperative_programming imperative] package and user management. In NixOS, all components of the distribution &amp;amp;mdash; including the [https://en.wikipedia.org/wiki/Linux_kernel kernel], installed [https://en.wikipedia.org/wiki/Package_manager packages] and system configuration files &amp;amp;mdash; are built by [[Nix]] from [[Wikipedia:Pure function|pure functions]] called [[Nix Expression Language|Nix expressions]].&lt;br /&gt;
&lt;br /&gt;
Since Nix uses [https://en.wikipedia.org/wiki/Executable binary] caching, this provides a unique compromise between the binary-oriented approach used by distributions such as Debian and the [https://en.wikipedia.org/wiki/Source_code source]-oriented approach used by distributions such as Gentoo. Binaries can be used for standard components, and custom-built packages and modules can be used automatically when a pre-built binary is not available.&lt;br /&gt;
&lt;br /&gt;
Stable NixOS releases are delivered twice a year (around the end of May and the end of November). NixOS was created by [https://edolstra.github.io/ Eelco Dolstra] and [https://en.wikipedia.org/wiki/Armijn_Hemel Armijn Hemel], and initially released in 2003. It is community developed and maintained under the stewardship of the [[Nix_Community#NixOS_Foundation|NixOS Foundation]].&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
For a full installation guide, see the [https://nixos.org/nixos/manual/index.html#ch-installation Installation chapter of the NixOS manual]. This wiki also includes alternative or supplemental guides, such as [[NixOS as a desktop]].&lt;br /&gt;
&lt;br /&gt;
Most users will install NixOS via [https://nixos.org/download/#nixos-iso one of the ISO images.] Both &amp;quot;graphical&amp;quot; and &amp;quot;minimal&amp;quot; ISO variants are available for each supported architecture; the &amp;quot;graphical&amp;quot; images are suitable for users intending to install a desktop environment, and the &amp;quot;minimal&amp;quot; images are suitable for users intending to install NixOS in a server role or desiring a smaller ISO image. The ISO images are hybrid images which can be burnt to optical media or copied raw to a USB drive and booted as-is. See the installation guide for details.&lt;br /&gt;
&lt;br /&gt;
In addition to the ISO images, the [https://nixos.org/download/#nixos-iso download page] provides a number of alternative methods for installing NixOS. These include:&lt;br /&gt;
&lt;br /&gt;
* Virtual appliances in OVA format (compatible with VirtualBox);&lt;br /&gt;
* Amazon EC2 AMIs;&lt;br /&gt;
&lt;br /&gt;
Additionally, many existing Linux installations can be converted into NixOS installations using [https://github.com/elitak/nixos-infect nixos-infect] or [https://github.com/jeaye/nixos-in-place nixos-in-place]; this is particularly useful for installing NixOS on hosting providers which do not natively support NixOS.&lt;br /&gt;
&lt;br /&gt;
For information on installing NixOS on various ARM devices, see [[NixOS on ARM]].&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
&lt;br /&gt;
=== Declarative Configuration ===&lt;br /&gt;
&lt;br /&gt;
One of NixOS&#039;s defining features is its declarative configuration model, where the entire system state — including installed packages, system services, and settings — is described in configuration files. The primary file is typically located at &amp;lt;code&amp;gt;/etc/nixos/configuration.nix&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Changes to the configuration are applied atomically using &amp;lt;code&amp;gt;nixos-rebuild switch&amp;lt;/code&amp;gt;, ensuring reproducibility and the ability to roll back to previous states. Most users track their configuration files in a version control system, enabling consistent and portable system setups. These shortcomings are often rectified after-the-fact if at all by configuration management solutions such as Puppet, Ansible or Chef. These tools reconcile system configuration with a description of the expected state. However, these tools are not integrated into the operating system design and are simply layered on top, and OS configuration may still vary where an aspect of OS configuration has not been specified in the description of expected state. &lt;br /&gt;
&lt;br /&gt;
Unlike conventional distributions, where system configuration is often scattered across manually edited files, NixOS integrates configuration management directly into the operating system. This eliminates configuration drift and makes NixOS particularly well-suited for automated, reproducible deployments.&lt;br /&gt;
&lt;br /&gt;
For more details and examples on NixOS configurations, see [[NixOS system configuration]].&lt;br /&gt;
&lt;br /&gt;
=== Imperative Operations ===&lt;br /&gt;
&lt;br /&gt;
While NixOS is typically configured declaratively as much as possible, these are a few domains where imperative operations are still necessary; these include user environment management and channel management.&lt;br /&gt;
&lt;br /&gt;
====  User Environments ====&lt;br /&gt;
&lt;br /&gt;
In addition to declarative system configuration, NixOS users can utilize Nix&#039;s imperative &amp;lt;code&amp;gt;nix-env&amp;lt;/code&amp;gt; command to install packages at the user level, without changing the system state. See the [[Nix#User Environments| user environments section of the Nix article]] for more information.&lt;br /&gt;
&lt;br /&gt;
==== Channels ====&lt;br /&gt;
&lt;br /&gt;
In the [[Nix ecosystem]], [[Channel branches|channels]] are a mechanism for distributing collections of [[Nixpkgs|Nix packages]] and [[NixOS]] module definitions. A channel represents a curated, versioned set of package definitions and system configurations, typically corresponding to a particular release or the latest available development state.&lt;br /&gt;
&lt;br /&gt;
When using channels, your system or [[User Environment|user environment]] pulls package definitions and options from a URL pointing to a specific snapshot of the Nix Packages collection (Nixpkgs) and associated NixOS modules.&lt;br /&gt;
&lt;br /&gt;
For more information on using and configuring nix channels, refer to [[channel branches]].&lt;br /&gt;
&lt;br /&gt;
== Internals ==&lt;br /&gt;
&lt;br /&gt;
=== Comparison with traditional Linux Distributions ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Main Article: [[Nix vs. Linux Standard Base]]&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The main difference between NixOS and other Linux distributions is that NixOS does not follow the [https://en.wikipedia.org/wiki/Linux_Standard_Base Linux Standard Base] file system structure. On LSB-compliant systems software is stored under &amp;lt;code&amp;gt;/{,usr}/{bin,lib,share}&amp;lt;/code&amp;gt; and configuration is generally stored in &amp;lt;code&amp;gt;/etc&amp;lt;/code&amp;gt;. Software binaries are available in the user environment if they are placed in one of the LSB&#039;s &amp;lt;code&amp;gt;/bin&amp;lt;/code&amp;gt; directories. When a program references dynamic libraries it will search for the required libraries in the LSB folders (&amp;lt;code&amp;gt;/lib&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;/usr/lib&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
In NixOS however &amp;lt;code&amp;gt;/lib&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;/usr/lib&amp;lt;/code&amp;gt; do not exist. Instead all system libraries, binaries, kernels, firmware and configuration files are placed in the [[Nix#Nix store|Nix store]]. The files and directories in &amp;lt;code&amp;gt;/nix/store&amp;lt;/code&amp;gt; are named by hashes of the information describing the built data. All of the files and directories placed in the Nix store are immutable. &amp;lt;code&amp;gt;/bin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;/usr/bin&amp;lt;/code&amp;gt; are almost absent: they contain only &amp;lt;code&amp;gt;/bin/sh&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;/usr/bin/env&amp;lt;/code&amp;gt; respectively, to provide minimal compatibility with existing scripts using shebang lines. User-level environments are implemented using a large number of symbolic links to all required packages and auxiliary files. These environments are called [[Nix#Profiles|profiles]] and are stored in &amp;lt;code&amp;gt;/nix/var/nix/profiles&amp;lt;/code&amp;gt;, each user having their own profiles. Structuring the system in this way is how NixOS obtains its key advantages over conventional Linux distributions, such as atomicity and rollback support.&lt;br /&gt;
&lt;br /&gt;
=== Usage of the Nix store ===&lt;br /&gt;
&lt;br /&gt;
A lot of confusion for newcomers arises from the fact that configuration is stored in the read-only &amp;lt;code&amp;gt;/nix/store&amp;lt;/code&amp;gt; tree along with all the installed packages. This fact makes it impossible to manually edit system configuration; all configuration changes must be performed by editing the &amp;lt;code&amp;gt;/etc/nixos/configuration.nix&amp;lt;/code&amp;gt; file and executing &amp;lt;code&amp;gt;nixos-rebuild switch&amp;lt;/code&amp;gt;. NixOS provides the [[NixOS_modules|module system]] for editing all required configurations. Users should first use [https://search.nixos.org/options the option search tool] to check if the option they need exists before attempting to manually add files or configuration via low-level NixOS features like activation scripts.&lt;br /&gt;
&lt;br /&gt;
The system purity makes it possible to keep system configuration in a central place, without the need to edit multiple files. This configuration can be distributed or version controlled as desired. It also provides for determinism; if you provide the same inputs, the same version of Nixpkgs and the same &amp;lt;code&amp;gt;/etc/nixos/configuration.nix&amp;lt;/code&amp;gt; you will get the exact same system state.&lt;br /&gt;
&lt;br /&gt;
=== Modules ===&lt;br /&gt;
&lt;br /&gt;
The [[NixOS modules|NixOS module system]] as defined in  [[Nixpkgs]] provides the means necessary to customize the configuration of the OS. It is used to enable and customize services such as nginx, enable firmware and customize the kernel.&lt;br /&gt;
&lt;br /&gt;
All module configuration is generally performed by adding options to &amp;lt;code&amp;gt;/etc/nixos/configuration.nix&amp;lt;/code&amp;gt;. Most of the examples in the wiki show how this file can be used to configure the OS.&lt;br /&gt;
&lt;br /&gt;
The NixOS module system implements a typing system which allows typechecking of option settings. It also enables options defined in multiple places to be merged automatically. This allows you to spread your configuration over multiple files, and the options you set across all of those files will be merged together:&lt;br /&gt;
&lt;br /&gt;
{{file|/etc/nixos/configuration.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  imports = [&lt;br /&gt;
    ./basic-webserver.nix&lt;br /&gt;
    ./blog.nix&lt;br /&gt;
  ];&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
{{file|/etc/nixos/basic-webserver.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  services.nginx.enable = true;&lt;br /&gt;
  services.nginx.virtualHosts.&amp;quot;example.com&amp;quot; = {&lt;br /&gt;
    root = &amp;quot;/var/www/example.com&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
{{file|/etc/nixos/blog.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  services.nginx.virtualHosts.&amp;quot;blog.example.com&amp;quot; = {&lt;br /&gt;
    root = &amp;quot;/var/www/blog.example.com&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
See the [https://nixos.org/nixos/manual/index.html#sec-writing-modules Modules section of the NixOS Manual] for more details.&lt;br /&gt;
&lt;br /&gt;
=== Generations ===&lt;br /&gt;
&lt;br /&gt;
Every time the system state is rebuilt using &amp;lt;code&amp;gt;nixos-rebuild switch&amp;lt;/code&amp;gt;, a new generation is created. You can revert to the previous generation at any time, which is useful if a configuration change (or system update) turns out to be detrimental.&lt;br /&gt;
&lt;br /&gt;
You can roll back via:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxHighlight lang=shell&amp;gt;&lt;br /&gt;
$ nix-env --rollback               # roll back a user environment&lt;br /&gt;
$ nixos-rebuild switch --rollback  # roll back a system environment&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NixOS also places entries for previous generations in the bootloader menu, so as a last resort you can always revert to a previous configuration by rebooting. To set the currently booted generation as the default run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxHighlight lang=shell&amp;gt;&lt;br /&gt;
$ /run/current-system/bin/switch-to-configuration boot&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because NixOS keeps previous generations of system state available in case rollback is desired, old package versions aren&#039;t deleted from your system immediately after an update. You can delete old generations manually:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxHighlight lang=shell&amp;gt;&lt;br /&gt;
# delete generations older than 30 days&lt;br /&gt;
$ nix-collect-garbage --delete-older-than 30d&lt;br /&gt;
&lt;br /&gt;
# delete ALL previous generations - you can no longer rollback after running this&lt;br /&gt;
$ nix-collect-garbage -d                       &lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
List generations:&lt;br /&gt;
&amp;lt;syntaxHighlight lang=shell&amp;gt;&lt;br /&gt;
# as root&lt;br /&gt;
$ nix-env --list-generations --profile /nix/var/nix/profiles/system&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Switch generations:&lt;br /&gt;
&amp;lt;syntaxHighlight lang=shell&amp;gt;&lt;br /&gt;
# as root switch to generation 204&lt;br /&gt;
$ nix-env --profile /nix/var/nix/profiles/system --switch-generation 204&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
delete broken generation(s):&lt;br /&gt;
&amp;lt;syntaxHighlight lang=shell&amp;gt;&lt;br /&gt;
# as root delete broken generations 205 and 206 &lt;br /&gt;
$ nix-env --profile /nix/var/nix/profiles/system --delete-generations 205 206&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can configure automatic garbage collection by setting the [https://search.nixos.org/options?query=nix.gc nix.gc] options in &amp;lt;code&amp;gt;/etc/nixos/configuration.nix&amp;lt;/code&amp;gt;. This is recommended, as it keeps the size of the Nix store down.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[NixOS modules]], a library for modular [[Overview of the Nix Expression Language#Expressions|Nix expressions]] which powers [[#Declarative Configuration|the declarative configuration of NixOS]].&lt;br /&gt;
* [[NixOS VM tests]], a library for creating reproducible infrastructure tests, based on [[Nixpkgs]], [[NixOS]], QEMU and Perl.&lt;br /&gt;
* [https://github.com/ryan4yin/nixos-and-flakes-book NixOS &amp;amp; Flakes Book] (Ryan4yin, 2023) - 🛠️ ❤️ An unofficial NixOS &amp;amp; Flakes book for beginners. &lt;br /&gt;
&lt;br /&gt;
[[Category:Pedias]]&lt;br /&gt;
[[Category:NixOS]]&lt;br /&gt;
[[Category:Nix]]&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=Channel_branches&amp;diff=22970</id>
		<title>Channel branches</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=Channel_branches&amp;diff=22970"/>
		<updated>2025-06-12T17:33:05Z</updated>

		<summary type="html">&lt;p&gt;Pigs: Reword and reorganize page, add section on flakes and usage in nixos&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Nix channels provide a structured and reliable way to access tested, verified package collections and [[NixOS]] configurations from the [[Nixpkgs]] repository. Rather than installing packages or building systems directly from the frequently updated &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch of Nixpkgs, which receives new commits before extensive testing. Because of this, users typically follow channel branches.&lt;br /&gt;
&lt;br /&gt;
A channel branch is a curated, tested snapshot of Nixpkgs, made available via [https://channels.nixos.org channels.nixos.org]. These branches only advance after builds and tests for a given commit have successfully passed on the [[Hydra]] continuous integration system.&lt;br /&gt;
&lt;br /&gt;
Each channel branch follows a corresponding development branch to which new commits are first added. These new commits are then &amp;quot;verified&amp;quot; using the [[Hydra]] continuous integration system, where each channel branch corresponds to building any new or updated packages for that branch and perform the associated tests. A channel branch is updated once its builds succeeds for a new commit. Contrary to users of the development branches, channel branch users will benefit from both &amp;quot;verified&amp;quot; commits and pre-built packages from the [https://cache.nixos.org official public binary cache].&lt;br /&gt;
&lt;br /&gt;
== The official channels ==&lt;br /&gt;
&lt;br /&gt;
There are several types of channel branches, each with its own use case and verification phase. Channels can be broadly categorized into &#039;&#039;stable&#039;&#039; and &#039;&#039;unstable&#039;&#039; channels, and &#039;&#039;large&#039;&#039; and &#039;&#039;small&#039;&#039; channels. To view the current official channels, see the [https://status.nixos.org channel status webpage].&lt;br /&gt;
&lt;br /&gt;
* Stable vs unstable:&lt;br /&gt;
** &#039;&#039;&#039;Stable channels&#039;&#039;&#039; (e.g. &amp;lt;code&amp;gt;nixos-25.05&amp;lt;/code&amp;gt;) only provide conservative updates for fixing bugs and security vulnerabilities, but do not receive major updates after the initial release. New stable channels are released every six months.&lt;br /&gt;
** &#039;&#039;&#039;Unstable channels&#039;&#039;&#039; (e.g. &amp;lt;code&amp;gt;nixos-unstable&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;nixpkgs-unstable&amp;lt;/code&amp;gt;) follow the &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; branch of Nixpkgs, delivering the latest tested updates on a rolling basis.&lt;br /&gt;
&lt;br /&gt;
* Large vs small:&lt;br /&gt;
** &#039;&#039;&#039;Large channels&#039;&#039;&#039; (e.g. &amp;lt;code&amp;gt;nixos-25.05&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;nixos-unstable&amp;lt;/code&amp;gt;) are updated only after Hydra has finished building the full breadth of Nixpkgs.&lt;br /&gt;
** &#039;&#039;&#039;Small channels&#039;&#039;&#039; (e.g. &amp;lt;code&amp;gt;nixos-25.05-small&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;nixos-unstable-small&amp;lt;/code&amp;gt;) are identical to large channels, but are updated as soon as Hydra has finished building a defined set of commonly-used packages. Thus, users following these channels will get faster updates but may need to build any packages they use from outside the defined set themselves. These channels are intended to be used for server setups, for example.&lt;br /&gt;
&lt;br /&gt;
For most users, a stable/large channel is recommended.&lt;br /&gt;
&lt;br /&gt;
== The nix-channel command ==&lt;br /&gt;
&lt;br /&gt;
Nix channels are maintained separately for each user account, including the root user. Each user, including root, has their own list of subscribed channels and local copies of those channel definitions. In NixOS, the channels configured for root control system-level operations such as nixos-rebuild, while channels for other users only affect their personal environments and package installations through tools like nix-env or nix-shell. If you wish to change the channel used by the system-level configuration (&amp;lt;code&amp;gt;/etc/nixos/configuration.nix&amp;lt;/code&amp;gt;), ensure you run the correct &amp;lt;code&amp;gt;nix-channel&amp;lt;/code&amp;gt; command as root:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Common nix-channel commands&lt;br /&gt;
|-&lt;br /&gt;
|Listing current channels&lt;br /&gt;
|&amp;lt;code&amp;gt;nix-channel --list&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Adding a primary channel&lt;br /&gt;
|&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;nix-channel --add https://nixos.org/channels/channel-name nixos&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Adding other channels&lt;br /&gt;
|&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;nix-channel --add https://some.channel/url my-alias&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Remove a channel&lt;br /&gt;
|&amp;lt;code&amp;gt;nix-channel --remove channel-alias&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Updating a channel&lt;br /&gt;
|&amp;lt;code&amp;gt;nix-channel --update channel-alias&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Updating all channels&lt;br /&gt;
|&amp;lt;code&amp;gt;nix-channel --update&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Rollback the last update (useful if the last update breaks the &amp;lt;code&amp;gt;nixos-rebuild&amp;lt;/code&amp;gt;)&lt;br /&gt;
|&amp;lt;code&amp;gt;nix-channel --rollback&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Channel usage in NixOS ==&lt;br /&gt;
&lt;br /&gt;
Note that updating channels won&#039;t cause a rebuild in itself; if you want to update channels and rebuild, you can run &amp;lt;code&amp;gt;nixos-rebuild --upgrade switch&amp;lt;/code&amp;gt; to do both in one step. See [[Updating NixOS]] for more in-depth information on changing/updating channels in NixOS.&lt;br /&gt;
&lt;br /&gt;
== Using channel branches with flakes ==&lt;br /&gt;
&lt;br /&gt;
Although [[Flakes]] do not make use of traditional Nix channels, they can still reference the same channel branches by specifying them in the flake’s inputs. These branches, such as &amp;lt;code&amp;gt;nixos-25.05&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;nixos-unstable&amp;lt;/code&amp;gt;, correspond to named references within the Nixpkgs repository and serve a similar role in selecting which version of Nixpkgs or other inputs to use.&lt;br /&gt;
&lt;br /&gt;
A simple example of defining channel branches in a flake:&lt;br /&gt;
&lt;br /&gt;
{{file|flake.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  inputs = {&lt;br /&gt;
    nixpkgs.url = &amp;quot;github:nixos/nixpkgs/nixos-25.05&amp;quot;;&lt;br /&gt;
    nixpkgs-unstable.url = &amp;quot;github:nixos/nixpkgs/nixos-unstable&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
In this way, flakes offer fine-grained, declarative control over which versions of inputs are used, while no longer depending on the global Nix channel system.&lt;br /&gt;
&lt;br /&gt;
== Internal channel update process ==&lt;br /&gt;
&lt;br /&gt;
This section details the inner workings of how channels get generated from the Nixpkgs repository into channel branches. The channel update process begins when anyone with commit access pushes changes to either &amp;lt;code&amp;gt;master&amp;lt;/code&amp;gt; or one of the &amp;lt;code&amp;gt;release-XX.XX&amp;lt;/code&amp;gt; branches.&lt;br /&gt;
&lt;br /&gt;
=== Hydra Build ===&lt;br /&gt;
&lt;br /&gt;
Then, for each &#039;&#039;&#039;unstable&#039;&#039;&#039; channel (see above), a particular job at [https://hydra.nixos.org hydra.nixos.org] is started which must succeed:&lt;br /&gt;
&lt;br /&gt;
* For NixOS: the [http://hydra.nixos.org/job/nixos/trunk-combined/tested trunk-combined/tested] job, which includes some automated NixOS tests.&lt;br /&gt;
*  For nixos-small: the [http://hydra.nixos.org/job/nixos/unstable-small/tested unstable-small/tested] job.&lt;br /&gt;
*  For nixpkgs: the [http://hydra.nixos.org/job/nixpkgs/trunk/unstable trunk/unstable] job, which contains some critical release packages.&lt;br /&gt;
&lt;br /&gt;
=== Success Conditions ===&lt;br /&gt;
&lt;br /&gt;
For a channel update to succeed, two conditions need to be satisfied:&lt;br /&gt;
&lt;br /&gt;
* Particular jobset evaluation needs to be completely built ie. no more queued jobs, even if some jobs may fail&lt;br /&gt;
* Particular jobset evaluation&#039;s tested/unstable job needs to be built succesfully&lt;br /&gt;
&lt;br /&gt;
The nixos.org server has a cronjob for which [https://github.com/nixOS/nixos-channel-scripts nixos-channel-scripts] are executed and poll for the newest jobset that satisfies the above two conditions and trigger a channel update.&lt;br /&gt;
&lt;br /&gt;
=== Channel Update ===&lt;br /&gt;
&lt;br /&gt;
Once the job succeeds at a particular nixpkgs commit, cache.nixos.org will download binaries from [https://hydra.nixos.org hydra.nixos.org]. When the download completes, the channel updates.&lt;br /&gt;
&lt;br /&gt;
For the &amp;lt;code&amp;gt;NixOS&amp;lt;/code&amp;gt; channel command-not-found index is generated, which can take some time since it has to fetch all packages. &amp;lt;code&amp;gt;nixpkgs&amp;lt;/code&amp;gt; is quickly updated since none of the above needs to happen once a channel update is triggered.&lt;br /&gt;
&lt;br /&gt;
Updates for the -unstable channels typically take a few days after commits land in the master branch.&lt;br /&gt;
&lt;br /&gt;
To find out when a channel was last updated, check [https://status.nixos.org/ https://status.nixos.org/]. The progress of a particular pull request can be tracked via the (third-party) [https://nixpk.gs/pr-tracker.html Nixpkgs Pull Request Tracker].&lt;br /&gt;
&lt;br /&gt;
=== Check build status ===&lt;br /&gt;
[https://github.com/nix-community/hydra-check hydra-check]&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot;&amp;gt;&lt;br /&gt;
$ hydra-check --channel unstable bash&lt;br /&gt;
Build Status for nixpkgs.bash.x86_64-linux on unstable&lt;br /&gt;
✔ bash-4.4-p23 from 2021-05-23 - https://hydra.nixos.org/build/143785213&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
also useful for finding build logs&lt;br /&gt;
&lt;br /&gt;
== Tips and tricks ==&lt;br /&gt;
&lt;br /&gt;
=== When unstable lags behind master ===&lt;br /&gt;
&lt;br /&gt;
As https://status.nixos.org shows, a downside of nixos-unstable is that when the channel is blocked due to hydra failures, other (security) fixes will also not get in. While of course we try to keep hydra green, it is expected that this happens every once in a while. When you want to upgrade or downgrade a single package while leaving the rest of your system on nixos-unstable, you could use [[User:Raboof#using_a_fork_of_a_packaged_project|this approach]].&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[Updating NixOS]] - For changing branches in NixOS&lt;br /&gt;
* [[Binary Cache]]&lt;br /&gt;
* [https://nix.dev/concepts/faq#which-channel-branch-should-i-use nix.dev] FAQ: Which channel branch should I use?&lt;br /&gt;
* [https://samuel.dionne-riel.com/blog/2024/05/07/its-not-flakes-vs-channels.html It&#039;s not about “Flakes vs. Channels”] by samueldr&lt;br /&gt;
&lt;br /&gt;
[[Category:Nix]]&lt;br /&gt;
[[Category:NixOS]]&lt;br /&gt;
[[Category:Hydra]]&lt;br /&gt;
[[Category:Software]]&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=GNOME&amp;diff=22969</id>
		<title>GNOME</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=GNOME&amp;diff=22969"/>
		<updated>2025-06-12T16:32:06Z</updated>

		<summary type="html">&lt;p&gt;Pigs: /* Tips and tricks */ add back Excluding Gnome Applications section, under tips and tricks with a more minimal definition&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[{{PAGENAME}}]] (/(ɡ)noʊm/) is a [[:Category:Desktop environment|desktop environment]] for both [[Wayland]] and [[Xorg]] that seeks to be &amp;quot;an independent computing platform for everyone.&amp;quot;&amp;lt;ref&amp;gt;Official GNOME Project one-liner https://www.gnome.org/ &amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This article is an extension of the documentation in the [https://nixos.org/manual/nixos/stable/#chap-gnome NixOS manual].&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
=== GNOME desktop ===&lt;br /&gt;
To use the GNOME desktop environment on NixOS, the following configuration options must be set:&lt;br /&gt;
&lt;br /&gt;
{{file|/etc/nixos/configuration.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  # Pre 25.11&lt;br /&gt;
  services.xserver.enable = true;&lt;br /&gt;
  services.xserver.displayManager.gdm.enable = true;&lt;br /&gt;
  services.xserver.desktopManager.gnome.enable = true;&lt;br /&gt;
&lt;br /&gt;
  # As of 25.11&lt;br /&gt;
  services.displayManager.gdm.enable = true;&lt;br /&gt;
  services.desktopManager.gnome.enable = true;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Despite the options in NixOS versions before 25.11 being under the &amp;lt;code&amp;gt;xserver&amp;lt;/code&amp;gt; namespace, GNOME runs offers [[Wayland]] by default. 25.11 and later versions remove support for the [[Xorg]] session entirely (though Xwayland is still included and supported for compatibility).&lt;br /&gt;
&lt;br /&gt;
=== GNOME extensions ===&lt;br /&gt;
GNOME offers support for changing/overhauling the user interface (GNOME Shell) through the use of &#039;&#039;[https://extensions.gnome.org/about/ Extensions].&#039;&#039; Extensions are bundles of third-party [https://gjs.guide/extensions/ GJS] modules that are loaded while GNOME is running to augment the user experience. A repository of GNOME extensions can be found on GNOME&#039;s official [https://extensions.gnome.org/ webpage] and can be installed imperatively if needed by unpacking the extension in &amp;lt;code&amp;gt;~/.local/share/gnome-shell/extensions&amp;lt;/code&amp;gt; directory. Extensions can only be activated if it supports the GNOME release that it&#039;s installed alongside with.&lt;br /&gt;
&lt;br /&gt;
However, Nix automatically packages all available GNOME extensions under the &amp;lt;code&amp;gt;pkgs.gnomeExtensions&amp;lt;/code&amp;gt; attribute. Extensions which require additional dependencies are then manually packaged if needed. Installed extensions can be enabled graphically through the built-in &amp;quot;Extensions&amp;quot; application or through the &amp;lt;code&amp;gt;gnome-extensions&amp;lt;/code&amp;gt; command line interface.&lt;br /&gt;
&lt;br /&gt;
{{file|3={&lt;br /&gt;
  environment.systemPackages = with pkgs; [&lt;br /&gt;
    gnomeExtensions.blur-my-shell&lt;br /&gt;
    gnomeExtensions.just-perfection&lt;br /&gt;
    gnomeExtensions.arc-menu&lt;br /&gt;
  ];&lt;br /&gt;
}|name=/etc/nixos/configuration.nix|lang=nix}}&lt;br /&gt;
== Configuration ==&lt;br /&gt;
&lt;br /&gt;
=== dconf ===&lt;br /&gt;
&lt;br /&gt;
Dconf is a low-level configuration system for storing and loading configurations. The dconf database is stored in a single binary file in &amp;lt;code&amp;gt;~/.config/dconf/user&amp;lt;/code&amp;gt;  and contains all known configuration values for all applications and programs that use dconf (GNOME applications and shell, gtk, etc).&lt;br /&gt;
&lt;br /&gt;
For example, the setting which controls the accent color of GNOME shell is located in the &#039;&#039;schema&#039;&#039; labeled &amp;lt;code&amp;gt;/org/gnome/desktop/interface/&amp;lt;/code&amp;gt; which contains the &#039;&#039;key&#039;&#039; &amp;lt;code&amp;gt;accent-color&amp;lt;/code&amp;gt; which accepts a GVariant &#039;&#039;value&#039;&#039; of type &amp;lt;code&amp;gt;enum&amp;lt;/code&amp;gt; (one of &amp;lt;code&amp;gt;&#039;blue&#039;&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;&#039;teal&#039;&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;&#039;green&#039;&amp;lt;/code&amp;gt;, etc)&lt;br /&gt;
&lt;br /&gt;
NixOS and Home Manager both provide an interface for declarative configuration of dconf settings exposed in &amp;lt;code&amp;gt;programs.dconf&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;dconf&amp;lt;/code&amp;gt; modules respectively. This option accepts an attribute set whose names are schemas whose paired value is another attribute set whose names are keys and paired values as GVariant values.&lt;br /&gt;
&lt;br /&gt;
Going back to the previous example, to set the accent color of GNOME in a declarative manner in NixOS as well as mapping the keyboard&#039;s &amp;quot;caps lock&amp;quot; key to &amp;quot;ctrl&amp;quot; you would write:&lt;br /&gt;
&lt;br /&gt;
{{file|3={&lt;br /&gt;
  programs.dconf.profiles.user.databases = [&lt;br /&gt;
    {&lt;br /&gt;
      lockAll = true; # prevents overriding&lt;br /&gt;
      settings = {&lt;br /&gt;
        &amp;quot;org/gnome/desktop/interface&amp;quot; = {&lt;br /&gt;
          accent-color = &amp;quot;blue&amp;quot;;&lt;br /&gt;
        };&lt;br /&gt;
        &amp;quot;org/gnome/desktop/input-sources&amp;quot; = {&lt;br /&gt;
          xkb-options = [ &amp;quot;ctrl:nocaps&amp;quot; ];&lt;br /&gt;
        };&lt;br /&gt;
      };&lt;br /&gt;
    }&lt;br /&gt;
  ];&lt;br /&gt;
}|name=/etc/nixos/configuration.nix|lang=nix}}&lt;br /&gt;
&lt;br /&gt;
And the equivalent snippet in Home Manager:&lt;br /&gt;
&lt;br /&gt;
{{file|3={&lt;br /&gt;
  dconf.enable = true;&lt;br /&gt;
  dconf.settings = {&lt;br /&gt;
    &amp;quot;org/gnome/desktop/interface&amp;quot; = {&lt;br /&gt;
      accent-color = &amp;quot;blue&amp;quot;;&lt;br /&gt;
    };&lt;br /&gt;
    &amp;quot;org/gnome/desktop/input-sources&amp;quot; = {&lt;br /&gt;
      xkb-options = [ &amp;quot;ctrl:nocaps&amp;quot; ];&lt;br /&gt;
    };&lt;br /&gt;
  };&lt;br /&gt;
}|name=~/.config/home-manager/home.nix|lang=nix}}&lt;br /&gt;
&lt;br /&gt;
{{Note|Schemas in Nix are written without leading and trailing slashes. In addition, since dconf have more data types than the Nix language (for example, tuples), in some cases you&#039;ll need to convert Nix value to a GVariant value. You can achieve that by using function defined in &amp;lt;code&amp;gt;lib.gvariant&amp;lt;/code&amp;gt;, they&#039;re documented [https://nixos.org/manual/nixpkgs/stable/#sec-functions-library-gvariant here].}}&lt;br /&gt;
&lt;br /&gt;
==== Extensions ====&lt;br /&gt;
Extensions are not activated by default when installed with Nix but can be configured to do so using the respective dconf modules. The schema is &amp;lt;code&amp;gt;/org/gnome/shell/&amp;lt;/code&amp;gt; with the key &amp;lt;code&amp;gt;enabled-extensions&amp;lt;/code&amp;gt; which accepts a list of strings that represent extension UUIDs. If the extension was installed with Nix, then the UUID can be accessed by the &amp;lt;code&amp;gt;extensionUuid&amp;lt;/code&amp;gt; attribute of the extension itself. Each extension&#039;s configuration can then be found under their corresponding schema in &amp;lt;code&amp;gt;/org/gnome/shell/extensions/&amp;lt;/code&amp;gt; and be configured as needed.&lt;br /&gt;
&lt;br /&gt;
For example, in Home Manager, you could write:&lt;br /&gt;
&lt;br /&gt;
{{file|3={&lt;br /&gt;
  dconf = {&lt;br /&gt;
    enable = true;&lt;br /&gt;
    settings = {&lt;br /&gt;
      &amp;quot;org/gnome/shell&amp;quot; = {&lt;br /&gt;
        disable-user-extensions = false; # enables user extensions&lt;br /&gt;
        enabled-extensions = [&lt;br /&gt;
          # Put UUIDs of extensions that you want to enable here.&lt;br /&gt;
          # If the extension you want to enable is packaged in nixpkgs,&lt;br /&gt;
          # you can easily get its UUID by accessing its extensionUuid&lt;br /&gt;
          # field (look at the following example).&lt;br /&gt;
          pkgs.gnomeExtensions.gsconnect.extensionUuid&lt;br /&gt;
&lt;br /&gt;
          # Alternatively, you can manually pass UUID as a string.&lt;br /&gt;
          &amp;quot;blur-my-shell@aunetx&amp;quot;&lt;br /&gt;
          # ...&lt;br /&gt;
        ];&lt;br /&gt;
      };&lt;br /&gt;
&lt;br /&gt;
      # Configure individual extensions&lt;br /&gt;
      &amp;quot;org/gnome/shell/extensions/blur-my-shell&amp;quot; = {&lt;br /&gt;
        brightness = 0.75;&lt;br /&gt;
        noise-amount = 0;&lt;br /&gt;
      };&lt;br /&gt;
    };&lt;br /&gt;
  };&lt;br /&gt;
}|name=~/.config/home-manager/home.nix|lang=nix}}&lt;br /&gt;
&lt;br /&gt;
== Tips and tricks ==&lt;br /&gt;
&lt;br /&gt;
=== Discover dconf settings ===&lt;br /&gt;
If you wish to discover the corresponding dconf entry for a given setting in a program, you can run `dconf watch /` inside of a terminal and change the setting graphically. For example, when changing toggling the Quick-Settings option &amp;quot;Dark Style&amp;quot; from &amp;quot;on&amp;quot; to &amp;quot;off&amp;quot; and back to &amp;quot;on,&amp;quot; this will be the output:&amp;lt;syntaxhighlight lang=&amp;quot;shell-session&amp;quot;&amp;gt;&lt;br /&gt;
$ dconf watch /&lt;br /&gt;
/org/gnome/desktop/interface/color-scheme&lt;br /&gt;
  &#039;default&#039;&lt;br /&gt;
&lt;br /&gt;
/org/gnome/desktop/interface/color-scheme&lt;br /&gt;
  &#039;prefer-dark&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;Otherwise you can use the gsettings programs to inspect the schemas installed on your system. For example, to inspect all the keys contained within &amp;lt;code&amp;gt;/org/gnome/desktop/background&amp;lt;/code&amp;gt; you could run:&amp;lt;syntaxhighlight lang=&amp;quot;shell-session&amp;quot;&amp;gt;&lt;br /&gt;
$ gsettings list-keys org.gnome.desktop.background&lt;br /&gt;
color-shading-type&lt;br /&gt;
picture-opacity&lt;br /&gt;
picture-options&lt;br /&gt;
picture-uri&lt;br /&gt;
picture-uri-dark&lt;br /&gt;
primary-color&lt;br /&gt;
secondary-color&lt;br /&gt;
show-desktop-icons&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;Then to see the range of possible values for one of the keys such as &amp;lt;code&amp;gt;picture-options&amp;lt;/code&amp;gt; you could then run:&amp;lt;syntaxhighlight lang=&amp;quot;shell-session&amp;quot;&amp;gt;&lt;br /&gt;
$ gsettings range org.gnome.desktop.background picture-options&lt;br /&gt;
enum&lt;br /&gt;
&#039;none&#039;&lt;br /&gt;
&#039;wallpaper&#039;&lt;br /&gt;
&#039;centered&#039;&lt;br /&gt;
&#039;scaled&#039;&lt;br /&gt;
&#039;stretched&#039;&lt;br /&gt;
&#039;zoom&#039;&lt;br /&gt;
&#039;spanned&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;Which tells you that the &#039;&#039;key&#039;&#039; &amp;lt;code&amp;gt;picture-options&amp;lt;/code&amp;gt; located in &#039;&#039;schema&#039;&#039; &amp;lt;code&amp;gt;/org/gnome/desktop/background/&amp;lt;/code&amp;gt; accepts a &#039;&#039;value&#039;&#039; of type enumeration (a single string value from a set of accepted values). &lt;br /&gt;
&lt;br /&gt;
=== Enable system tray icons ===&lt;br /&gt;
GNOME does not currently support system tray icons. However, Ubuntu has created an [https://extensions.gnome.org/extension/615/appindicator-support/ extension] that implements this in the top bar. You can install this extension with the following in NixOS:&lt;br /&gt;
{{File|3={&lt;br /&gt;
  environment.systemPackages = [ pkgs.gnomeExtensions.appindicator  ];&lt;br /&gt;
  services.udev.packages = [ pkgs.gnome-settings-daemon ];&lt;br /&gt;
}|name=/etc/nixos/configuration.nix|lang=nix}}&lt;br /&gt;
&lt;br /&gt;
=== Profiling (with sysprof) ===&lt;br /&gt;
&lt;br /&gt;
Install {{ic|sysprof}} as a &#039;&#039;system&#039;&#039; package (it won&#039;t work properly if installed against users). Then enable the associated service with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
  services.sysprof.enable = true;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Automatic screen rotation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
  hardware.sensor.iio.enable = true;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dark mode ===&lt;br /&gt;
&lt;br /&gt;
Change default color theme for all GTK4 applications to dark using [[Home Manager]].&lt;br /&gt;
&lt;br /&gt;
{{file|~/.config/home-manager/home.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  dconf = {&lt;br /&gt;
    enable = true;&lt;br /&gt;
    settings.&amp;quot;org/gnome/desktop/interface&amp;quot;.color-scheme = &amp;quot;prefer-dark&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
=== Excluding GNOME Applications ===&lt;br /&gt;
&lt;br /&gt;
To exclude certain applications that are installed by default with GNOME, set the {{nixos:option|environment.gnome.excludePackages}} module option:&lt;br /&gt;
&lt;br /&gt;
{{file|/etc/nixos/configuration.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
  environment.gnome.excludePackages = with pkgs; [&lt;br /&gt;
    totem&lt;br /&gt;
  ];&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
=== Running GConf-based applications ===&lt;br /&gt;
&lt;br /&gt;
There exist very old applications which use the deprecated GConf service to store configuration. If you are running such an application and are getting an error like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
GLib.GException: Failed to contact configuration server; the most common cause is a missing or misconfigured D-Bus session bus daemon. See http://projects.gnome.org/gconf/ for information&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
you will need to add &amp;lt;code&amp;gt;pkgs.gnome2.GConf&amp;lt;/code&amp;gt; to the list of dbus packages in your NixOS configuration like so:&lt;br /&gt;
&lt;br /&gt;
{{File|3={&lt;br /&gt;
  services.dbus.packages = with pkgs; [ gnome2.GConf ];&lt;br /&gt;
}|name=/etc/nixos/configuration.nix|lang=nix}}&lt;br /&gt;
&lt;br /&gt;
After rebuilding your configuration, restart your desktop session to have GConf take effect.&lt;br /&gt;
&lt;br /&gt;
=== Automatic login ===&lt;br /&gt;
&lt;br /&gt;
As a potential workaround&amp;lt;ref&amp;gt;https://github.com/NixOS/nixpkgs/issues/103746#issuecomment-945091229&amp;lt;/ref&amp;gt; for automatic login, include this in your NixOS configuration:&lt;br /&gt;
&lt;br /&gt;
{{File|3={&lt;br /&gt;
  services.xserver.displayManager.autoLogin.enable = true;&lt;br /&gt;
  services.xserver.displayManager.autoLogin.user = &amp;quot;account&amp;quot;;&lt;br /&gt;
  &lt;br /&gt;
  systemd.services.&amp;quot;getty@tty1&amp;quot;.enable = false;&lt;br /&gt;
  systemd.services.&amp;quot;autovt@tty1&amp;quot;.enable = false;&lt;br /&gt;
}|name=/etc/nixos/configuration.nix|lang=nix}}&lt;br /&gt;
:&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[GNOME/Calendar]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Desktop environment]]&lt;br /&gt;
[[Category:Applications]]&lt;br /&gt;
[[Category:NixOS Manual]]&lt;br /&gt;
[[Category:GNOME]]&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=Biome&amp;diff=22890</id>
		<title>Biome</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=Biome&amp;diff=22890"/>
		<updated>2025-06-10T21:14:36Z</updated>

		<summary type="html">&lt;p&gt;Pigs: Add category and beginning statement&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[https://github.com/biomejs/biome Biome] is a fast formatter and performant linter for [[JavaScript]], TypeScript, JSX, JSON, CSS and GraphQL.&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
&lt;br /&gt;
==== Issue: Biome LSP in Neovim failed on NixOS due to dynamic linking error. ====&lt;br /&gt;
Logged in &amp;lt;code&amp;gt;/home/incogshift/.local/state/nvim/lsp.log&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;log&amp;quot; line&amp;gt;&lt;br /&gt;
[ERROR] Could not start dynamically linked executable [...] NixOS cannot run dynamically linked executables intended for generic\nlinux environments out of the box [...]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Fix ====&lt;br /&gt;
&lt;br /&gt;
Edit: &amp;lt;code&amp;gt;~/.local/share/nvim/mason/bin/biome&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Look for a section like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot; line&amp;gt;&lt;br /&gt;
const PLATFORMS = {&lt;br /&gt;
	...&lt;br /&gt;
	darwin: {&lt;br /&gt;
		x64: &amp;quot;@biomejs/cli-darwin-x64/biome&amp;quot;,&lt;br /&gt;
		arm64: &amp;quot;@biomejs/cli-darwin-arm64/biome&amp;quot;,&lt;br /&gt;
	},&lt;br /&gt;
	linux: {&lt;br /&gt;
		x64: &amp;quot;@biomejs/cli-linux-x64/biome&amp;quot;,&lt;br /&gt;
		arm64: &amp;quot;@biomejs/cli-linux-arm64/biome&amp;quot;,&lt;br /&gt;
	},&lt;br /&gt;
	...&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Replace the architecture path of your OS with the absolute path to &amp;lt;code&amp;gt;biome&amp;lt;/code&amp;gt; in your system. Find it using:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; line&amp;gt;&lt;br /&gt;
$ which biome&lt;br /&gt;
/etc/profiles/per-user/&amp;lt;user&amp;gt;/bin/biome&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then update the block (assuming &amp;lt;code&amp;gt;x64&amp;lt;/code&amp;gt; Linux as the platform):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot; line&amp;gt;&lt;br /&gt;
const PLATFORMS = {&lt;br /&gt;
	...&lt;br /&gt;
	darwin: {&lt;br /&gt;
		x64: &amp;quot;@biomejs/cli-darwin-x64/biome&amp;quot;,&lt;br /&gt;
		arm64: &amp;quot;@biomejs/cli-darwin-arm64/biome&amp;quot;,&lt;br /&gt;
	},&lt;br /&gt;
	linux: {&lt;br /&gt;
		x64: &amp;quot;/etc/profiles/per-user/&amp;lt;user&amp;gt;/bin/biome&amp;quot;,&lt;br /&gt;
		arm64: &amp;quot;@biomejs/cli-linux-arm64/biome&amp;quot;,&lt;br /&gt;
	},&lt;br /&gt;
	...&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reference for similar issues: [https://stackoverflow.com/a/78215911/27134695 Stack Overflow]&lt;br /&gt;
&lt;br /&gt;
[[Category:JavaScript]]&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=Talk:Haskell&amp;diff=22881</id>
		<title>Talk:Haskell</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=Talk:Haskell&amp;diff=22881"/>
		<updated>2025-06-10T16:39:01Z</updated>

		<summary type="html">&lt;p&gt;Pigs: /* flowchart replacement */ new section&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;quot;Nix recipes for Haskellers&amp;quot; link is currently broken (4/2/2021).&lt;br /&gt;
&lt;br /&gt;
[2022/10/25] Thanks for working on this page. It is informative and has improved a lot since my last visit around a year ago. Thank you!&lt;br /&gt;
&lt;br /&gt;
== ghcup ==&lt;br /&gt;
&lt;br /&gt;
What about ghcup? The main installer of Haskell [[User:Turbotimon|Turbotimon]] ([[User talk:Turbotimon|talk]]) 16:05, 13 February 2025 (UTC)&lt;br /&gt;
&lt;br /&gt;
:I added a section on ghcup under limitations. GHCup does not work out of the box on NixOS and the effort to get it to work is probably not worth it compared to just grabbing specific GHC versions from Nixpkgs. [[User:Pigs|Pigs]] ([[User talk:Pigs|talk]]) 16:56, 20 May 2025 (UTC)&lt;br /&gt;
&lt;br /&gt;
== flowchart replacement ==&lt;br /&gt;
&lt;br /&gt;
This flowchart was removed from the page. It did have many issues such as being out of date, an image that you cant update, and oversimplified,&lt;br /&gt;
&lt;br /&gt;
However, with the 6 different ways documented on how to build Haskell projects, there needs to be some sort of introductory information at the top of the page that details why someone should choose one method over the other. &lt;br /&gt;
&lt;br /&gt;
[[File:haskell_choice.png]] [[User:Pigs|Pigs]] ([[User talk:Pigs|talk]]) 16:39, 10 June 2025 (UTC)&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=1Password&amp;diff=22810</id>
		<title>1Password</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=1Password&amp;diff=22810"/>
		<updated>2025-06-09T18:31:26Z</updated>

		<summary type="html">&lt;p&gt;Pigs: /* Unlocking with System Authentication */ don&amp;#039;t link to old wiki&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[https://1password.com/ 1Password] is a password manager.&lt;br /&gt;
&lt;br /&gt;
== NixOS ==&lt;br /&gt;
&lt;br /&gt;
=== Installation ===&lt;br /&gt;
&lt;br /&gt;
If you&#039;re using [[NixOS]], you can enable 1Password and its GUI with:&lt;br /&gt;
{{file|/etc/nixos/configuration.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
{ config, lib, pkgs, ... }:&lt;br /&gt;
{&lt;br /&gt;
  # Enable the unfree 1Password packages&lt;br /&gt;
  nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [&lt;br /&gt;
    &amp;quot;1password-gui&amp;quot;&lt;br /&gt;
    &amp;quot;1password&amp;quot;&lt;br /&gt;
  ];&lt;br /&gt;
  # Alternatively, you could also just allow all unfree packages&lt;br /&gt;
  # nixpkgs.config.allowUnfree = true;&lt;br /&gt;
&lt;br /&gt;
  programs._1password.enable = true;&lt;br /&gt;
  programs._1password-gui = {&lt;br /&gt;
    enable = true;&lt;br /&gt;
    # Certain features, including CLI integration and system authentication support,&lt;br /&gt;
    # require enabling PolKit integration on some desktop environments (e.g. Plasma).&lt;br /&gt;
    polkitPolicyOwners = [ &amp;quot;yourUsernameHere&amp;quot; ];&lt;br /&gt;
  };&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Unlocking browser extensions ===&lt;br /&gt;
&lt;br /&gt;
{{warning|1=This only works for browsers that are installed via [[NixOS]]. Browsers installed via [[Flatpak]] are not supported.}}&lt;br /&gt;
&lt;br /&gt;
The 1Password app can unlock your browser extension using a special [https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Native_messaging native messaging] process.  This streamlines your 1Password experience: Once you unlock 1Password from your tray icon, your browser extensions will be unlocked as well.  &lt;br /&gt;
&lt;br /&gt;
This is automatically configured for [[Firefox]], [[Chrome]], and [[Brave]] browsers.  However, [[Vivaldi]] and other custom Chrome-based browsers may not unlock when you unlock 1Password.  If you find this to be the case, the solution is to set the  &amp;lt;code&amp;gt;/etc/1password/custom_allowed_browsers&amp;lt;/code&amp;gt; file as follows:&lt;br /&gt;
&lt;br /&gt;
* First, use &amp;lt;code&amp;gt;ps aux&amp;lt;/code&amp;gt; to find the application name for the browser.  For Vivaldi, this is &amp;lt;code&amp;gt;vivaldi-bin&amp;lt;/code&amp;gt;&lt;br /&gt;
* Add that binary name to &amp;lt;code&amp;gt;/etc/1password/custom_allowed_browsers&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
    environment.etc = {&lt;br /&gt;
      &amp;quot;1password/custom_allowed_browsers&amp;quot; = {&lt;br /&gt;
        text = &#039;&#039;&lt;br /&gt;
          vivaldi-bin&lt;br /&gt;
          wavebox&lt;br /&gt;
        &#039;&#039;;&lt;br /&gt;
        mode = &amp;quot;0755&amp;quot;;&lt;br /&gt;
      };&lt;br /&gt;
    };&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Unlocking with System Authentication ===&lt;br /&gt;
&lt;br /&gt;
1Password allows [https://support.1password.com/system-authentication-linux/ unlocking with system authentication]. This means fingerprints or login passwords may be used in addition to the master password. This must be enabled under the Security preferences tab of 1Password as outlined in the 1Password documentation, but also requires a few other system tools to work.&lt;br /&gt;
&lt;br /&gt;
For the graphical authentication prompt to work, a user [[Polkit#Authentication_agents|Polkit authentication agent]] must be started. The authentication agent may automatically be started under Gnome, KDE, or other DE at login, but may need to be explicitly enabled for other window managers.&lt;br /&gt;
&lt;br /&gt;
For fingerprint unlocking to work, [[Fingerprint scanner|fingerprint scanning]] to be enabled and allowed for typical system authentication.&lt;br /&gt;
&lt;br /&gt;
== Home Manager ==&lt;br /&gt;
&lt;br /&gt;
{{warning|1=Non-[[NixOS]] installs [https://1password.community/discussion/comment/655813/#Comment_655813 will not link with browser extensions or system authentication] }}&lt;br /&gt;
&lt;br /&gt;
=== Installation ===&lt;br /&gt;
&lt;br /&gt;
Add the following to your [[Home Manager]] configuration:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
  home.packages = [&lt;br /&gt;
    pkgs._1password&lt;br /&gt;
    pkgs._1password-gui&lt;br /&gt;
  ];&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH key management ===&lt;br /&gt;
&lt;br /&gt;
1Password [https://developer.1password.com/docs/ssh/ can manage SSH keys].&lt;br /&gt;
&lt;br /&gt;
==== Configuring SSH ====&lt;br /&gt;
&lt;br /&gt;
If 1Password manages your [[SSH]] keys and you use [[Home Manager]], you may also configure your &amp;lt;code&amp;gt;~/.ssh/config&amp;lt;/code&amp;gt; file using Nix:&lt;br /&gt;
&lt;br /&gt;
{{note|In order to start the 1Password SSH agent, you must open the 1Password settings, go to the Developer section and check the checkbox &amp;quot;Use the SSH agent&amp;quot;.}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
_: let&lt;br /&gt;
  # onePassPath = &amp;quot;~/Library/Group Containers/2BUA8C4S2C.com.1password/t/agent.sock&amp;quot;;&lt;br /&gt;
  onePassPath = &amp;quot;~/.1password/agent.sock&amp;quot;;&lt;br /&gt;
in {&lt;br /&gt;
  programs.ssh = {&lt;br /&gt;
    enable = true;&lt;br /&gt;
    extraConfig = &#039;&#039;&lt;br /&gt;
      Host *&lt;br /&gt;
          IdentityAgent ${onePassPath}&lt;br /&gt;
    &#039;&#039;;&lt;br /&gt;
  };&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configuring Git ====&lt;br /&gt;
&lt;br /&gt;
You can enable [[Git]]&#039;s [[SSH]] signing with [[Home Manager]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  programs.git = {&lt;br /&gt;
    enable = true;&lt;br /&gt;
    extraConfig = {&lt;br /&gt;
      gpg = {&lt;br /&gt;
        format = &amp;quot;ssh&amp;quot;;&lt;br /&gt;
      };&lt;br /&gt;
      &amp;quot;gpg \&amp;quot;ssh\&amp;quot;&amp;quot; = {&lt;br /&gt;
        program = &amp;quot;${lib.getExe&#039; pkgs._1password-gui &amp;quot;op-ssh-sign&amp;quot;}&amp;quot;;&lt;br /&gt;
      };&lt;br /&gt;
      commit = {&lt;br /&gt;
        gpgsign = true;&lt;br /&gt;
      };&lt;br /&gt;
&lt;br /&gt;
      user = {&lt;br /&gt;
        signingKey = &amp;quot;...&amp;quot;;&lt;br /&gt;
      };&lt;br /&gt;
    };&lt;br /&gt;
  };&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Applications]]&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=Nixpkgs_enhancements&amp;diff=22740</id>
		<title>Nixpkgs enhancements</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=Nixpkgs_enhancements&amp;diff=22740"/>
		<updated>2025-06-09T06:44:51Z</updated>

		<summary type="html">&lt;p&gt;Pigs: mark for deletion&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{delete}}&lt;br /&gt;
&lt;br /&gt;
(Under construction; please see [[Talk: Nixpkgs enhancements|Discussion]] about what should go here.)&lt;br /&gt;
&lt;br /&gt;
[[Category:Nixpkgs]]&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=Template_talk:NixOS_Manual&amp;diff=22738</id>
		<title>Template talk:NixOS Manual</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=Template_talk:NixOS_Manual&amp;diff=22738"/>
		<updated>2025-06-09T06:31:32Z</updated>

		<summary type="html">&lt;p&gt;Pigs: /* {{Manual }}does not work for nixos manual */ new section&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== {{{{:manual}} }}does not work for nixos manual ==&lt;br /&gt;
&lt;br /&gt;
Currently, {{:manual}} only links to https://nix.dev, the nix language reference material and does not have capabilities to link to https://nixos.org/manual/nixos where the nixos manual lives. &lt;br /&gt;
&lt;br /&gt;
Until {{:manual}} can link to the nixos manual, I don&#039;t think marking this page for removal is appropriate. [[User:Pigs|Pigs]] ([[User talk:Pigs|talk]]) 06:31, 9 June 2025 (UTC)&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=NixOS_as_a_desktop&amp;diff=22736</id>
		<title>NixOS as a desktop</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=NixOS_as_a_desktop&amp;diff=22736"/>
		<updated>2025-06-09T05:49:37Z</updated>

		<summary type="html">&lt;p&gt;Pigs: update flake link to new page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;languages/&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:1--&amp;gt;&lt;br /&gt;
[[NixOS]] is a versatile operating system suitable for a wide range of use cases. This page is intended for users who wish to run NixOS as their primary desktop environment, either on physical hardware or within a virtual machine. Additionally, users planning to deploy NixOS in [[NixOS friendly hosters|cloud]] environments or on specialized server infrastructure may find it helpful to begin with the concepts and practices introduced here, as they provide a useful foundation for working within the broader [[Nix ecosystem]].&lt;br /&gt;
&lt;br /&gt;
== Installation == &amp;lt;!--T:2--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:4--&amp;gt;&lt;br /&gt;
Refer to [[NixOS Installation Guide]] to get started. Keep in mind that, for a desktop installation, you will probably want to make sure you start with at least 30 GiB of available disk space to allow for the [[:Category:Desktop environment|desktop environments]], [[:Category:Web Browser|web browsers]], and other [[:Category:Applications|graphical applications]], that would be typical of daily use. 15 GiB might be enough for a fairly bare-bones setup.&lt;br /&gt;
&lt;br /&gt;
== Managing your configuration == &amp;lt;!--T:7--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:8--&amp;gt;&lt;br /&gt;
As described in the [[Overview of the NixOS Linux distribution#Declarative Configuration]], NixOS is designed to be configured declaratively. This means the entire system configuration, including installed packages, system services, kernel parameters, and user accounts is defined in configuration files, typically in &amp;lt;code&amp;gt;/etc/nixos/configuration.nix&amp;lt;/code&amp;gt;. These settings can then be applied consistently and reproducibly across machines.&lt;br /&gt;
&lt;br /&gt;
The process for managing your configuration is documented in the {{NixOS Manual|name=NixOS official manual|anchor=#ch-configuration}}.&lt;br /&gt;
&lt;br /&gt;
=== System Configuration ===&lt;br /&gt;
&lt;br /&gt;
{{main|NixOS system configuration}}&lt;br /&gt;
&lt;br /&gt;
The primary configuration file, &amp;lt;code&amp;gt;/etc/nixos/configuration.nix&amp;lt;/code&amp;gt;, defines system-wide settings. This includes options like enabling services, managing system users, setting hardware options, and specifying installed packages. Changes are applied with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
# nixos-rebuild switch&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== User configuration with Home Manager ===&lt;br /&gt;
&lt;br /&gt;
For managing per-user configurations such as application preferences, command-line tools, and dotfiles, [[Home Manager]] provides a convenient, declarative approach. It allows users to define which programs should be installed and how they should be configured, without needing to include those settings in the system-wide [https://nixos.org/manual/nixos/stable/#sec-changing-config configuration.nix].&lt;br /&gt;
&lt;br /&gt;
Home Manager can be used independently of the system configuration and works with both traditional setups and newer [[Flakes]]-based configurations.&lt;br /&gt;
&lt;br /&gt;
=== With Flakes === &amp;lt;!--T:17--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:18--&amp;gt;&lt;br /&gt;
For users looking for a more streamlined and reproducible way to manage NixOS configurations, the [[Flakes]] feature has been gaining popularity within the community. While Flakes introduce some new concepts compared to traditional workflows, many users find them a convenient and organized approach to managing system and development configurations.&lt;br /&gt;
&lt;br /&gt;
Refer to [[NixOS system configuration#Defining NixOS as a flake]] for details on getting started.&lt;br /&gt;
&lt;br /&gt;
== Beyond initial setup == &amp;lt;!--T:21--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:22--&amp;gt;&lt;br /&gt;
Once your basic NixOS installation is complete and functional, you can further customize your system with a variety of optional configurations tailored for desktop use. For a list of recommended initial system configurations, see [[NixOS Installation Guide#NixOS configuration]].&lt;br /&gt;
&lt;br /&gt;
Common configuration areas include:&lt;br /&gt;
&lt;br /&gt;
==== Desktop Environments ====&lt;br /&gt;
&lt;br /&gt;
Install and configure full-featured environments such as [[GNOME]], [[KDE Plasma]], or [[Xfce]].&lt;br /&gt;
&lt;br /&gt;
See [[:Category:Desktop environment]] for a full list.&lt;br /&gt;
&lt;br /&gt;
==== Window Managers ====&lt;br /&gt;
&lt;br /&gt;
Set up lightweight or tiling window managers like [[i3]], [[Sway]], [[Hyprland]], or [[xmonad]].&lt;br /&gt;
&lt;br /&gt;
See [[:Category:Window managers]] for a full list.&lt;br /&gt;
&lt;br /&gt;
==== Display Managers (Login Managers) ==== &lt;br /&gt;
&lt;br /&gt;
Configure graphical session managers such as [[Gnome|GDM]], [[KDE|SDDM]], or [[LightDM]].&lt;br /&gt;
&lt;br /&gt;
==== Audio Setup ====&lt;br /&gt;
&lt;br /&gt;
Enable and configure [[:Category:Audio|audio]] systems like [[PipeWire]], [[PulseAudio]], or [[ALSA]].&lt;br /&gt;
&lt;br /&gt;
==== Network Management ====&lt;br /&gt;
&lt;br /&gt;
Use tools such as [[NetworkManager]] or [[systemd-networkd]] for managing [[Networking|network]] connections.&lt;br /&gt;
&lt;br /&gt;
==== Bluetooth Support ====&lt;br /&gt;
&lt;br /&gt;
Set up [[Bluetooth]] with blueman or other management tools.&lt;br /&gt;
&lt;br /&gt;
==== Power Management ====&lt;br /&gt;
&lt;br /&gt;
Configure [[laptop]] [[Power Management|battery management]], suspend, and hibernation with tools like [[Laptop#tlp|tlp]] or [[systemd]] services.&lt;br /&gt;
&lt;br /&gt;
==== Printing and Scanning ==== &lt;br /&gt;
&lt;br /&gt;
Enable [[Cups]] for printer support and tools like Sane for [[Scanners|scanning]] devices.&lt;br /&gt;
&lt;br /&gt;
== Tips and tricks == &amp;lt;!--T:12--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Modularizing your configuration with modules === &amp;lt;!--T:13--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{main|NixOS system configuration#Modularizing your configuration with modules}}&lt;br /&gt;
&lt;br /&gt;
== See also == &amp;lt;!--T:23--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:25--&amp;gt;&lt;br /&gt;
* [[Overview of the NixOS Linux distribution]]&lt;br /&gt;
* [[Comparison of NixOS setups]] for a table comparing some popular choices.&lt;br /&gt;
* [[Configuration Collection]] for a long list within the wiki.&lt;br /&gt;
* [https://github.com/topics/nix-flake nix-flake], [https://github.com/topics/nixos-configuration nixos-configuration], [https://github.com/topics/nixos-dotfiles nixos-dotfiles] Github topics&lt;br /&gt;
* [[Wil T Nix Guides]] Youtube video format guide&lt;br /&gt;
&lt;br /&gt;
[[Category:Desktop]]&lt;br /&gt;
[[Category:Guide]]&lt;br /&gt;
[[Category:NixOS]]&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=NixOS_as_a_desktop&amp;diff=22730</id>
		<title>NixOS as a desktop</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=NixOS_as_a_desktop&amp;diff=22730"/>
		<updated>2025-06-09T05:16:20Z</updated>

		<summary type="html">&lt;p&gt;Pigs: /* System Configuration */ add link to system configuration&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;languages/&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:1--&amp;gt;&lt;br /&gt;
[[NixOS]] is a versatile operating system suitable for a wide range of use cases. This page is intended for users who wish to run NixOS as their primary desktop environment, either on physical hardware or within a virtual machine. Additionally, users planning to deploy NixOS in [[NixOS friendly hosters|cloud]] environments or on specialized server infrastructure may find it helpful to begin with the concepts and practices introduced here, as they provide a useful foundation for working within the broader [[Nix ecosystem]].&lt;br /&gt;
&lt;br /&gt;
== Installation == &amp;lt;!--T:2--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:4--&amp;gt;&lt;br /&gt;
Refer to [[NixOS Installation Guide]] to get started. Keep in mind that, for a desktop installation, you will probably want to make sure you start with at least 30 GiB of available disk space to allow for the [[:Category:Desktop environment|desktop environments]], [[:Category:Web Browser|web browsers]], and other [[:Category:Applications|graphical applications]], that would be typical of daily use. 15 GiB might be enough for a fairly bare-bones setup.&lt;br /&gt;
&lt;br /&gt;
== Managing your configuration == &amp;lt;!--T:7--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:8--&amp;gt;&lt;br /&gt;
As described in the [[Overview of the NixOS Linux distribution#Declarative Configuration]], NixOS is designed to be configured declaratively. This means the entire system configuration, including installed packages, system services, kernel parameters, and user accounts is defined in configuration files, typically in &amp;lt;code&amp;gt;/etc/nixos/configuration.nix&amp;lt;/code&amp;gt;. These settings can then be applied consistently and reproducibly across machines.&lt;br /&gt;
&lt;br /&gt;
The process for managing your configuration is documented in the {{NixOS Manual|name=NixOS official manual|anchor=#ch-configuration}}.&lt;br /&gt;
&lt;br /&gt;
=== System Configuration ===&lt;br /&gt;
&lt;br /&gt;
{{main|NixOS system configuration}}&lt;br /&gt;
&lt;br /&gt;
The primary configuration file, &amp;lt;code&amp;gt;/etc/nixos/configuration.nix&amp;lt;/code&amp;gt;, defines system-wide settings. This includes options like enabling services, managing system users, setting hardware options, and specifying installed packages. Changes are applied with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
# nixos-rebuild switch&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== User configuration with Home Manager ===&lt;br /&gt;
&lt;br /&gt;
For managing per-user configurations such as application preferences, command-line tools, and dotfiles, [[Home Manager]] provides a convenient, declarative approach. It allows users to define which programs should be installed and how they should be configured, without needing to include those settings in the system-wide [https://nixos.org/manual/nixos/stable/#sec-changing-config configuration.nix].&lt;br /&gt;
&lt;br /&gt;
Home Manager can be used independently of the system configuration and works with both traditional setups and newer [[Flakes]]-based configurations.&lt;br /&gt;
&lt;br /&gt;
=== With Flakes === &amp;lt;!--T:17--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:18--&amp;gt;&lt;br /&gt;
For users looking for a more streamlined and reproducible way to manage NixOS configurations, the [[Flakes]] feature has been gaining popularity within the community. While Flakes introduce some new concepts compared to traditional workflows, many users find them a convenient and organized approach to managing system and development configurations.&lt;br /&gt;
&lt;br /&gt;
Refer to [[Flakes#NixOS configuration with flakes]] for details on getting started.&lt;br /&gt;
&lt;br /&gt;
== Beyond initial setup == &amp;lt;!--T:21--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:22--&amp;gt;&lt;br /&gt;
Once your basic NixOS installation is complete and functional, you can further customize your system with a variety of optional configurations tailored for desktop use. For a list of recommended initial system configurations, see [[NixOS Installation Guide#NixOS configuration]].&lt;br /&gt;
&lt;br /&gt;
Common configuration areas include:&lt;br /&gt;
&lt;br /&gt;
==== Desktop Environments ====&lt;br /&gt;
&lt;br /&gt;
Install and configure full-featured environments such as [[GNOME]], [[KDE Plasma]], or [[Xfce]].&lt;br /&gt;
&lt;br /&gt;
See [[:Category:Desktop environment]] for a full list.&lt;br /&gt;
&lt;br /&gt;
==== Window Managers ====&lt;br /&gt;
&lt;br /&gt;
Set up lightweight or tiling window managers like [[i3]], [[Sway]], [[Hyprland]], or [[xmonad]].&lt;br /&gt;
&lt;br /&gt;
See [[:Category:Window managers]] for a full list.&lt;br /&gt;
&lt;br /&gt;
==== Display Managers (Login Managers) ==== &lt;br /&gt;
&lt;br /&gt;
Configure graphical session managers such as [[Gnome|GDM]], [[KDE|SDDM]], or [[LightDM]].&lt;br /&gt;
&lt;br /&gt;
==== Audio Setup ====&lt;br /&gt;
&lt;br /&gt;
Enable and configure [[:Category:Audio|audio]] systems like [[PipeWire]], [[PulseAudio]], or [[ALSA]].&lt;br /&gt;
&lt;br /&gt;
==== Network Management ====&lt;br /&gt;
&lt;br /&gt;
Use tools such as [[NetworkManager]] or [[systemd-networkd]] for managing [[Networking|network]] connections.&lt;br /&gt;
&lt;br /&gt;
==== Bluetooth Support ====&lt;br /&gt;
&lt;br /&gt;
Set up [[Bluetooth]] with blueman or other management tools.&lt;br /&gt;
&lt;br /&gt;
==== Power Management ====&lt;br /&gt;
&lt;br /&gt;
Configure [[laptop]] [[Power Management|battery management]], suspend, and hibernation with tools like [[Laptop#tlp|tlp]] or [[systemd]] services.&lt;br /&gt;
&lt;br /&gt;
==== Printing and Scanning ==== &lt;br /&gt;
&lt;br /&gt;
Enable [[Cups]] for printer support and tools like Sane for [[Scanners|scanning]] devices.&lt;br /&gt;
&lt;br /&gt;
== Tips and tricks == &amp;lt;!--T:12--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Modularizing your configuration with modules === &amp;lt;!--T:13--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{main|NixOS system configuration#Modularizing your configuration with modules}}&lt;br /&gt;
&lt;br /&gt;
== See also == &amp;lt;!--T:23--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:25--&amp;gt;&lt;br /&gt;
* [[Overview of the NixOS Linux distribution]]&lt;br /&gt;
* [[Comparison of NixOS setups]] for a table comparing some popular choices.&lt;br /&gt;
* [[Configuration Collection]] for a long list within the wiki.&lt;br /&gt;
* [https://github.com/topics/nix-flake nix-flake], [https://github.com/topics/nixos-configuration nixos-configuration], [https://github.com/topics/nixos-dotfiles nixos-dotfiles] Github topics&lt;br /&gt;
* [[Wil T Nix Guides]] Youtube video format guide&lt;br /&gt;
&lt;br /&gt;
[[Category:Desktop]]&lt;br /&gt;
[[Category:Guide]]&lt;br /&gt;
[[Category:NixOS]]&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=NixOS_Installation_Guide&amp;diff=22729</id>
		<title>NixOS Installation Guide</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=NixOS_Installation_Guide&amp;diff=22729"/>
		<updated>2025-06-09T05:10:52Z</updated>

		<summary type="html">&lt;p&gt;Pigs: /* NixOS configuration */ add links to other pages&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;languages/&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:1--&amp;gt;&lt;br /&gt;
This guide serves as a companion guide for the [https://nixos.org/nixos/manual/index.html#ch-installation official manual]. It describes installation of [[NixOS]] as a complete operating system. For instructions on installing [[Nix]] within an existing operating system, refer to the [[Nix Installation Guide]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:2--&amp;gt;&lt;br /&gt;
In addition to covering the steps from the official manual, it provides known good instructions for common use cases. When there is a discrepancy between the manual and this guide, the supported case is the one described in the manual.&lt;br /&gt;
&lt;br /&gt;
== Installation target == &amp;lt;!--T:4--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:5--&amp;gt;&lt;br /&gt;
NixOS can be installed on an increasing variety of hardware:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:6--&amp;gt;&lt;br /&gt;
* regular (Intel or AMD) desktop computers, laptops or physically accessible servers, covered on this page&lt;br /&gt;
* SBCs (like the Raspberry Pis) and other ARM boards, see [[NixOS on ARM]]&lt;br /&gt;
* cloud and remote servers, see [[NixOS friendly hosters]]&lt;br /&gt;
&lt;br /&gt;
== Installation method == &amp;lt;!--T:7--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:8--&amp;gt;&lt;br /&gt;
NixOS, as with most Linux-based operating systems, can be installed in different ways.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:9--&amp;gt;&lt;br /&gt;
# The classic way, booting from the installation media. (Described below.)&lt;br /&gt;
# [[Installing from Linux|Booting the media from an existing Linux installation]]&lt;br /&gt;
&lt;br /&gt;
== Making the installation media == &amp;lt;!--T:10--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:11--&amp;gt;&lt;br /&gt;
Since NixOS 14.11 the installer ISO is hybrid. This means it is bootable on both CD and USB drives. It also boots on EFI systems, like most modern motherboards and apple systems. The following instructions will assume the standard way of copying the image to a USB drive. When using a CD or DVD, the usual methods to burn to disk should work with the iso.&lt;br /&gt;
&lt;br /&gt;
=== &amp;quot;Burning&amp;quot; to USB drive === &amp;lt;!--T:12--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:13--&amp;gt;&lt;br /&gt;
First, download a [https://nixos.org/download.html#nixos-iso NixOS ISO image] or [[Creating a NixOS live CD|create a custom ISO]]. Then plug in a USB stick large enough to accommodate the image. Then follow the platform instructions:&lt;br /&gt;
&lt;br /&gt;
==== From Linux ==== &amp;lt;!--T:14--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:15--&amp;gt;&lt;br /&gt;
# Find the right device with &amp;lt;code&amp;gt;lsblk&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;fdisk -l&amp;lt;/code&amp;gt;. Replace &amp;lt;code&amp;gt;&amp;lt;i&amp;gt;/dev/sdX&amp;lt;/i&amp;gt;&amp;lt;/code&amp;gt; with the proper device in the following steps.&lt;br /&gt;
# Copy to device: &amp;lt;code&amp;gt;cp nixos-xxx.iso &amp;lt;em&amp;gt;/dev/sdX&amp;lt;/em&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:16--&amp;gt;&lt;br /&gt;
{{note|do not use /dev/sdX1 or partitions of the disk, use the whole disk /dev/sdX.}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:17--&amp;gt;&lt;br /&gt;
Writing the disk image with &amp;lt;code&amp;gt;dd if=nixos.iso of=/dev/sdX bs=4M status=progress conv=fdatasync&amp;lt;/code&amp;gt; also works.&lt;br /&gt;
&lt;br /&gt;
==== From macOS ==== &amp;lt;!--T:18--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:19--&amp;gt;&lt;br /&gt;
# Find the right device with &amp;lt;code&amp;gt;diskutil list&amp;lt;/code&amp;gt;, let&#039;s say &amp;lt;code&amp;gt;&amp;lt;i&amp;gt;diskX&amp;lt;/i&amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
# Unmount with &amp;lt;code&amp;gt;diskutil unmountDisk &amp;lt;i&amp;gt;diskX&amp;lt;/i&amp;gt;&amp;lt;/code&amp;gt;.&lt;br /&gt;
# Burn with: &amp;lt;code&amp;gt;sudo dd if=&amp;lt;b&amp;gt;path_to_nixos.iso&amp;lt;/b&amp;gt; of=/dev/&amp;lt;i&amp;gt;diskX&amp;lt;/i&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:20--&amp;gt;&lt;br /&gt;
{{tip|Using &amp;lt;code&amp;gt;rdiskX&amp;lt;/code&amp;gt; instead of &amp;lt;code&amp;gt;diskX&amp;lt;/code&amp;gt; can makes a large speed difference. You can check the write speed with &amp;lt;code&amp;gt;iostat 2&amp;lt;/code&amp;gt; in another terminal.}}&lt;br /&gt;
&lt;br /&gt;
==== From Windows ==== &amp;lt;!--T:21--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:22--&amp;gt;&lt;br /&gt;
# Download [http://sourceforge.net/projects/usbwriter/ USBwriter].&lt;br /&gt;
# Start USBwriter.&lt;br /&gt;
# Choose the downloaded ISO as &#039;Source&#039;&lt;br /&gt;
# Choose the USB drive as &#039;Target&#039;&lt;br /&gt;
# Click &#039;Write&#039;&lt;br /&gt;
# When USBwriter has finished writing, safely unplug the USB drive.&lt;br /&gt;
&lt;br /&gt;
=== Alternative installation media instructions === &amp;lt;!--T:23--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:24--&amp;gt;&lt;br /&gt;
The previous methods are the supported methods of making the USB installation media.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:25--&amp;gt;&lt;br /&gt;
Those methods are also documented, they can allow using the USB drive to boot multiple distributions. This is not supported, your mileage may vary.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:26--&amp;gt;&lt;br /&gt;
* [[NixOS_Installation_Guide/Unetbootin|Using Unetbootin]]&lt;br /&gt;
* [[NixOS_Installation_Guide/Manual USB Creation|Manual USB Creation]]&lt;br /&gt;
* [[NixOS_Installation_Guide/multibootusb|multibootusb]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:27--&amp;gt;&lt;br /&gt;
== Booting the installation media ==&lt;br /&gt;
{{expansion|Troubleshooting steps, and details are lacking.}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:28--&amp;gt;&lt;br /&gt;
The installation media is hybrid and is capable of booting in both legacy BIOS mode and [[UEFI]] mode.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:29--&amp;gt;&lt;br /&gt;
Whatever mode is used to boot the installation media, your motherboard or computer&#039;s configuration may need to be changed to allow booting from a Optical Disk Drive (for CD/DVD) or an external USB drive.&lt;br /&gt;
&lt;br /&gt;
=== Legacy bios boot === &amp;lt;!--T:30--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:31--&amp;gt;&lt;br /&gt;
This is the only boot possible on machines lacking EFI/UEFI.&lt;br /&gt;
&lt;br /&gt;
=== UEFI boot === &amp;lt;!--T:32--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:33--&amp;gt;&lt;br /&gt;
The EFI bootloader of the installation media is not signed and is not using a signed shim to boot. This means that Secure Boot will need to be disabled to boot.&lt;br /&gt;
&lt;br /&gt;
== Connecting to the internet == &amp;lt;!--T:34--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:35--&amp;gt;&lt;br /&gt;
The installation will &#039;&#039;&#039;definitely&#039;&#039;&#039; need a working internet connection. It is possible to install without one, but the available set of packages is limited.&lt;br /&gt;
&lt;br /&gt;
=== Wired === &amp;lt;!--T:36--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:37--&amp;gt;&lt;br /&gt;
For network interfaces supported by the kernel, DHCP resolution should already have happened once the shell is available.&lt;br /&gt;
&lt;br /&gt;
==Tethered (Internet Sharing)== &amp;lt;!--T:38--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:39--&amp;gt;&lt;br /&gt;
If you can not connect to the internet via cable or wifi, you may use smartphone&#039;s tethering capability to share internet. Depending on your smartphones capabilities, only stock kernel drivers may be required which can help providing a working network connection.&lt;br /&gt;
&lt;br /&gt;
=== Wireless === &amp;lt;!--T:40--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:41--&amp;gt;&lt;br /&gt;
[[NetworkManager]] is installed on the graphical ISO, meaning that it is possible to use &amp;lt;code&amp;gt;nmtui&amp;lt;/code&amp;gt; on the command line to connect to a network.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:42--&amp;gt;&lt;br /&gt;
Using the &amp;quot;Applications&amp;quot; tab at top&lt;br /&gt;
left or the launcher bar at bottom, choose a terminal application and from there launch &amp;lt;code&amp;gt;nmtui&amp;lt;/code&amp;gt;. This will allow you to &#039;activate&#039; a (wireless) connection - your local SSIDs should be visible in the list, else you can add a new connection.  When the wireless connection is active and you have tested it, it is likely the install app which launched on startup has not detected the new connection.  Close down the install app, and reopen it from the launcher bar at the bottom of the screen.  This should then find the new connection and proceed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:43--&amp;gt;&lt;br /&gt;
On the minimal ISO, or if you are more familiar with [[wpa_supplicant]] then you can also run &amp;lt;code&amp;gt;wpa_passphrase ESSID | sudo tee /etc/wpa_supplicant.conf&amp;lt;/code&amp;gt;, then enter your password and &amp;lt;code&amp;gt;systemctl restart wpa_supplicant&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Partitioning == &amp;lt;!--T:44--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:45--&amp;gt;&lt;br /&gt;
To partition the persistent storage run &amp;lt;code&amp;gt;sudo fdisk /dev/diskX&amp;lt;/code&amp;gt; and follow instructions for MBR or (U)EFI. To determine which mode you are booted into, run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
$ [ -d /sys/firmware/efi/efivars ] &amp;amp;&amp;amp; echo &amp;quot;UEFI&amp;quot; || echo &amp;quot;Legacy&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A very simple example setup is given here.&lt;br /&gt;
&lt;br /&gt;
=== Legacy Boot (MBR) === &amp;lt;!--T:46--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:47--&amp;gt;&lt;br /&gt;
* o (dos disk label)&lt;br /&gt;
* n new&lt;br /&gt;
* p primary (4 primary in total)&lt;br /&gt;
* 1 (partition number [1/4])&lt;br /&gt;
* 2048 first sector (alignment for performance)&lt;br /&gt;
* +500M last sector (boot sector size)&lt;br /&gt;
* rm signature (Y), if ex. =&amp;gt; warning of overwriting existing system, could use wipefs&lt;br /&gt;
* n&lt;br /&gt;
* p&lt;br /&gt;
* 2&lt;br /&gt;
* default (fill up partition)&lt;br /&gt;
* default (fill up partition)&lt;br /&gt;
* w (write)&lt;br /&gt;
&lt;br /&gt;
=== UEFI === &amp;lt;!--T:48--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:49--&amp;gt;&lt;br /&gt;
* g (gpt disk label)&lt;br /&gt;
* n&lt;br /&gt;
* 1 (partition number [1/128])&lt;br /&gt;
* 2048 first sector&lt;br /&gt;
* +500M last sector (boot sector size)&lt;br /&gt;
* t&lt;br /&gt;
* 1 (EFI System)&lt;br /&gt;
* n&lt;br /&gt;
* 2&lt;br /&gt;
* default (fill up partition)&lt;br /&gt;
* default (fill up partition)&lt;br /&gt;
* w (write)&lt;br /&gt;
&lt;br /&gt;
=== Format partitions === &amp;lt;!--T:50--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:51--&amp;gt;&lt;br /&gt;
The example below uses the [[ext4]] filesystem format. If you wish to use other filesystem formats such as [[Btrfs]] or [[ZFS]]: &lt;br /&gt;
&lt;br /&gt;
* [[Bcachefs#NixOS installation on bcachefs]]&lt;br /&gt;
* [[Btrfs#Installation of NixOS on btrfs]]&lt;br /&gt;
* [[LVM#Basic Setup]]&lt;br /&gt;
* [[ZFS#Simple NixOS ZFS on root installation]]&lt;br /&gt;
&lt;br /&gt;
This is useful for having multiple setups and makes partitions easier to handle&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
$ lsblk # lists current system block devices&lt;br /&gt;
# mkfs.fat -F 32 -n boot /dev/sdX1&lt;br /&gt;
# mkfs.ext4 /dev/sdX2 -L nixos&lt;br /&gt;
# mount /dev/disk/by-label/root /mnt&lt;br /&gt;
# mkdir -p /mnt/boot&lt;br /&gt;
# mount /dev/disk/by-label/boot /mnt/boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:53--&amp;gt;&lt;br /&gt;
== NixOS configuration ==&lt;br /&gt;
&lt;br /&gt;
NixOS is configured through a [[Overview of the NixOS Linux distribution#Declarative Configuration|declarative configuration]] file. To generate a default config file, run [[nixos-generate-config]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
# nixos-generate-config --root /mnt&lt;br /&gt;
# nano /mnt/etc/nixos/configuration.nix&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For information on working with a system configuration, see [[NixOS system configuration]]. For desktop-specific configurations, see [[NixOS as a desktop]].&lt;br /&gt;
&lt;br /&gt;
Most essential changes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:54--&amp;gt;&lt;br /&gt;
* keyboard layout, ie &amp;lt;code&amp;gt;[[Keyboard Layout Customization|services.xserver.xkb.layout]]&amp;lt;/code&amp;gt;&lt;br /&gt;
* [[networking]] (wifi), see below for fix if it breaks&lt;br /&gt;
* install [[:Category:Text Editor|editor]] to edit the configuration&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:55--&amp;gt;&lt;br /&gt;
The self-documenting NixOS options can be searched with [https://search.nixos.org/options NixOS options search].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:52--&amp;gt;&lt;br /&gt;
=== Swap file ===&lt;br /&gt;
&lt;br /&gt;
For additional methods of configuring swap, see [[Swap]]. The following example demonstrates how to create and enable a [[Swap#Swap file|swap file]]:&lt;br /&gt;
&lt;br /&gt;
{{file|/mnt/etc/nixos/configuration.nix|nix|&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
  swapDevices = [{&lt;br /&gt;
    device = &amp;quot;/var/lib/swapfile&amp;quot;;&lt;br /&gt;
    size = 16*1024; # 16 GB&lt;br /&gt;
  }];&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Bootloader ===&lt;br /&gt;
&lt;br /&gt;
NixOS supports multiple [[Bootloader|bootloaders]] such as [[GNU GRUB]] and [[Systemd/boot]].&lt;br /&gt;
&lt;br /&gt;
Sysyemd-boot is the recommended bootloader. The following example demonstrates how to enable systemd-boot in your configuration:&lt;br /&gt;
&lt;br /&gt;
{{file|/mnt/etc/nixos/configuration.nix|nix|&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
  boot.loader.systemd-boot.enable = true;&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
You may also wish to configure [[Secure Boot]].&lt;br /&gt;
&lt;br /&gt;
=== Users ===&lt;br /&gt;
&lt;br /&gt;
For information on creating and managing users, see [[User management]] and the {{NixOS Manual|name=NixOS Manual: Chapter - Package Management|anchor=#sec-user-management}}. See an example below:&lt;br /&gt;
&lt;br /&gt;
{{file|/mnt/etc/nixos/configuration.nix|nix|&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
  users.users.alice = {&lt;br /&gt;
    isNormalUser = true;&lt;br /&gt;
    initialPassword = &amp;quot;pw123&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== NixOS installation ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
# cd /mnt&lt;br /&gt;
# nixos-install&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;after installation: Run &amp;lt;code&amp;gt;passwd&amp;lt;/code&amp;gt; to change user password.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:57--&amp;gt;&lt;br /&gt;
if internet broke/breaks, try one of the following:&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
# nixos-rebuild switch --option substitute false # no downloads&lt;br /&gt;
# nixos-rebuild switch --option binary-caches &amp;quot;&amp;quot; # no downloads&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* wpa_supplicant flags to connect to wifi&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:58--&amp;gt;&lt;br /&gt;
&amp;lt;hr /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Additional notes for specific hardware == &amp;lt;!--T:59--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:60--&amp;gt;&lt;br /&gt;
These are collected notes or links for specific hardware issues.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:61--&amp;gt;&lt;br /&gt;
* Blog post how to install NixOS on a [http://grahamc.com/blog/nixos-on-dell-9560 Dell 9560]&lt;br /&gt;
* Brand servers may require extra kernel modules be included into initrd (&amp;lt;code&amp;gt;boot.initrd.extraKernelModules&amp;lt;/code&amp;gt; in configuration.nix) For example HP Proliant needs &amp;quot;hpsa&amp;quot; module to see the disk drive.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:62--&amp;gt;&lt;br /&gt;
[[Category:Guide]]&lt;br /&gt;
[[Category:Deployment]]&lt;br /&gt;
[[Category:NixOS]]&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=Template_talk:Nixos:package&amp;diff=22724</id>
		<title>Template talk:Nixos:package</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=Template_talk:Nixos:package&amp;diff=22724"/>
		<updated>2025-06-09T01:56:15Z</updated>

		<summary type="html">&lt;p&gt;Pigs: /* Deletion candidate */ Reply&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Deletion candidate ==&lt;br /&gt;
&lt;br /&gt;
Completely disagree about deleting this template. &lt;br /&gt;
&lt;br /&gt;
* {{nixpkgs}} links to the github page. That is not user friendly. Someone should not have to read source code files to understand module package options and descriptions. The UI on search.nixos.org is much more user friendly.&lt;br /&gt;
* It is not LMGTFY as packages are not always indexed on search engines. It took me a long time as a NixOS user to learn about the existence of search.nixos.org, it should not be assumed that everyone is familiar with this service.&lt;br /&gt;
* This is one of the most used templates on the wiki.&lt;br /&gt;
&lt;br /&gt;
If anything, in my opinion we should be encouraging {{nixos:package}} over the use of {{nixpkgs}} unless if there is a specific reason that a user would find the source code important. [[User:Pigs|Pigs]] ([[User talk:Pigs|talk]]) 05:31, 8 June 2025 (UTC)&lt;br /&gt;
&lt;br /&gt;
:I &#039;&#039;would agree&#039;&#039; with you &#039;&#039;if&#039;&#039; the core of the argument was implemented properly on the search page. I &#039;&#039;&#039;am 100% on the same page&#039;&#039;&#039; that we should aim for readability and user friendliness here. But that&#039;s exactly why I don&#039;t think this template hits the mark on that front.&lt;br /&gt;
:&amp;lt;blockquote&amp;gt;Someone should not have to read source code files to understand module &#039;&#039;&#039;package options&#039;&#039;&#039; and descriptions.&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
:That&#039;s exactly the thing: the search functionality doesn&#039;t expose package options at all. The only way an user can learn about them is by reading the source code. Is that ideal? Of course not, but it is currently what it is. &lt;br /&gt;
:As for the description part, I would say in 99% of the time when this template is used, it&#039;s used either in the corresponding package&#039;s article, or in a context where adding the package description is trivial.&lt;br /&gt;
:For the second point, I think we should definitely be improving the main page itself to point the user to the search functionality as an option, as well as improving [[NixOS search]]. And on top of that, we probably want a [[First steps using NixOS]] page or similar to really drive this point home.&lt;br /&gt;
:For the third point, I don&#039;t think a package&#039;s current usage is an argument for or against its deletion (other than on technicality: we&#039;d of course want to modify all pages using this template to point to the new one). However, do note, it&#039;s only used in [[Special:WhatLinksHere/Template:Nixos:package|24 pages]], hardly an edit burden. [[User:DoggoBit|DoggoBit]] ([[User talk:DoggoBit|talk]]) 17:10, 8 June 2025 (UTC)&lt;br /&gt;
::When I was writing my reply I kept mistakenly was thinking of the {{:nixos:option}} template which is much more of a useful and popular template. My mistake. &lt;br /&gt;
::You are right that currently linking to a package on search.nixos.org does not provide as much information as it should. (It&#039;s more on the package maintainers to provide useful descriptions (like the {{nixos:package|docker}} maintainers do) than it is of a missing feature from search.nixos.org.&lt;br /&gt;
::I still hold my position that linking to {{nixos:package|ghc}} is a way better user experience than linking to {{Nixpkgs Link|pkgs/development/compilers/ghc/common-hadrian.nix}} both in terms of a maintainer and as an end user.&lt;br /&gt;
::To me, linking to source code is a bad option when there is a friendly interface that displays all the relevant information such as &#039;&#039;&#039;programs provided&#039;&#039;&#039;, &#039;&#039;&#039;current version&#039;&#039;&#039;, &#039;&#039;&#039;outputs&#039;&#039;&#039;, and if a user wants to, there is a link to the source code on the search result. How fast can you find that information on the Nixpkgs link? The version isn&#039;t even mentioned in the source code of the main file for GHC. [[User:Pigs|Pigs]] ([[User talk:Pigs|talk]]) 21:31, 8 June 2025 (UTC)&lt;br /&gt;
:::Yeah, I&#039;m 100% with you on this, and {{tl|nixos:option}} is nowhere near being at risk of not making the cut here haha (other than a saner renaming). That template is a million times more useful than this one.&lt;br /&gt;
:::I&#039;m thinking here very much from a user perspective: If I&#039;m being served a link off the wiki, I would want it to contain &#039;&#039;more&#039;&#039; information than the wiki itself, right? Otherwise there&#039;s no point linking somewhere external in the first place. That&#039;s why I don&#039;t think this template makes sense with the current search interface at all, it&#039;s &#039;&#039;less useful&#039;&#039; than the page it&#039;s being used on. However, linking to the nixpkgs file is &#039;&#039;more usefu&#039;&#039; than the page, because the user can see the additional build options that package may have.&lt;br /&gt;
:::If we&#039;re talking about having &#039;&#039;a link&#039;&#039; to the corresponding Nix package entry, we could implement this via {{tl|infobox application}} (or the corresponding one) further down the line [[User:DoggoBit|DoggoBit]] ([[User talk:DoggoBit|talk]]) 21:55, 8 June 2025 (UTC)&lt;br /&gt;
::::But linking to search.nixos.org &#039;&#039;&#039;DOES&#039;&#039;&#039; provide more information on packages than linking to the nixpkgs source code. The search query result includes the link to the source code AND more. See my example above with the &amp;lt;code&amp;gt;ghc&amp;lt;/code&amp;gt; package. &lt;br /&gt;
::::It is useful to the end user as it &#039;&#039;&#039;DOES&#039;&#039;&#039; include more information than what is on a wiki page, such as the current version. We wouldn&#039;t want to include information like package versions on the wiki since they can update very frequently. Would be cool to maybe auto-generate an {{:infobox application}} with the nixpkg information. I&#039;ve toyed around with this idea before and have gone as so far to make a prototype mediawiki plugin that does it.&lt;br /&gt;
::::&amp;lt;br&amp;gt;&lt;br /&gt;
::::Another example that I have used {{:nixos:package}} in the past has been linking to package sets. For example, {{nixos:package|haskellPackages.*}}. What am I suppose to do here? Link to the nixpkg file that contains all the haskellPackages that is so big it can&#039;t even render on github? https://github.com/NixOS/nixpkgs/blob/nixos-25.05/pkgs/development/haskell-modules/hackage-packages.nix&lt;br /&gt;
::::&amp;lt;br&amp;gt;&lt;br /&gt;
::::This isn&#039;t most useful template, but it still has use cases and adds value to some wiki pages. I&#039;m up for replacing this template with something else that contains the same information as search.nixos.org has on packages, but as I am aware that information is only able to be generated from evaluating the nix expressions in nixpkgs (which search.nixos.org does and stores it in an elasticache instance). [[User:Pigs|Pigs]] ([[User talk:Pigs|talk]]) 01:56, 9 June 2025 (UTC)&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=Template_talk:Nixos:package&amp;diff=22654</id>
		<title>Template talk:Nixos:package</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=Template_talk:Nixos:package&amp;diff=22654"/>
		<updated>2025-06-08T21:31:12Z</updated>

		<summary type="html">&lt;p&gt;Pigs: /* Deletion candidate */ Reply&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Deletion candidate ==&lt;br /&gt;
&lt;br /&gt;
Completely disagree about deleting this template. &lt;br /&gt;
&lt;br /&gt;
* {{nixpkgs}} links to the github page. That is not user friendly. Someone should not have to read source code files to understand module package options and descriptions. The UI on search.nixos.org is much more user friendly.&lt;br /&gt;
* It is not LMGTFY as packages are not always indexed on search engines. It took me a long time as a NixOS user to learn about the existence of search.nixos.org, it should not be assumed that everyone is familiar with this service.&lt;br /&gt;
* This is one of the most used templates on the wiki.&lt;br /&gt;
&lt;br /&gt;
If anything, in my opinion we should be encouraging {{nixos:package}} over the use of {{nixpkgs}} unless if there is a specific reason that a user would find the source code important. [[User:Pigs|Pigs]] ([[User talk:Pigs|talk]]) 05:31, 8 June 2025 (UTC)&lt;br /&gt;
&lt;br /&gt;
:I &#039;&#039;would agree&#039;&#039; with you &#039;&#039;if&#039;&#039; the core of the argument was implemented properly on the search page. I &#039;&#039;&#039;am 100% on the same page&#039;&#039;&#039; that we should aim for readability and user friendliness here. But that&#039;s exactly why I don&#039;t think this template hits the mark on that front.&lt;br /&gt;
:&amp;lt;blockquote&amp;gt;Someone should not have to read source code files to understand module &#039;&#039;&#039;package options&#039;&#039;&#039; and descriptions.&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
:That&#039;s exactly the thing: the search functionality doesn&#039;t expose package options at all. The only way an user can learn about them is by reading the source code. Is that ideal? Of course not, but it is currently what it is. &lt;br /&gt;
:As for the description part, I would say in 99% of the time when this template is used, it&#039;s used either in the corresponding package&#039;s article, or in a context where adding the package description is trivial.&lt;br /&gt;
:For the second point, I think we should definitely be improving the main page itself to point the user to the search functionality as an option, as well as improving [[NixOS search]]. And on top of that, we probably want a [[First steps using NixOS]] page or similar to really drive this point home.&lt;br /&gt;
:For the third point, I don&#039;t think a package&#039;s current usage is an argument for or against its deletion (other than on technicality: we&#039;d of course want to modify all pages using this template to point to the new one). However, do note, it&#039;s only used in [[Special:WhatLinksHere/Template:Nixos:package|24 pages]], hardly an edit burden. [[User:DoggoBit|DoggoBit]] ([[User talk:DoggoBit|talk]]) 17:10, 8 June 2025 (UTC)&lt;br /&gt;
::When I was writing my reply I kept mistakenly was thinking of the {{:nixos:option}} template which is much more of a useful and popular template. My mistake. &lt;br /&gt;
::You are right that currently linking to a package on search.nixos.org does not provide as much information as it should. (It&#039;s more on the package maintainers to provide useful descriptions (like the {{nixos:package|docker}} maintainers do) than it is of a missing feature from search.nixos.org.&lt;br /&gt;
::I still hold my position that linking to {{nixos:package|ghc}} is a way better user experience than linking to {{Nixpkgs Link|pkgs/development/compilers/ghc/common-hadrian.nix}} both in terms of a maintainer and as an end user.&lt;br /&gt;
::To me, linking to source code is a bad option when there is a friendly interface that displays all the relevant information such as &#039;&#039;&#039;programs provided&#039;&#039;&#039;, &#039;&#039;&#039;current version&#039;&#039;&#039;, &#039;&#039;&#039;outputs&#039;&#039;&#039;, and if a user wants to, there is a link to the source code on the search result. How fast can you find that information on the Nixpkgs link? The version isn&#039;t even mentioned in the source code of the main file for GHC. [[User:Pigs|Pigs]] ([[User talk:Pigs|talk]]) 21:31, 8 June 2025 (UTC)&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=Talk:Docker&amp;diff=22653</id>
		<title>Talk:Docker</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=Talk:Docker&amp;diff=22653"/>
		<updated>2025-06-08T21:04:59Z</updated>

		<summary type="html">&lt;p&gt;Pigs: /* Rootless linger */ Reply&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Rootless linger ==&lt;br /&gt;
&lt;br /&gt;
I was new to using Docker rootless, and wasn&#039;t aware that systemd stops user services at logout. Docker itself doesn&#039;t provide any obvious logs that this is what stopped the container, and automatic restarts were allowed to trigger, leading to very unintuitive hard-to-debug problems, starting at random times when my login shell automatically exited. Some mention of  `users.users.&amp;lt;name&amp;gt;.linger` similar to docker docs `sudo loginctl enable-linger $(whoami)` command would help those new to rootless docker tremendously. Also hi! First post on the wiki. [[User:CallumMcMahon|CallumMcMahon]] ([[User talk:CallumMcMahon|talk]]) 20:40, 8 June 2025 (UTC)&lt;br /&gt;
&lt;br /&gt;
:That is a very useful note to make, thanks! Updated the page. [[User:Pigs|Pigs]] ([[User talk:Pigs|talk]]) 21:04, 8 June 2025 (UTC)&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=Docker&amp;diff=22652</id>
		<title>Docker</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=Docker&amp;diff=22652"/>
		<updated>2025-06-08T21:03:53Z</updated>

		<summary type="html">&lt;p&gt;Pigs: Ad note about rootless linger&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;languages/&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:1--&amp;gt;&lt;br /&gt;
[https://www.docker.com/ Docker] is a platform for building, packaging, and distributing applications inside containers. Containers bundle an application&#039;s code, configurations, and dependencies into a single object that runs consistently across different computing environments. Docker works well with NixOS through the virtualization module.&amp;lt;ref&amp;gt;https://www.docker.com/resources/what-container/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
== Installation == &amp;lt;!--T:2--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== Shell ==== &amp;lt;!--T:3--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:4--&amp;gt;&lt;br /&gt;
To temporarily use Docker in a shell environment, you can run:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nix-shell -p docker&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:5--&amp;gt;&lt;br /&gt;
This will provide a shell with Docker CLI available, but note that the Docker daemon will not be running. For full functionality, you&#039;ll need a system-level installation.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== System setup ==== &amp;lt;!--T:6--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:7--&amp;gt;&lt;br /&gt;
To install Docker on NixOS, add the virtualization.docker module to your system configuration at &amp;lt;code&amp;gt;/etc/nixos/configuration.nix&amp;lt;/code&amp;gt;:&amp;lt;ref&amp;gt;https://nixos.org/manual/nixos/stable/options#opt-virtualisation.docker.enable&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
# In /etc/nixos/configuration.nix&lt;br /&gt;
virtualisation.docker = {&lt;br /&gt;
  enable = true;&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
# Optional: Add your user to the &amp;quot;docker&amp;quot; group to run docker without sudo&lt;br /&gt;
users.users.&amp;lt;username&amp;gt;.extraGroups = [ &amp;quot;docker&amp;quot; ];&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
{{Security Warning|Beware that the docker group membership is effectively [https://github.com/moby/moby/issues/9976 equivalent to being root]! &amp;lt;br&amp;gt; Consider using [[#Rootless Docker|rootless mode]].}}&lt;br /&gt;
&lt;br /&gt;
{{evaluate}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:8--&amp;gt;&lt;br /&gt;
For a comprehensive list of configuration options, refer to the {{nixos:option|virtualisation.docker}} module options.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
== Configuration == &amp;lt;!--T:9--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== Basic ==== &amp;lt;!--T:10--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:11--&amp;gt;&lt;br /&gt;
The basic Docker configuration on NixOS includes several options you can set in your &amp;lt;code&amp;gt;configuration.nix&amp;lt;/code&amp;gt; file:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
virtualisation.docker = {&lt;br /&gt;
  enable = true;&lt;br /&gt;
  # Set up resource limits&lt;br /&gt;
  daemon.settings = {&lt;br /&gt;
    experimental = true;&lt;br /&gt;
    default-address-pools = [&lt;br /&gt;
      {&lt;br /&gt;
        base = &amp;quot;172.30.0.0/16&amp;quot;;&lt;br /&gt;
        size = 24;&lt;br /&gt;
      }&lt;br /&gt;
    ];&lt;br /&gt;
  };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== Advanced ==== &amp;lt;!--T:12--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:13--&amp;gt;&lt;br /&gt;
For more advanced configuration, you can customize Docker daemon options and networking:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
virtualisation.docker = {&lt;br /&gt;
  enable = true;&lt;br /&gt;
  # Customize Docker daemon settings using the daemon.settings option&lt;br /&gt;
  daemon.settings = {&lt;br /&gt;
    dns = [ &amp;quot;1.1.1.1&amp;quot; &amp;quot;8.8.8.8&amp;quot; ];&lt;br /&gt;
    log-driver = &amp;quot;journald&amp;quot;;&lt;br /&gt;
    registry-mirrors = [ &amp;quot;https://mirror.gcr.io&amp;quot; ];&lt;br /&gt;
    storage-driver = &amp;quot;overlay2&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
  # Use the rootless mode - run Docker daemon as non-root user&lt;br /&gt;
  rootless = {&lt;br /&gt;
    enable = true;&lt;br /&gt;
    setSocketVariable = true;&lt;br /&gt;
  };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
== Docker Compose == &amp;lt;!--T:14--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:15--&amp;gt;&lt;br /&gt;
Currently, there are two options to use Docker Compose with NixOS: Arion or Compose2Nix.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:16--&amp;gt;&lt;br /&gt;
With Arion, you can specify most Docker Compose options in Nix Syntax, and Arion will generate a &amp;lt;code&amp;gt;docker-compose.yml&amp;lt;/code&amp;gt; file internally. The result is a systemd service that starts and stops the container.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:17--&amp;gt;&lt;br /&gt;
Compose2Nix, generates all necessary configs directly from the &amp;lt;code&amp;gt;docker-compose.yml&amp;lt;/code&amp;gt;, which is easier when using an already existing Docker Compose project. The result is similar to that from Arion: a systemd service is created that handles starting and stopping the container.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Arion === &amp;lt;!--T:18--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:19--&amp;gt;&lt;br /&gt;
[https://docs.hercules-ci.com/arion/ Arion] is created for running Nix-based projects in Docker Compose. It uses the NixOS module system for configuration, it can bypass &amp;lt;code&amp;gt;docker build&amp;lt;/code&amp;gt; and lets you use dockerTools or use the store directly in the containers. The images/containers can be typical dockerTools style images or full NixOS configs.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:20--&amp;gt;&lt;br /&gt;
To use Arion, you first need to add its module to your NixOS configuration:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
modules = [ arion.nixosModules.arion ];&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:21--&amp;gt;&lt;br /&gt;
After that, you can access its options under&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
virtualisation.arion = {}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:22--&amp;gt;&lt;br /&gt;
A config for a simple container could look like this:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
virtualisation.arion = {&lt;br /&gt;
  backend = &amp;quot;docker&amp;quot;;&lt;br /&gt;
  projects = {&lt;br /&gt;
    &amp;quot;db&amp;quot;.settings.services.&amp;quot;db&amp;quot;.service = {&lt;br /&gt;
      image = &amp;quot;&amp;quot;;&lt;br /&gt;
      restart = &amp;quot;unless-stopped&amp;quot;;&lt;br /&gt;
      environment = { POSTGRESS_PASSWORD = &amp;quot;password&amp;quot;; };&lt;br /&gt;
    };&lt;br /&gt;
  };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Compose2Nix === &amp;lt;!--T:23--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:24--&amp;gt;&lt;br /&gt;
With [https://github.com/aksiksi/compose2nix compose2nix] you can generate [https://search.nixos.org/options?query=virtualisation.oci-containers oci-containers] config from a &amp;lt;code&amp;gt;docker-compose.yaml&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== Install ==== &amp;lt;!--T:25--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:26--&amp;gt;&lt;br /&gt;
To use &amp;lt;code&amp;gt;compose2nix&amp;lt;/code&amp;gt; with &amp;lt;code&amp;gt;nix-shell&amp;lt;/code&amp;gt; you can use&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nix shell github:aksiksi/compose2nix&lt;br /&gt;
compose2nix -h&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:27--&amp;gt;&lt;br /&gt;
To install &amp;lt;code&amp;gt;compose2nix&amp;lt;/code&amp;gt; to NixOS, add the repo to your flake inputs&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
compose2nix = {&lt;br /&gt;
  url = &amp;quot;github:aksiksi/compose2nix&amp;quot;;&lt;br /&gt;
  inputs.nixpkgs.follows = &amp;quot;nixpkgs&amp;quot;;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:28--&amp;gt;&lt;br /&gt;
and add the package to your configuration&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
environment.systemPackages = [&lt;br /&gt;
  inputs.compose2nix.packages.x86_64-linux.default&lt;br /&gt;
];&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== Usage ==== &amp;lt;!--T:29--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:30--&amp;gt;&lt;br /&gt;
After you have installed &amp;lt;code&amp;gt;compose2nix&amp;lt;/code&amp;gt;, you can run &amp;lt;code&amp;gt;compose2nix&amp;lt;/code&amp;gt; in the directory with your &amp;lt;code&amp;gt;docker-compose.yml&amp;lt;/code&amp;gt;, which will output a &amp;lt;code&amp;gt;docker-compose.nix&amp;lt;/code&amp;gt;.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:31--&amp;gt;&lt;br /&gt;
Alternatively, you can specify the input and output files with the following flags&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
compose2nix -inputs input.yml -output output.nix -runtime docker&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:32--&amp;gt;&lt;br /&gt;
The &amp;lt;code&amp;gt;-runtime&amp;lt;/code&amp;gt; flag specifies the runtime. Here, we select &amp;lt;code&amp;gt;docker&amp;lt;/code&amp;gt;. Options are &amp;lt;code&amp;gt;podman&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;docker&amp;lt;/code&amp;gt;. The default is &amp;lt;code&amp;gt;podman&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
== Tips and tricks == &amp;lt;!--T:33--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Docker on btrfs === &amp;lt;!--T:34--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:35--&amp;gt;&lt;br /&gt;
If you use the [[btrfs]] file system, you might need to set the {{nixos:option|virtualisation.docker.storageDriver|storageDriver}} option:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
virtualisation.docker.storageDriver = &amp;quot;btrfs&amp;quot;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Rootless Docker === &amp;lt;!--T:36--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:37--&amp;gt;&lt;br /&gt;
[https://docs.docker.com/engine/security/rootless/ Rootless Docker] lets you run the Docker daemon as a non-root user for improved security. To do so, enable {{nixos:option|virtualisation.docker.rootless}}. This activates the user-level systemd Docker service. Additionally, the option {{nixos:option|virtualisation.docker.rootless.setSocketVariable|setSocketVariable}} configures the &amp;lt;code&amp;gt;DOCKER_HOST&amp;lt;/code&amp;gt; environment variable to point to the rootless Docker instance. &lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
virtualisation.docker = {&lt;br /&gt;
  # Consider disabling the system wide Docker daemon&lt;br /&gt;
  enable = false;&lt;br /&gt;
&lt;br /&gt;
  rootless = {&lt;br /&gt;
    enable = true;&lt;br /&gt;
    setSocketVariable = true;&lt;br /&gt;
    # Optionally customize rootless Docker daemon settings&lt;br /&gt;
    daemon.settings = {&lt;br /&gt;
      dns = [ &amp;quot;1.1.1.1&amp;quot; &amp;quot;8.8.8.8&amp;quot; ];&lt;br /&gt;
      registry-mirrors = [ &amp;quot;https://mirror.gcr.io&amp;quot; ];&lt;br /&gt;
    };&lt;br /&gt;
  };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:39--&amp;gt;&lt;br /&gt;
A system reboot is required for these changes to take effect. Alternatively, the environment variable can be set manually in the current shell session, and the user Docker service can be started with the following commands:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
$ export DOCKER_HOST=unix://$XDG_RUNTIME_DIR/docker.sock&lt;br /&gt;
$ systemctl --user start docker&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{note|User services do not persist after logging out by default. This will cause any Docker containers to stop if a user logs out. Set option {{nixos:option|users.users.*.linger|users.users.&amp;lt;name&amp;gt;.linger}} to true for Docker containers to persist. See [[Systemd/User Services#Keeping user services running after logout]] for more details.}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:40--&amp;gt;&lt;br /&gt;
To verify the status of the rootless Docker service: &lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
$ systemctl --user status docker&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To confirm that Docker is running in rootless mode:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
$ docker info -f &amp;quot;{{println .SecurityOptions}}&amp;quot; | grep rootless &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Using Privileged Ports for Rootless Docker ===&lt;br /&gt;
Rootless containers are not able to ports from 0 to 1023 as such port can only be used by privileged users.  This problem can be solved by using port forwarding.&lt;br /&gt;
&lt;br /&gt;
Assume you&#039;d like a rootless container to make use of ports 53 (DNS; TPC and UDP) and 80 (web; TCP).  We may force the container to use port 8000 while the firewall is instructed for forward traffic from port 80 to 8000.  Same logic applies for port 53.  Refer to the following example:&amp;lt;syntaxhighlight lang=&amp;quot;nixos&amp;quot;&amp;gt;# Firewall&lt;br /&gt;
networking.firewall = {&lt;br /&gt;
  enable = true;&lt;br /&gt;
  allowedTCPPorts = [ 80 8000 53 5300 ];	&lt;br /&gt;
  allowedUDPPorts = [ 53 5300 ];&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
boot.kernel.sysctl = {&lt;br /&gt;
  &amp;quot;net.ipv4.conf.eth0.forwarding&amp;quot; = 1;    # enable port forwarding&lt;br /&gt;
};&lt;br /&gt;
    &lt;br /&gt;
networking = {&lt;br /&gt;
  firewall.extraCommands = &#039;&#039;&lt;br /&gt;
    iptables -A PREROUTING -t nat -i eth0 -p TCP --dport 80 -j REDIRECT --to-port 8000&lt;br /&gt;
    iptables -A PREROUTING -t nat -i eth0 -p TCP --dport 53 -j REDIRECT --to-port 5300&lt;br /&gt;
    iptables -A PREROUTING -t nat -i eth0 -p UDP --dport 53 -j REDIRECT --to-port 5300&lt;br /&gt;
  &#039;&#039;;&lt;br /&gt;
};&amp;lt;/syntaxhighlight&amp;gt;Whilst the docker-compose.yaml might look like this:&amp;lt;syntaxhighlight lang=&amp;quot;dockerfile&amp;quot;&amp;gt;&lt;br /&gt;
services:&lt;br /&gt;
  myserver:&lt;br /&gt;
    image: ...&lt;br /&gt;
    restart: always&lt;br /&gt;
    ports:&lt;br /&gt;
      - &amp;quot;5300:53/tcp&amp;quot;&lt;br /&gt;
      - &amp;quot;5300:53/udp&amp;quot;&lt;br /&gt;
      - &amp;quot;8000:80&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Creating images with Nix === &amp;lt;!--T:41--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== Building a docker image with nixpkgs ==== &amp;lt;!--T:42--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:43--&amp;gt;&lt;br /&gt;
There is an entry for [https://nixos.org/nixpkgs/manual/#sec-pkgs-dockerTools dockerTools] in the Nixpkgs manual for reference. In the linked page, they give the following example config:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
buildImage {&lt;br /&gt;
  name = &amp;quot;redis&amp;quot;;&lt;br /&gt;
  tag = &amp;quot;latest&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
  fromImage = someBaseImage;&lt;br /&gt;
  fromImageName = null;&lt;br /&gt;
  fromImageTag = &amp;quot;latest&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
  copyToRoot = pkgs.buildEnv {&lt;br /&gt;
    name = &amp;quot;image-root&amp;quot;;&lt;br /&gt;
    paths = [ pkgs.redis ];&lt;br /&gt;
    pathsToLink = [ &amp;quot;/bin&amp;quot; ];&lt;br /&gt;
  };&lt;br /&gt;
&lt;br /&gt;
  runAsRoot = &#039;&#039;&lt;br /&gt;
    #!${pkgs.runtimeShell}&lt;br /&gt;
    mkdir -p /data&lt;br /&gt;
  &#039;&#039;;&lt;br /&gt;
&lt;br /&gt;
  config = {&lt;br /&gt;
    Cmd = [ &amp;quot;/bin/redis-server&amp;quot; ];&lt;br /&gt;
    WorkingDir = &amp;quot;/data&amp;quot;;&lt;br /&gt;
    Volumes = { &amp;quot;/data&amp;quot; = { }; };&lt;br /&gt;
  };&lt;br /&gt;
&lt;br /&gt;
  diskSize = 1024;&lt;br /&gt;
  buildVMMemorySize = 512;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:44--&amp;gt;&lt;br /&gt;
More examples can be found in the [https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/docker/examples.nix nixpkgs] repo.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:45--&amp;gt;&lt;br /&gt;
Also check out the excellent article by [https://lucabrunox.github.io/2016/04/cheap-docker-images-with-nix_15.html lethalman] about building minimal docker images with nix.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== Reproducible image dates ==== &amp;lt;!--T:46--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:47--&amp;gt;&lt;br /&gt;
The manual advises against using &amp;lt;code&amp;gt;created = &amp;quot;now&amp;quot;&amp;lt;/code&amp;gt;, as that prevents images from being reproducible.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:48--&amp;gt;&lt;br /&gt;
An alternative, if using [[flakes]], is to do &amp;lt;code&amp;gt;created = builtins.substring 0 8 self.lastModifiedDate&amp;lt;/code&amp;gt;, which uses the commit date, and is therefore reproducible.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== Calculating the sha256 for a pulled Docker image ==== &amp;lt;!--T:49--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:50--&amp;gt;&lt;br /&gt;
The &amp;lt;code&amp;gt;sha256&amp;lt;/code&amp;gt; argument of the &amp;lt;code&amp;gt;dockerTools.pullImage&amp;lt;/code&amp;gt; function is the checksum of the archive generated by Skopeo. Since the archive contains the name and the tag of the image, Skopeo arguments used to fetch the image have to be identical to those used by the &amp;lt;code&amp;gt;dockerTools.pullImage&amp;lt;/code&amp;gt; function.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:51--&amp;gt;&lt;br /&gt;
For instance, the SHA of the following image&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
pkgs.dockerTools.pullImage{&lt;br /&gt;
  imageName = &amp;quot;lnl7/nix&amp;quot;;&lt;br /&gt;
  finalImageTag = &amp;quot;2.0&amp;quot;;&lt;br /&gt;
  imageDigest = &amp;quot;sha256:632268d5fd9ca87169c65353db99be8b4e2eb41833b626e09688f484222e860f&amp;quot;;&lt;br /&gt;
  sha256 = &amp;quot;1x00ks05cz89k3wc460i03iyyjr7wlr28krk7znavfy2qx5a0hfd&amp;quot;;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:52--&amp;gt;&lt;br /&gt;
can be manually generated with the following shell commands&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
skopeo copy docker://lnl7/nix@sha256:632268d5fd9ca87169c65353db99be8b4e2eb41833b626e09688f484222e860f docker-archive:///tmp/image.tgz:lnl7/nix:2.0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nix-hash --base32 --flat --type sha256 /tmp/image.tgz &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
1x00ks05cz89k3wc460i03iyyjr7wlr28krk7znavfy2qx5a0hfd&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== Directly Using Nix in Image Layers ==== &amp;lt;!--T:53--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:54--&amp;gt;&lt;br /&gt;
Instead of copying Nix packages into Docker image layers, Docker can be configured to directly utilize the &amp;lt;code&amp;gt;nix-store&amp;lt;/code&amp;gt; by integrating with [https://github.com/pdtpartners/nix-snapshotter nix-snapshotter].&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:55--&amp;gt;&lt;br /&gt;
This will significantly reduce data duplication and the time it takes to pull images.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Using Podman as an alternative === &amp;lt;!--T:56--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:57--&amp;gt;&lt;br /&gt;
Podman is a daemonless container engine that can run Docker containers without elevated privileges. It can be used as a drop-in replacement for Docker in many cases:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
# Enable Podman in configuration.nix&lt;br /&gt;
virtualisation.podman = {&lt;br /&gt;
  enable = true;&lt;br /&gt;
  # Create the default bridge network for podman&lt;br /&gt;
  defaultNetwork.settings.dns_enabled = true;&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
# Optionally, create a Docker compatibility alias&lt;br /&gt;
programs.zsh.shellAliases = {&lt;br /&gt;
  docker = &amp;quot;podman&amp;quot;;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Changing Docker Daemon&#039;s Data Root === &amp;lt;!--T:58--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:59--&amp;gt;&lt;br /&gt;
By default, the Docker daemon stores images, containers, and build context on the root file system. To use a different storage location, specify a new &amp;lt;code&amp;gt;data-root&amp;lt;/code&amp;gt; in your configuration:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
virtualisation.docker.daemon.settings = {&lt;br /&gt;
  data-root = &amp;quot;/some-place/to-store-the-docker-data&amp;quot;;&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Docker Containers as systemd Services === &amp;lt;!--T:60--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:61--&amp;gt;&lt;br /&gt;
You can run Docker containers as systemd services using the &amp;lt;code&amp;gt;oci-containers&amp;lt;/code&amp;gt; module:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
virtualisation.oci-containers = {&lt;br /&gt;
  # backend defaults to &amp;quot;podman&amp;quot;&lt;br /&gt;
  backend = &amp;quot;docker&amp;quot;;&lt;br /&gt;
  containers = {&lt;br /&gt;
    foo = {&lt;br /&gt;
      # ...&lt;br /&gt;
    };&lt;br /&gt;
  };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:62--&amp;gt;&lt;br /&gt;
A more advanced example:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
{ config, pkgs, ... }:&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  config.virtualisation.oci-containers.containers = {&lt;br /&gt;
    hackagecompare = {&lt;br /&gt;
      image = &amp;quot;chrissound/hackagecomparestats-webserver:latest&amp;quot;;&lt;br /&gt;
      ports = [&amp;quot;127.0.0.1:3010:3010&amp;quot;];&lt;br /&gt;
      volumes = [&lt;br /&gt;
        &amp;quot;/root/hackagecompare/packageStatistics.json:/root/hackagecompare/packageStatistics.json&amp;quot;&lt;br /&gt;
      ];&lt;br /&gt;
      cmd = [&lt;br /&gt;
        &amp;quot;--base-url&amp;quot;&lt;br /&gt;
        &amp;quot;\&amp;quot;/hackagecompare\&amp;quot;&amp;quot;&lt;br /&gt;
      ];&lt;br /&gt;
    };&lt;br /&gt;
  };&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:63--&amp;gt;&lt;br /&gt;
See [https://search.nixos.org/options?from=0&amp;amp;size=50&amp;amp;sort=alpha_asc&amp;amp;query=virtualisation.oci-containers oci-containers] for further options.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
==== Usage ==== &amp;lt;!--T:64--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:65--&amp;gt;&lt;br /&gt;
Unless otherwise specified, NixOS uses Podman to run OCI containers. Note that these are &#039;&#039;&#039;user-specific&#039;&#039;&#039;, so running commands with or without sudo can change your output.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:66--&amp;gt;&lt;br /&gt;
List containers&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
# podman ps&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:67--&amp;gt;&lt;br /&gt;
Update image&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
# podman restart hackagecompare&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:68--&amp;gt;&lt;br /&gt;
List images&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
# podman ls&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:69--&amp;gt;&lt;br /&gt;
Remove container&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
# podman rm hackagecompare&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:70--&amp;gt;&lt;br /&gt;
Remove image&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
# podman rmi c0d9a5f58afe&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:71--&amp;gt;&lt;br /&gt;
Update image&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
# podman pull chrissound/hackagecomparestats-webserver:latest&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:72--&amp;gt;&lt;br /&gt;
Run interactive shell in running container&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
# podman exec -ti $ContainerId /bin/sh&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
===== Exposing ports from the host ===== &amp;lt;!--T:73--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:74--&amp;gt;&lt;br /&gt;
If you have a service running on the host that you want to connect to from the container, you could try connecting to the hostname &amp;lt;code&amp;gt;host.containers.internal&amp;lt;/code&amp;gt; (or &amp;lt;code&amp;gt;host.docker.internal&amp;lt;/code&amp;gt; for podman), but this might require additional networking setup&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
===== Exposing sockets from the host ===== &amp;lt;!--T:75--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:76--&amp;gt;&lt;br /&gt;
If you have a service running on the host that exposes a socket, such as mariadb, you can also expose that socket to the container instead. You&#039;ll want to expose the folder the socket is in as a volume - so:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
      volumes = [&lt;br /&gt;
        &amp;quot;/var/run/mysqld:/mysqld&amp;quot;&lt;br /&gt;
      ];&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:77--&amp;gt;&lt;br /&gt;
to provide access to &amp;lt;code&amp;gt;/var/run/mysqld/mysqld.sock&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Running the docker daemon from nix-the-package-manager - not NixOS === &amp;lt;!--T:78--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:79--&amp;gt;&lt;br /&gt;
This is not supported. You&#039;re better off installing the docker daemon [https://docs.docker.com/engine/install/ &amp;quot;the normal non-nix way&amp;quot;].&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:80--&amp;gt;&lt;br /&gt;
See the discourse discussion: [https://discourse.nixos.org/t/how-to-run-docker-daemon-from-nix-not-nixos/43413 How to run docker daemon from nix (not NixOS)] for more.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
== Troubleshooting == &amp;lt;!--T:81--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Cannot connect to the Docker daemon === &amp;lt;!--T:83--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:84--&amp;gt;&lt;br /&gt;
If you encounter errors connecting to the Docker daemon, check that:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:85--&amp;gt;&lt;br /&gt;
- The Docker service is running: &amp;lt;code&amp;gt;systemctl status docker&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:86--&amp;gt;&lt;br /&gt;
- Your user is in the docker [[User management#Adding User to a group|group]]: &amp;lt;code&amp;gt;groups | grep docker&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:87--&amp;gt;&lt;br /&gt;
- You&#039;ve logged out and back in after adding your user to the docker group&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Storage space issues === &amp;lt;!--T:88--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:89--&amp;gt;&lt;br /&gt;
When Docker uses too much disk space:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Remove unused containers, networks, images, and volumes&lt;br /&gt;
docker system prune -a --volumes&lt;br /&gt;
&lt;br /&gt;
# Configure Docker daemon to automatically prune in configuration.nix&lt;br /&gt;
virtualisation.docker.daemon.settings = {&lt;br /&gt;
  pruning = {&lt;br /&gt;
    enabled = true;&lt;br /&gt;
    interval = &amp;quot;24h&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Network conflicts === &amp;lt;!--T:90--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:91--&amp;gt;&lt;br /&gt;
Docker&#039;s default subnet (`172.17.0.0/16`) might conflict with your existing network. Configure a different subnet in your `configuration.nix`:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
virtualisation.docker.daemon.settings = {&lt;br /&gt;
  default-address-pools = [&lt;br /&gt;
    {&lt;br /&gt;
      base = &amp;quot;192.168.0.0/16&amp;quot;;&lt;br /&gt;
      size = 24;&lt;br /&gt;
    }&lt;br /&gt;
  ];&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
=== Cannot connect to public Wi-Fi, when using Docker === &amp;lt;!--T:92--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:93--&amp;gt;&lt;br /&gt;
When connecting to a public Wi-Fi, where the login page&#039;s IP-Address is within the Docker network range, accessing the Internet might not be possible. This has been reported when trying to connect to the WIFIonICE of the Deutsche Bahn (DB). They use the &amp;lt;code&amp;gt;172.18.x.x&amp;lt;/code&amp;gt; address range.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:94--&amp;gt;&lt;br /&gt;
This can be resolved by changing the default address pool that Docker uses.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
virtualisation.docker = {&lt;br /&gt;
  enable = true;&lt;br /&gt;
  daemon.settings = {&lt;br /&gt;
    &amp;quot;default-address-pools&amp;quot; = [&lt;br /&gt;
      { &amp;quot;base&amp;quot; = &amp;quot;172.27.0.0/16&amp;quot;; &amp;quot;size&amp;quot; = 24; }&lt;br /&gt;
    ];&lt;br /&gt;
  };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:95--&amp;gt;&lt;br /&gt;
Restarting the container or Docker might be required.&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References == &amp;lt;!--T:96--&amp;gt;&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Applications]]&lt;br /&gt;
[[Category:Virtualization]]&lt;br /&gt;
[[Category:Cookbook]]&lt;br /&gt;
[[Category:Software]]&lt;br /&gt;
[[Category:Server]]&lt;br /&gt;
[[Category:Container]]&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=Flakes&amp;diff=22608</id>
		<title>Flakes</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=Flakes&amp;diff=22608"/>
		<updated>2025-06-08T17:59:44Z</updated>

		<summary type="html">&lt;p&gt;Pigs: /* NixOS configuration with flakes */ move nixos section to new page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;languages /&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:1--&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Nix flakes&#039;&#039;&#039; is an [https://nixos.org/manual/nix/stable/development/experimental-features.html experimental feature] that was introduced with Nix 2.4 ([https://nixos.org/manual/nix/unstable/release-notes/rl-2.4.html see release notes]).&lt;br /&gt;
&lt;br /&gt;
====Introduction==== &amp;lt;!--T:2--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:3--&amp;gt;&lt;br /&gt;
Nix flakes enforce a uniform structure for [[Nix]] projects, pin versions of their dependencies in a lock file, and make it more convenient to write reproducible Nix expressions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:4--&amp;gt;&lt;br /&gt;
* A [https://nixos.org/manual/nix/unstable/command-ref/new-cli/nix3-flake.html#description flake] refers to a file-system tree whose root directory contains the Nix file specification called &amp;lt;code&amp;gt;flake.nix&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:141--&amp;gt;&lt;br /&gt;
* The contents of &amp;lt;code&amp;gt;flake.nix&amp;lt;/code&amp;gt; file follow a uniform naming schema for declaring packages and their dependencies in the Nix language.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:142--&amp;gt;&lt;br /&gt;
*  Flakes introduce a [https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake.html#flake-references URL-like syntax] for specifying remote sources.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:143--&amp;gt;&lt;br /&gt;
* To simplify the long URL syntax with shorter names, [https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-registry.html flakes uses a registry] of symbolic identifiers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:144--&amp;gt;&lt;br /&gt;
* Flakes also allow for locking references and versions that can then be queried and updated programmatically.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:145--&amp;gt;&lt;br /&gt;
* 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.&lt;br /&gt;
&lt;br /&gt;
=== Enabling flakes ===&lt;br /&gt;
&lt;br /&gt;
====Enable flakes temporarily==== &amp;lt;!--T:5--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:6--&amp;gt;&lt;br /&gt;
When using any [[Nix command|&amp;lt;code&amp;gt;nix&amp;lt;/code&amp;gt; command]], add the following command-line options:&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;&lt;br /&gt;
 --experimental-features &#039;nix-command flakes&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Enable flakes permanently in NixOS==== &amp;lt;!--T:7--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:8--&amp;gt;&lt;br /&gt;
Add the following to the [[Overview_of_the_NixOS_Linux_distribution#Declarative_Configuration system configuration |NixOS configuration]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxHighlight lang=nix&amp;gt;&lt;br /&gt;
  nix.settings.experimental-features = [ &amp;quot;nix-command&amp;quot; &amp;quot;flakes&amp;quot; ];&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====With Home Manager==== &amp;lt;!--T:10--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:11--&amp;gt;&lt;br /&gt;
Add the following to your [[Home Manager|home manager]] config:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
  nix.settings.experimental-features = [ &amp;quot;nix-command&amp;quot; &amp;quot;flakes&amp;quot; ];&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Other Distros, without Home Manager==== &amp;lt;!--T:13--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:14--&amp;gt;&lt;br /&gt;
{{Note | The  [https://github.com/DeterminateSystems/nix-installer Determinate Nix Installer] enables flakes by default.}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:15--&amp;gt;&lt;br /&gt;
Add the following to &amp;lt;code&amp;gt;~/.config/nix/nix.conf&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;/etc/nix/nix.conf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxHighlight lang=text&amp;gt;&lt;br /&gt;
experimental-features = nix-command flakes&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Basic Usage of Flake=== &amp;lt;!--T:17--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:20--&amp;gt;&lt;br /&gt;
{{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]].}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:146--&amp;gt;&lt;br /&gt;
{{Note | For flakes in [[git]] repositories, only files in the working tree will be copied to the store.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:22--&amp;gt;&lt;br /&gt;
Therefore, if you use &amp;lt;code&amp;gt;git&amp;lt;/code&amp;gt; for your flake, ensure to &amp;lt;code&amp;gt;git add&amp;lt;/code&amp;gt; any project files after you first create them.}}&lt;br /&gt;
&lt;br /&gt;
====Generate flake.nix file==== &amp;lt;!--T:24--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:25--&amp;gt;&lt;br /&gt;
To initialize a flake, run the following flake command in the project directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
$ nix flake init&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Common structure====&lt;br /&gt;
&lt;br /&gt;
The above command will provide a very simple flake file looking like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxHighlight lang=nix&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  description = &amp;quot;A very basic flake&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
  inputs = {&lt;br /&gt;
    nixpkgs.url = &amp;quot;github:nixos/nixpkgs?ref=nixos-unstable&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
&lt;br /&gt;
  outputs = { self, nixpkgs }: {&lt;br /&gt;
&lt;br /&gt;
    packages.x86_64-linux.hello = nixpkgs.legacyPackages.x86_64-linux.hello;&lt;br /&gt;
&lt;br /&gt;
    packages.x86_64-linux.default = self.packages.x86_64-linux.hello;&lt;br /&gt;
&lt;br /&gt;
  };&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will then be able to build this flake with &amp;lt;code&amp;gt;nix build&amp;lt;/code&amp;gt; and run it with &amp;lt;code&amp;gt;nix run&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{note|Flakes force you to specify a program for each supported architecture. To avoid this, refer to [[#Defining a flake for multiple architectures]] section of the wiki.}}&lt;br /&gt;
&lt;br /&gt;
==== The nix flakes command ==== &amp;lt;!--T:64--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:65--&amp;gt;&lt;br /&gt;
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}}.&lt;br /&gt;
&lt;br /&gt;
This flake produces a single flake output &amp;lt;code&amp;gt;packages&amp;lt;/code&amp;gt;. And within that, &amp;lt;code&amp;gt;x86_64-linux&amp;lt;/code&amp;gt; is a system-specifc attribute set. And within that, two package [[derivations]] &amp;lt;code&amp;gt;default&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;hello&amp;lt;/code&amp;gt;. 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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
$ nix flake show&lt;br /&gt;
└───packages&lt;br /&gt;
    └───x86_64-linux&lt;br /&gt;
        ├───default: package &#039;hello-2.12.2&#039;&lt;br /&gt;
        └───hello: package &#039;hello-2.12.2&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Development shells ====&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;code&amp;gt;devShell&amp;lt;/code&amp;gt; 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 &amp;lt;code&amp;gt;nix-shell&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  description = &amp;quot;Example flake with a devShell&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
  inputs.nixpkgs.url = &amp;quot;github:nixos/nixpkgs?ref=nixos-unstable&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
  outputs = { self, nixpkgs}:&lt;br /&gt;
    let&lt;br /&gt;
      system = &amp;quot;x86_64-linux&amp;quot;;&lt;br /&gt;
      pkgs = import nixpkgs { inherit system; };&lt;br /&gt;
    in {&lt;br /&gt;
      devShells.x86_64-linux.default = pkgs.mkShell {&lt;br /&gt;
        buildInputs = with pkgs; [&lt;br /&gt;
          hello&lt;br /&gt;
        ];&lt;br /&gt;
        shellHook = &#039;&#039;&lt;br /&gt;
          echo &amp;quot;Welcome to the devShell!&amp;quot;&lt;br /&gt;
        &#039;&#039;;&lt;br /&gt;
      };&lt;br /&gt;
    };&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To enter the development shell environment:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
$ nix develop&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{note|You don’t need to define a devShell to enter a development shell using nix develop.&lt;br /&gt;
If no devShell is defined, nix develop will drop you into an environment containing the default build dependencies of the flake (if any).}}&lt;br /&gt;
&lt;br /&gt;
==== Build specific attributes in a flake repository ==== &amp;lt;!--T:102--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:103--&amp;gt;&lt;br /&gt;
Running &amp;lt;code&amp;gt;nix build&amp;lt;/code&amp;gt; will look in the &amp;lt;code&amp;gt;legacyPackages&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;packages&amp;lt;/code&amp;gt; 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 &amp;lt;code&amp;gt;nix build .#&amp;lt;attr&amp;gt;&amp;lt;/code&amp;gt;. In the example above, if you wanted to build the &amp;lt;code&amp;gt;packages.x86_64-linux.hello&amp;lt;/code&amp;gt; attribute, run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxHighlight lang=console&amp;gt;&lt;br /&gt;
$ nix build .#hello&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Likewise, you can specify an attribute with the run command: &amp;lt;code&amp;gt;nix run .#hello&amp;lt;/code&amp;gt; and the develop command: &amp;lt;code&amp;gt;nix develop .#hello&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Flake schema == &amp;lt;!--T:27--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:28--&amp;gt;&lt;br /&gt;
The flake.nix file is a Nix file but that has special restrictions (more on that later).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:29--&amp;gt;&lt;br /&gt;
It has 4 top-level attributes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:30--&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;description&amp;lt;/code&amp;gt; is a string describing the flake.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:147--&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;inputs&amp;lt;/code&amp;gt; is an attribute set of all the dependencies of the flake. The schema is described below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:148--&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;outputs&amp;lt;/code&amp;gt; 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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:149--&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;nixConfig&amp;lt;/code&amp;gt; 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&#039;s nix experience by adding flake-specific configuration, such as a [[Binary Cache|binary cache]].&lt;br /&gt;
&lt;br /&gt;
=== Input schema === &amp;lt;!--T:31--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:32--&amp;gt;&lt;br /&gt;
[https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake.html#flake-inputs The nix flake inputs manual].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:150--&amp;gt;&lt;br /&gt;
[https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake.html#flake-references The nix flake references manual].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:33--&amp;gt;&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:34--&amp;gt;&lt;br /&gt;
[[Nixpkgs]] can be defined using the following code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;inputs.nixpkgs.url = &amp;quot;github:NixOS/nixpkgs/&amp;lt;branch name&amp;gt;&amp;quot;;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Nixpkgs can alternatively also point to an url cached by the NixOS organization:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;inputs.nixpkgs.url = &amp;quot;&amp;lt;nowiki&amp;gt;https://nixos.org/channels/nixpkgs-unstable/nixexprs.tar.xz&amp;lt;/nowiki&amp;gt;&amp;quot;;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example the input would point to the `nixpkgs-unstable` channel.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:36--&amp;gt;&lt;br /&gt;
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&#039;s on GitHub is unnecessary.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:37--&amp;gt;&lt;br /&gt;
For example, adding [[Hyprland]] as an input would look something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;inputs.hyprland.url = &amp;quot;github:hyprwm/Hyprland&amp;quot;;&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:39--&amp;gt;&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;inputs.hyprland.inputs.nixpkgs.follows = &amp;quot;nixpkgs&amp;quot;;&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:41--&amp;gt;&lt;br /&gt;
Using curly brackets({}), we can shorten all of this and put it in a table. The code will look something like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
inputs = {&lt;br /&gt;
  nixpkgs.url = &amp;quot;github:NixOS/nixpkgs/&amp;lt;branch name&amp;gt;&amp;quot;;&lt;br /&gt;
  hyprland = {&lt;br /&gt;
    url = &amp;quot;github:hyprwm/Hyprland&amp;quot;;&lt;br /&gt;
    inputs.nixpkgs.follows = &amp;quot;nixpkgs&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, Git submodules in package &amp;lt;code&amp;gt;src&amp;lt;/code&amp;gt;&#039;s won&#039;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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
  inputs.self.submodules = true;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Output schema === &amp;lt;!--T:42--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:151--&amp;gt;&lt;br /&gt;
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].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:43--&amp;gt;&lt;br /&gt;
Once the inputs are resolved, they&#039;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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:44--&amp;gt;&lt;br /&gt;
Where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:45--&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;&amp;lt;system&amp;gt;&amp;lt;/code&amp;gt; is something like &amp;quot;x86_64-linux&amp;quot;, &amp;quot;aarch64-linux&amp;quot;, &amp;quot;i686-linux&amp;quot;, &amp;quot;x86_64-darwin&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:152--&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;&amp;lt;name&amp;gt;&amp;lt;/code&amp;gt; is an attribute name like &amp;quot;hello&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:153--&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;&amp;lt;flake&amp;gt;&amp;lt;/code&amp;gt; is a flake name like &amp;quot;nixpkgs&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:154--&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;&amp;lt;store-path&amp;gt;&amp;lt;/code&amp;gt; is a &amp;lt;code&amp;gt;/nix/store..&amp;lt;/code&amp;gt; path&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxHighlight lang=nix&amp;gt;&lt;br /&gt;
{ self, ... }@inputs:&lt;br /&gt;
{&lt;br /&gt;
  # Executed by `nix flake check`&lt;br /&gt;
  checks.&amp;quot;&amp;lt;system&amp;gt;&amp;quot;.&amp;quot;&amp;lt;name&amp;gt;&amp;quot; = derivation;&lt;br /&gt;
  # Executed by `nix build .#&amp;lt;name&amp;gt;`&lt;br /&gt;
  packages.&amp;quot;&amp;lt;system&amp;gt;&amp;quot;.&amp;quot;&amp;lt;name&amp;gt;&amp;quot; = derivation;&lt;br /&gt;
  # Executed by `nix build .`&lt;br /&gt;
  packages.&amp;quot;&amp;lt;system&amp;gt;&amp;quot;.default = derivation;&lt;br /&gt;
  # Executed by `nix run .#&amp;lt;name&amp;gt;`&lt;br /&gt;
  apps.&amp;quot;&amp;lt;system&amp;gt;&amp;quot;.&amp;quot;&amp;lt;name&amp;gt;&amp;quot; = {&lt;br /&gt;
    type = &amp;quot;app&amp;quot;;&lt;br /&gt;
    program = &amp;quot;&amp;lt;store-path&amp;gt;&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
  # Executed by `nix run . -- &amp;lt;args?&amp;gt;`&lt;br /&gt;
  apps.&amp;quot;&amp;lt;system&amp;gt;&amp;quot;.default = { type = &amp;quot;app&amp;quot;; program = &amp;quot;...&amp;quot;; };&lt;br /&gt;
&lt;br /&gt;
  # Formatter (alejandra, nixfmt or nixpkgs-fmt)&lt;br /&gt;
  formatter.&amp;quot;&amp;lt;system&amp;gt;&amp;quot; = derivation;&lt;br /&gt;
  # Used for nixpkgs packages, also accessible via `nix build .#&amp;lt;name&amp;gt;`&lt;br /&gt;
  legacyPackages.&amp;quot;&amp;lt;system&amp;gt;&amp;quot;.&amp;quot;&amp;lt;name&amp;gt;&amp;quot; = derivation;&lt;br /&gt;
  # Overlay, consumed by other flakes&lt;br /&gt;
  overlays.&amp;quot;&amp;lt;name&amp;gt;&amp;quot; = final: prev: { };&lt;br /&gt;
  # Default overlay&lt;br /&gt;
  overlays.default = final: prev: { };&lt;br /&gt;
  # Nixos module, consumed by other flakes&lt;br /&gt;
  nixosModules.&amp;quot;&amp;lt;name&amp;gt;&amp;quot; = { config, ... }: { options = {}; config = {}; };&lt;br /&gt;
  # Default module&lt;br /&gt;
  nixosModules.default = { config, ... }: { options = {}; config = {}; };&lt;br /&gt;
  # Used with `nixos-rebuild switch --flake .#&amp;lt;hostname&amp;gt;`&lt;br /&gt;
  # nixosConfigurations.&amp;quot;&amp;lt;hostname&amp;gt;&amp;quot;.config.system.build.toplevel must be a derivation&lt;br /&gt;
  nixosConfigurations.&amp;quot;&amp;lt;hostname&amp;gt;&amp;quot; = {};&lt;br /&gt;
  # Used by `nix develop .#&amp;lt;name&amp;gt;`&lt;br /&gt;
  devShells.&amp;quot;&amp;lt;system&amp;gt;&amp;quot;.&amp;quot;&amp;lt;name&amp;gt;&amp;quot; = derivation;&lt;br /&gt;
  # Used by `nix develop`&lt;br /&gt;
  devShells.&amp;quot;&amp;lt;system&amp;gt;&amp;quot;.default = derivation;&lt;br /&gt;
  # Hydra build jobs&lt;br /&gt;
  hydraJobs.&amp;quot;&amp;lt;attr&amp;gt;&amp;quot;.&amp;quot;&amp;lt;system&amp;gt;&amp;quot; = derivation;&lt;br /&gt;
  # Used by `nix flake init -t &amp;lt;flake&amp;gt;#&amp;lt;name&amp;gt;`&lt;br /&gt;
  templates.&amp;quot;&amp;lt;name&amp;gt;&amp;quot; = {&lt;br /&gt;
    path = &amp;quot;&amp;lt;store-path&amp;gt;&amp;quot;;&lt;br /&gt;
    description = &amp;quot;template description goes here?&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
  # Used by `nix flake init -t &amp;lt;flake&amp;gt;`&lt;br /&gt;
  templates.default = { path = &amp;quot;&amp;lt;store-path&amp;gt;&amp;quot;; description = &amp;quot;&amp;quot;; };&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:48--&amp;gt;&lt;br /&gt;
You can also define additional arbitrary attributes, but these are the outputs that Nix knows about.&lt;br /&gt;
&lt;br /&gt;
== Core usage patterns ==&lt;br /&gt;
&lt;br /&gt;
=== Making your evaluations pure === &amp;lt;!--T:60--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:61--&amp;gt;&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:62--&amp;gt;&lt;br /&gt;
* {{Nixpkgs Manual|name=fetchurl|anchor=#sec-pkgs-fetchers-fetchurl-inputs}} and {{Nixpkgs Manual|name=fetchzip|anchor=#sec-pkgs-fetchers-fetchzip-inputs}} require a &amp;lt;code&amp;gt;sha256&amp;lt;/code&amp;gt; argument to be considered pure.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:156--&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;builtins.currentSystem&amp;lt;/code&amp;gt; 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.&lt;br /&gt;
&lt;br /&gt;
*  &amp;lt;code&amp;gt;builtins.getEnv&amp;lt;/code&amp;gt; is also impure. Avoid reading from environment variables and likewise, do not reference files outside of the flake&#039;s directory.&lt;br /&gt;
&lt;br /&gt;
=== Defining a flake for multiple architectures ===&lt;br /&gt;
&lt;br /&gt;
Flakes force you to specify a program for each supported architecture. An example below shows how to write a flake that targets multiple architectures.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  description = &amp;quot;A flake targeting multiple architectures&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
  inputs = {&lt;br /&gt;
    nixpkgs.url = &amp;quot;github:nixos/nixpkgs?ref=nixos-unstable&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
&lt;br /&gt;
  outputs = { self, nixpkgs }: let&lt;br /&gt;
    systems = [ &amp;quot;x86_64-linux&amp;quot; &amp;quot;aarch64-linux&amp;quot; ];&lt;br /&gt;
    forAllSystems = f: builtins.listToAttrs (map (system: {&lt;br /&gt;
      name = system;&lt;br /&gt;
      value = f system;&lt;br /&gt;
    }) systems);&lt;br /&gt;
  in {&lt;br /&gt;
    packages = forAllSystems (system: let&lt;br /&gt;
      pkgs = nixpkgs.legacyPackages.${system};&lt;br /&gt;
    in {&lt;br /&gt;
      hello = pkgs.hello;&lt;br /&gt;
      default = pkgs.hello;&lt;br /&gt;
    });&lt;br /&gt;
  };&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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]]&lt;br /&gt;
&lt;br /&gt;
=== Using overlays === &lt;br /&gt;
&lt;br /&gt;
To use [[Overlays]] with flakes, refer to [[Overlays#In a Nix flake]] page.&lt;br /&gt;
&lt;br /&gt;
=== Enable unfree software === &amp;lt;!--T:129--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To allow for [[Unfree software|unfree software]] in a flake project, you need to explicitly allow it by setting &amp;lt;code&amp;gt;config.allowUnree = true;&amp;lt;/code&amp;gt; when importing Nixpkgs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  inputs.nixpkgs.url = &amp;quot;github:nixos/nixpkgs?ref=nixos-unstable&amp;quot;;&lt;br /&gt;
  outputs = { self, nixpkgs, flake-compat }:&lt;br /&gt;
    let&lt;br /&gt;
      system = &amp;quot;x86_64-linux&amp;quot;;&lt;br /&gt;
      pkgs = import nixpkgs { inherit system; config.allowUnfree = true;};&lt;br /&gt;
    in {&lt;br /&gt;
      ...&lt;br /&gt;
    };&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
== NixOS configuration with flakes ==&lt;br /&gt;
&lt;br /&gt;
It is possible to manage a [[NixOS]] system configuration using flakes, gaining the benefits of reproducible, declarative inputs and streamlined updates.&lt;br /&gt;
&lt;br /&gt;
For details and examples, see [[NixOS system configuration#Defining NixOS as a flake]].&lt;br /&gt;
&lt;br /&gt;
== Development tricks == &amp;lt;!--T:131--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Automatically switch nix shells with direnv === &amp;lt;!--T:97--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:98--&amp;gt;&lt;br /&gt;
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].&lt;br /&gt;
&lt;br /&gt;
=== Pushing Flakes to Cachix === &amp;lt;!--T:99--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
https://docs.cachix.org/pushing#flakes&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Flake support in projects without flakes === &amp;lt;!--T:50--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:51--&amp;gt;&lt;br /&gt;
The [https://github.com/edolstra/flake-compat flake-compat] library provides a compatibility layer that allows projects using traditional &amp;lt;code&amp;gt;default.nix&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;shell.nix&amp;lt;/code&amp;gt; files to operate with flakes. For more details and usage examples, see the [[Flake Compat]] page.&lt;br /&gt;
&lt;br /&gt;
Another project that allows consuming flakes from non-flake projects is [https://github.com/fricklerhandwerk/flake-inputs flake-inputs].&lt;br /&gt;
&lt;br /&gt;
=== Accessing flakes from Nix expressions === &amp;lt;!--T:58--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:59--&amp;gt;&lt;br /&gt;
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 &amp;lt;code&amp;gt;(builtins.getFlake &amp;quot;/path/to/directory&amp;quot;).packages.x86_64-linux.default&amp;lt;/code&amp;gt;, where &#039;directory&#039; is the directory that contains your &amp;lt;code&amp;gt;flake.nix&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Efficiently build multiple flake outputs ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:101--&amp;gt;&lt;br /&gt;
To push &#039;&#039;all&#039;&#039; flake outputs automatically, checkout [https://github.com/srid/devour-flake#usage devour-flake].&lt;br /&gt;
&lt;br /&gt;
=== Build a package added in a PR === &amp;lt;!--T:161--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxHighlight&amp;gt;&lt;br /&gt;
nix build github:nixos/nixpkgs?ref=pull/&amp;lt;PR_NUMBER&amp;gt;/head#&amp;lt;PACKAGE&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:162--&amp;gt;&lt;br /&gt;
this allows building a package that has not yet been added to nixpkgs.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:132--&amp;gt;&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxHighlight&amp;gt;&lt;br /&gt;
git fetch upstream pull/&amp;lt;PR_NUMBER&amp;gt;/head &amp;amp;&amp;amp; git checkout FETCH_HEAD &amp;amp;&amp;amp; nix build .#PACKAGE&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:163--&amp;gt;&lt;br /&gt;
this allows building a package that has not yet been added to nixpkgs.&lt;br /&gt;
&lt;br /&gt;
=== How to add a file locally in git but not include it in commits === &amp;lt;!--T:164--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:133--&amp;gt;&lt;br /&gt;
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 &amp;lt;code&amp;gt;extra/flake.nix&amp;lt;/code&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxHighlight&amp;gt;&lt;br /&gt;
git add --intent-to-add extra/flake.nix&lt;br /&gt;
git update-index --skip-worktree --assume-unchanged extra/flake.nix&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Rapid iteration of a direct dependency === &amp;lt;!--T:135--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:165--&amp;gt;&lt;br /&gt;
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 &amp;lt;code&amp;gt;nix develop --redirect &amp;lt;flake&amp;gt; &amp;lt;directory&amp;gt;&amp;lt;/code&amp;gt; command allows you to provide a mutable dependency to your shell as if it were built by Nix.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:136--&amp;gt;&lt;br /&gt;
Consider a situation where your executable, &amp;lt;code&amp;gt;consumexe&amp;lt;/code&amp;gt;, depends on a library, &amp;lt;code&amp;gt;libdep&amp;lt;/code&amp;gt;. You&#039;re trying to work on both at the same time, where changes to &amp;lt;code&amp;gt;libdep&amp;lt;/code&amp;gt; are reflected in real time for &amp;lt;code&amp;gt;consumexe&amp;lt;/code&amp;gt;. This workflow can be achieved like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxHighlight lang=bash&amp;gt;&lt;br /&gt;
cd ~/libdep-src-checkout/&lt;br /&gt;
nix develop # Or `nix-shell` if applicable.&lt;br /&gt;
export prefix=&amp;quot;./install&amp;quot; # configure nix to install it here&lt;br /&gt;
buildPhase   # build it like nix does&lt;br /&gt;
installPhase # install it like nix does&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:166--&amp;gt;&lt;br /&gt;
Now that you&#039;ve built the dependency, &amp;lt;code&amp;gt;consumexe&amp;lt;/code&amp;gt; can take it as an input. &#039;&#039;&#039;In another terminal&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
&amp;lt;syntaxHighlight lang=bash&amp;gt;&lt;br /&gt;
cd ~/consumexe-src-checkout/&lt;br /&gt;
nix develop --redirect libdep ~/libdep-src-checkout/install&lt;br /&gt;
echo $buildInputs | tr &amp;quot; &amp;quot; &amp;quot;\n&amp;quot; | grep libdep&lt;br /&gt;
# Output should show ~/libdep-src-checkout/ so you know it worked&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:167--&amp;gt;&lt;br /&gt;
If Nix warns you that your redirected flake isn&#039;t actually used as an input to the evaluated flake, try using the &amp;lt;code&amp;gt;--inputs-from .&amp;lt;/code&amp;gt; flag. If all worked well you should be able to &amp;lt;code&amp;gt;buildPhase &amp;amp;&amp;amp; installPhase&amp;lt;/code&amp;gt; when the dependency changes and rebuild your consumer with the new version &#039;&#039;without&#039;&#039; exiting the development shell.&lt;br /&gt;
&lt;br /&gt;
== See also == &amp;lt;!--T:138--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Official sources ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:139--&amp;gt;&lt;br /&gt;
* [https://nix.dev/concepts/flakes Flakes] - nix.dev&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:176--&amp;gt;&lt;br /&gt;
* [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.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:178--&amp;gt;&lt;br /&gt;
* [https://github.com/NixOS/nix/blob/master/src/nix/flake.md spec describing flake inputs in more detail]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:168--&amp;gt;&lt;br /&gt;
* [https://github.com/NixOS/rfcs/pull/49 RFC 49] (2019) - Original flakes specification&lt;br /&gt;
&lt;br /&gt;
=== Guides ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:169--&amp;gt;&lt;br /&gt;
* [https://jade.fyi/blog/flakes-arent-real/ Flakes aren&#039;t real and can&#039;t hurt you] (Jade Lovelace, 2024)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:170--&amp;gt;&lt;br /&gt;
* [https://github.com/ryan4yin/nixos-and-flakes-book NixOS &amp;amp; Flakes Book](Ryan4yin, 2023) - 🛠️ ❤️ An unofficial NixOS &amp;amp; Flakes book for beginners.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:171--&amp;gt;&lt;br /&gt;
* [https://xeiaso.net/blog/nix-flakes-1-2022-02-21 Nix Flakes: an Introduction] (Xe Iaso, 2022)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:172--&amp;gt;&lt;br /&gt;
* [https://serokell.io/blog/practical-nix-flakes Practical Nix Flakes] (Alexander Bantyev, 2021) - Intro article on working with Nix and Flakes&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:173--&amp;gt;&lt;br /&gt;
* [https://www.tweag.io/blog/2020-05-25-flakes/ Nix Flakes, Part 1: An introduction and tutorial] (Eelco Dolstra, 2020)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:174--&amp;gt;&lt;br /&gt;
* [https://www.tweag.io/blog/2020-06-25-eval-cache/ Nix Flakes, Part 2: Evaluation caching] (Eelco Dolstra, 2020)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:175--&amp;gt;&lt;br /&gt;
* [https://www.tweag.io/blog/2020-07-31-nixos-flakes/ Nix Flakes, Part 3: Managing NixOS systems] (Eelco Dolstra, 2020)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:177--&amp;gt;&lt;br /&gt;
* [https://www.youtube.com/watch?v=QXUlhnhuRX4&amp;amp;list=PLgknCdxP89RcGPTjngfNR9WmBgvD_xW0l Nix flakes 101: Introduction to nix flakes] (Jörg Thalheim, 2020) YouTube video&lt;br /&gt;
&lt;br /&gt;
=== Useful flake modules === &lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:179--&amp;gt;&lt;br /&gt;
* [[Flake Utils|flake-utils]]: Library to avoid some boiler-code when writing flakes&lt;br /&gt;
&lt;br /&gt;
* [[Flake Parts|flake-parts]]: Library to help write modular and organized flakes&lt;br /&gt;
&lt;br /&gt;
* [[Flake Compat|flake-compat]]: A compatibility layer for flakes&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:181--&amp;gt;&lt;br /&gt;
* [https://github.com/nix-community/todomvc-nix building Rust and Haskell flakes]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;br /&gt;
[[Category:Software]]&lt;br /&gt;
[[Category:Nix]]&lt;br /&gt;
[[Category:Nix Language]]&lt;br /&gt;
[[Category:Flakes]]&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=NixOS_as_a_desktop&amp;diff=22606</id>
		<title>NixOS as a desktop</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=NixOS_as_a_desktop&amp;diff=22606"/>
		<updated>2025-06-08T17:59:26Z</updated>

		<summary type="html">&lt;p&gt;Pigs: Move module configuration to the system configuration page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;languages/&amp;gt;&lt;br /&gt;
&amp;lt;translate&amp;gt;&lt;br /&gt;
&amp;lt;!--T:1--&amp;gt;&lt;br /&gt;
[[NixOS]] is a versatile operating system suitable for a wide range of use cases. This page is intended for users who wish to run NixOS as their primary desktop environment, either on physical hardware or within a virtual machine. Additionally, users planning to deploy NixOS in [[NixOS friendly hosters|cloud]] environments or on specialized server infrastructure may find it helpful to begin with the concepts and practices introduced here, as they provide a useful foundation for working within the broader [[Nix ecosystem]].&lt;br /&gt;
&lt;br /&gt;
== Installation == &amp;lt;!--T:2--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:4--&amp;gt;&lt;br /&gt;
Refer to [[NixOS Installation Guide]] to get started. Keep in mind that, for a desktop installation, you will probably want to make sure you start with at least 30 GiB of available disk space to allow for the [[:Category:Desktop environment|desktop environments]], [[:Category:Web Browser|web browsers]], and other [[:Category:Applications|graphical applications]], that would be typical of daily use. 15 GiB might be enough for a fairly bare-bones setup.&lt;br /&gt;
&lt;br /&gt;
== Managing your configuration == &amp;lt;!--T:7--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:8--&amp;gt;&lt;br /&gt;
As described in the [[Overview of the NixOS Linux distribution#Declarative Configuration]], NixOS is designed to be configured declaratively. This means the entire system configuration, including installed packages, system services, kernel parameters, and user accounts is defined in configuration files, typically in &amp;lt;code&amp;gt;/etc/nixos/configuration.nix&amp;lt;/code&amp;gt;. These settings can then be applied consistently and reproducibly across machines.&lt;br /&gt;
&lt;br /&gt;
The process for managing your configuration is documented in the {{NixOS Manual|name=NixOS official manual|anchor=#ch-configuration}}.&lt;br /&gt;
&lt;br /&gt;
=== System Configuration ===&lt;br /&gt;
&lt;br /&gt;
The primary configuration file, &amp;lt;code&amp;gt;/etc/nixos/configuration.nix&amp;lt;/code&amp;gt;, defines system-wide settings. This includes options like enabling services, managing system users, setting hardware options, and specifying installed packages. Changes are applied with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
# nixos-rebuild switch&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== User configuration with Home Manager ===&lt;br /&gt;
&lt;br /&gt;
For managing per-user configurations such as application preferences, command-line tools, and dotfiles, [[Home Manager]] provides a convenient, declarative approach. It allows users to define which programs should be installed and how they should be configured, without needing to include those settings in the system-wide [https://nixos.org/manual/nixos/stable/#sec-changing-config configuration.nix].&lt;br /&gt;
&lt;br /&gt;
Home Manager can be used independently of the system configuration and works with both traditional setups and newer [[Flakes]]-based configurations.&lt;br /&gt;
&lt;br /&gt;
=== With Flakes === &amp;lt;!--T:17--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:18--&amp;gt;&lt;br /&gt;
For users looking for a more streamlined and reproducible way to manage NixOS configurations, the [[Flakes]] feature has been gaining popularity within the community. While Flakes introduce some new concepts compared to traditional workflows, many users find them a convenient and organized approach to managing system and development configurations.&lt;br /&gt;
&lt;br /&gt;
Refer to [[Flakes#NixOS configuration with flakes]] for details on getting started.&lt;br /&gt;
&lt;br /&gt;
== Beyond initial setup == &amp;lt;!--T:21--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:22--&amp;gt;&lt;br /&gt;
Once your basic NixOS installation is complete and functional, you can further customize your system with a variety of optional configurations tailored for desktop use. For a list of recommended initial system configurations, see [[NixOS Installation Guide#NixOS configuration]].&lt;br /&gt;
&lt;br /&gt;
Common configuration areas include:&lt;br /&gt;
&lt;br /&gt;
==== Desktop Environments ====&lt;br /&gt;
&lt;br /&gt;
Install and configure full-featured environments such as [[GNOME]], [[KDE Plasma]], or [[Xfce]].&lt;br /&gt;
&lt;br /&gt;
See [[:Category:Desktop environment]] for a full list.&lt;br /&gt;
&lt;br /&gt;
==== Window Managers ====&lt;br /&gt;
&lt;br /&gt;
Set up lightweight or tiling window managers like [[i3]], [[Sway]], [[Hyprland]], or [[xmonad]].&lt;br /&gt;
&lt;br /&gt;
See [[:Category:Window managers]] for a full list.&lt;br /&gt;
&lt;br /&gt;
==== Display Managers (Login Managers) ==== &lt;br /&gt;
&lt;br /&gt;
Configure graphical session managers such as [[Gnome|GDM]], [[KDE|SDDM]], or [[LightDM]].&lt;br /&gt;
&lt;br /&gt;
==== Audio Setup ====&lt;br /&gt;
&lt;br /&gt;
Enable and configure [[:Category:Audio|audio]] systems like [[PipeWire]], [[PulseAudio]], or [[ALSA]].&lt;br /&gt;
&lt;br /&gt;
==== Network Management ====&lt;br /&gt;
&lt;br /&gt;
Use tools such as [[NetworkManager]] or [[systemd-networkd]] for managing [[Networking|network]] connections.&lt;br /&gt;
&lt;br /&gt;
==== Bluetooth Support ====&lt;br /&gt;
&lt;br /&gt;
Set up [[Bluetooth]] with blueman or other management tools.&lt;br /&gt;
&lt;br /&gt;
==== Power Management ====&lt;br /&gt;
&lt;br /&gt;
Configure [[laptop]] [[Power Management|battery management]], suspend, and hibernation with tools like [[Laptop#tlp|tlp]] or [[systemd]] services.&lt;br /&gt;
&lt;br /&gt;
==== Printing and Scanning ==== &lt;br /&gt;
&lt;br /&gt;
Enable [[Cups]] for printer support and tools like Sane for [[Scanners|scanning]] devices.&lt;br /&gt;
&lt;br /&gt;
== Tips and tricks == &amp;lt;!--T:12--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Modularizing your configuration with modules === &amp;lt;!--T:13--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{main|NixOS system configuration#Modularizing your configuration with modules}}&lt;br /&gt;
&lt;br /&gt;
== See also == &amp;lt;!--T:23--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--T:25--&amp;gt;&lt;br /&gt;
* [[Overview of the NixOS Linux distribution]]&lt;br /&gt;
* [[Comparison of NixOS setups]] for a table comparing some popular choices.&lt;br /&gt;
* [[Configuration Collection]] for a long list within the wiki.&lt;br /&gt;
* [https://github.com/topics/nix-flake nix-flake], [https://github.com/topics/nixos-configuration nixos-configuration], [https://github.com/topics/nixos-dotfiles nixos-dotfiles] Github topics&lt;br /&gt;
* [[Wil T Nix Guides]] Youtube video format guide&lt;br /&gt;
&lt;br /&gt;
[[Category:Desktop]]&lt;br /&gt;
[[Category:Guide]]&lt;br /&gt;
[[Category:NixOS]]&lt;br /&gt;
&amp;lt;/translate&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=NixOS&amp;diff=22605</id>
		<title>NixOS</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=NixOS&amp;diff=22605"/>
		<updated>2025-06-08T17:59:12Z</updated>

		<summary type="html">&lt;p&gt;Pigs: /* Declarative Configuration */ simplify section for newcommers, move more in-depth information into new page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Expansion|Incomplete (reason: it needs to be an easy introduction, because its one of the first articles new users read here. Thats why it needs to be simplified a bit and more complex topics should be moved to other articles))}}&lt;br /&gt;
&lt;br /&gt;
[https://nixos.org/ NixOS] is a Linux distribution based on the [[Nix]] package manager and build system. It supports [https://en.wikipedia.org/wiki/Declarative_programming declarative] system-wide [https://en.wikipedia.org/wiki/Configuration_management configuration management] as well as [https://en.wikipedia.org/wiki/Atomicity_(database_systems) atomic] upgrades and rollbacks, although it can additionally support [https://en.wikipedia.org/wiki/Imperative_programming imperative] package and user management. In NixOS, all components of the distribution &amp;amp;mdash; including the [https://en.wikipedia.org/wiki/Linux_kernel kernel], installed [https://en.wikipedia.org/wiki/Package_manager packages] and system configuration files &amp;amp;mdash; are built by [[Nix]] from [[Wikipedia:Pure function|pure functions]] called [[Nix Expression Language|Nix expressions]].&lt;br /&gt;
&lt;br /&gt;
Since Nix uses [https://en.wikipedia.org/wiki/Executable binary] caching, this provides a unique compromise between the binary-oriented approach used by distributions such as Debian and the [https://en.wikipedia.org/wiki/Source_code source]-oriented approach used by distributions such as Gentoo. Binaries can be used for standard components, and custom-built packages and modules can be used automatically when a pre-built binary is not available.&lt;br /&gt;
&lt;br /&gt;
Stable NixOS releases are delivered twice a year (around the end of May and the end of November). NixOS was created by [https://edolstra.github.io/ Eelco Dolstra] and [https://en.wikipedia.org/wiki/Armijn_Hemel Armijn Hemel], and initially released in 2003. It is community developed and maintained under the stewardship of the [[Nix_Community#NixOS_Foundation|NixOS Foundation]].&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
For a full installation guide, see the [https://nixos.org/nixos/manual/index.html#ch-installation Installation chapter of the NixOS manual]. This wiki also includes alternative or supplemental guides, such as [[NixOS as a desktop]].&lt;br /&gt;
&lt;br /&gt;
Most users will install NixOS via [https://nixos.org/download/#nixos-iso one of the ISO images.] Both &amp;quot;graphical&amp;quot; and &amp;quot;minimal&amp;quot; ISO variants are available for each supported architecture; the &amp;quot;graphical&amp;quot; images are suitable for users intending to install a desktop environment, and the &amp;quot;minimal&amp;quot; images are suitable for users intending to install NixOS in a server role or desiring a smaller ISO image. The ISO images are hybrid images which can be burnt to optical media or copied raw to a USB drive and booted as-is. See the installation guide for details.&lt;br /&gt;
&lt;br /&gt;
In addition to the ISO images, the [https://nixos.org/download/#nixos-iso download page] provides a number of alternative methods for installing NixOS. These include:&lt;br /&gt;
&lt;br /&gt;
* Virtual appliances in OVA format (compatible with VirtualBox);&lt;br /&gt;
* Amazon EC2 AMIs;&lt;br /&gt;
&lt;br /&gt;
Additionally, many existing Linux installations can be converted into NixOS installations using [https://github.com/elitak/nixos-infect nixos-infect] or [https://github.com/jeaye/nixos-in-place nixos-in-place]; this is particularly useful for installing NixOS on hosting providers which do not natively support NixOS.&lt;br /&gt;
&lt;br /&gt;
For information on installing NixOS on various ARM devices, see [[NixOS on ARM]].&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
&lt;br /&gt;
=== Declarative Configuration ===&lt;br /&gt;
&lt;br /&gt;
One of NixOS&#039;s defining features is its declarative configuration model, where the entire system state — including installed packages, system services, and settings — is described in configuration files. The primary file is typically located at &amp;lt;code&amp;gt;/etc/nixos/configuration.nix&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Changes to the configuration are applied atomically using &amp;lt;code&amp;gt;nixos-rebuild switch&amp;lt;/code&amp;gt;, ensuring reproducibility and the ability to roll back to previous states. Most users track their configuration files in a version control system, enabling consistent and portable system setups. These shortcomings are often rectified after-the-fact if at all by configuration management solutions such as Puppet, Ansible or Chef. These tools reconcile system configuration with a description of the expected state. However, these tools are not integrated into the operating system design and are simply layered on top, and OS configuration may still vary where an aspect of OS configuration has not been specified in the description of expected state. &lt;br /&gt;
&lt;br /&gt;
Unlike conventional distributions, where system configuration is often scattered across manually edited files, NixOS integrates configuration management directly into the operating system. This eliminates configuration drift and makes NixOS particularly well-suited for automated, reproducible deployments.&lt;br /&gt;
&lt;br /&gt;
For more details and examples on NixOS configurations, see [[NixOS system configuration]].&lt;br /&gt;
&lt;br /&gt;
=== Imperative Operations ===&lt;br /&gt;
&lt;br /&gt;
While NixOS is typically configured declaratively as much as possible, these are a few domains where imperative operations are still necessary; these include user environment management and channel management.&lt;br /&gt;
&lt;br /&gt;
====  User Environments ====&lt;br /&gt;
&lt;br /&gt;
In addition to declarative system configuration, NixOS users can utilize Nix&#039;s imperative &amp;lt;code&amp;gt;nix-env&amp;lt;/code&amp;gt; command to install packages at the user level, without changing the system state. See the [[Nix#User Environments| user environments section of the Nix article]] for more information.&lt;br /&gt;
&lt;br /&gt;
==== Channels ====&lt;br /&gt;
&lt;br /&gt;
NixOS, as well as Nix packages and NixOS modules are distributed through Nix channels: mechanisms for distributing Nix expressions as well as the associated binary caches for them. These channels are what determine which version of NixOS you are using, and they can be broadly categorized into &#039;&#039;stable&#039;&#039; and &#039;&#039;unstable&#039;&#039; channels, and &#039;&#039;large&#039;&#039; and &#039;&#039;small&#039;&#039; channels. Most users will want the stable/large channel, currently &amp;lt;code&amp;gt;nixos-24.05&amp;lt;/code&amp;gt;. For more information on channels and how to choose them, see the [[Channel branches]] article.&lt;br /&gt;
&lt;br /&gt;
Like packages installed via &amp;lt;code&amp;gt;nix-env&amp;lt;/code&amp;gt;, channels are managed at user-level. NixOS uses the channels set for the &amp;lt;code&amp;gt;root&amp;lt;/code&amp;gt; user to update the system-wide configuration; channels set for other users control only the user environment for that user. If you wish to change the channel used by the system-level configuration (&amp;lt;code&amp;gt;/etc/nixos/configuration.nix&amp;lt;/code&amp;gt;), ensure you run the correct &amp;lt;code&amp;gt;nix-channel&amp;lt;/code&amp;gt; command as root:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Common nix-channel commands&lt;br /&gt;
|-&lt;br /&gt;
|Listing current channels&lt;br /&gt;
|&amp;lt;code&amp;gt;nix-channel --list&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Adding a primary channel&lt;br /&gt;
|&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;nix-channel --add https://nixos.org/channels/channel-name nixos&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Adding other channels&lt;br /&gt;
|&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;nix-channel --add https://some.channel/url my-alias&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Remove a channel&lt;br /&gt;
|&amp;lt;code&amp;gt;nix-channel --remove channel-alias&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Updating a channel&lt;br /&gt;
|&amp;lt;code&amp;gt;nix-channel --update channel-alias&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Updating all channels&lt;br /&gt;
|&amp;lt;code&amp;gt;nix-channel --update&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Rollback the last update (useful if the last update breaks the &amp;lt;code&amp;gt;nixos-rebuild&amp;lt;/code&amp;gt;)&lt;br /&gt;
|&amp;lt;code&amp;gt;nix-channel --rollback&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Note that updating channels won&#039;t cause a rebuild in itself; if you want to update channels and rebuild, you can run &amp;lt;code&amp;gt;nixos-rebuild --upgrade switch&amp;lt;/code&amp;gt; to do both in one step.&lt;br /&gt;
&lt;br /&gt;
== Internals ==&lt;br /&gt;
&lt;br /&gt;
=== Comparison with traditional Linux Distributions ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Main Article: [[Nix vs. Linux Standard Base]]&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
The main difference between NixOS and other Linux distributions is that NixOS does not follow the [https://en.wikipedia.org/wiki/Linux_Standard_Base Linux Standard Base] file system structure. On LSB-compliant systems software is stored under &amp;lt;code&amp;gt;/{,usr}/{bin,lib,share}&amp;lt;/code&amp;gt; and configuration is generally stored in &amp;lt;code&amp;gt;/etc&amp;lt;/code&amp;gt;. Software binaries are available in the user environment if they are placed in one of the LSB&#039;s &amp;lt;code&amp;gt;/bin&amp;lt;/code&amp;gt; directories. When a program references dynamic libraries it will search for the required libraries in the LSB folders (&amp;lt;code&amp;gt;/lib&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;/usr/lib&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
In NixOS however &amp;lt;code&amp;gt;/lib&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;/usr/lib&amp;lt;/code&amp;gt; do not exist. Instead all system libraries, binaries, kernels, firmware and configuration files are placed in the [[Nix#Nix store|Nix store]]. The files and directories in &amp;lt;code&amp;gt;/nix/store&amp;lt;/code&amp;gt; are named by hashes of the information describing the built data. All of the files and directories placed in the Nix store are immutable. &amp;lt;code&amp;gt;/bin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;/usr/bin&amp;lt;/code&amp;gt; are almost absent: they contain only &amp;lt;code&amp;gt;/bin/sh&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;/usr/bin/env&amp;lt;/code&amp;gt; respectively, to provide minimal compatibility with existing scripts using shebang lines. User-level environments are implemented using a large number of symbolic links to all required packages and auxiliary files. These environments are called [[Nix#Profiles|profiles]] and are stored in &amp;lt;code&amp;gt;/nix/var/nix/profiles&amp;lt;/code&amp;gt;, each user having their own profiles. Structuring the system in this way is how NixOS obtains its key advantages over conventional Linux distributions, such as atomicity and rollback support.&lt;br /&gt;
&lt;br /&gt;
=== Usage of the Nix store ===&lt;br /&gt;
&lt;br /&gt;
A lot of confusion for newcomers arises from the fact that configuration is stored in the read-only &amp;lt;code&amp;gt;/nix/store&amp;lt;/code&amp;gt; tree along with all the installed packages. This fact makes it impossible to manually edit system configuration; all configuration changes must be performed by editing the &amp;lt;code&amp;gt;/etc/nixos/configuration.nix&amp;lt;/code&amp;gt; file and executing &amp;lt;code&amp;gt;nixos-rebuild switch&amp;lt;/code&amp;gt;. NixOS provides the [[NixOS_modules|module system]] for editing all required configurations. Users should first use [https://search.nixos.org/options the option search tool] to check if the option they need exists before attempting to manually add files or configuration via low-level NixOS features like activation scripts.&lt;br /&gt;
&lt;br /&gt;
The system purity makes it possible to keep system configuration in a central place, without the need to edit multiple files. This configuration can be distributed or version controlled as desired. It also provides for determinism; if you provide the same inputs, the same version of Nixpkgs and the same &amp;lt;code&amp;gt;/etc/nixos/configuration.nix&amp;lt;/code&amp;gt; you will get the exact same system state.&lt;br /&gt;
&lt;br /&gt;
=== Modules ===&lt;br /&gt;
&lt;br /&gt;
The [[NixOS modules|NixOS module system]] as defined in  [[Nixpkgs]] provides the means necessary to customize the configuration of the OS. It is used to enable and customize services such as nginx, enable firmware and customize the kernel.&lt;br /&gt;
&lt;br /&gt;
All module configuration is generally performed by adding options to &amp;lt;code&amp;gt;/etc/nixos/configuration.nix&amp;lt;/code&amp;gt;. Most of the examples in the wiki show how this file can be used to configure the OS.&lt;br /&gt;
&lt;br /&gt;
The NixOS module system implements a typing system which allows typechecking of option settings. It also enables options defined in multiple places to be merged automatically. This allows you to spread your configuration over multiple files, and the options you set across all of those files will be merged together:&lt;br /&gt;
&lt;br /&gt;
{{file|/etc/nixos/configuration.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  imports = [&lt;br /&gt;
    ./basic-webserver.nix&lt;br /&gt;
    ./blog.nix&lt;br /&gt;
  ];&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
{{file|/etc/nixos/basic-webserver.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  services.nginx.enable = true;&lt;br /&gt;
  services.nginx.virtualHosts.&amp;quot;example.com&amp;quot; = {&lt;br /&gt;
    root = &amp;quot;/var/www/example.com&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
{{file|/etc/nixos/blog.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  services.nginx.virtualHosts.&amp;quot;blog.example.com&amp;quot; = {&lt;br /&gt;
    root = &amp;quot;/var/www/blog.example.com&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
See the [https://nixos.org/nixos/manual/index.html#sec-writing-modules Modules section of the NixOS Manual] for more details.&lt;br /&gt;
&lt;br /&gt;
=== Generations ===&lt;br /&gt;
&lt;br /&gt;
Every time the system state is rebuilt using &amp;lt;code&amp;gt;nixos-rebuild switch&amp;lt;/code&amp;gt;, a new generation is created. You can revert to the previous generation at any time, which is useful if a configuration change (or system update) turns out to be detrimental.&lt;br /&gt;
&lt;br /&gt;
You can roll back via:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxHighlight lang=shell&amp;gt;&lt;br /&gt;
$ nix-env --rollback               # roll back a user environment&lt;br /&gt;
$ nixos-rebuild switch --rollback  # roll back a system environment&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
NixOS also places entries for previous generations in the bootloader menu, so as a last resort you can always revert to a previous configuration by rebooting. To set the currently booted generation as the default run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxHighlight lang=shell&amp;gt;&lt;br /&gt;
$ /run/current-system/bin/switch-to-configuration boot&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because NixOS keeps previous generations of system state available in case rollback is desired, old package versions aren&#039;t deleted from your system immediately after an update. You can delete old generations manually:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxHighlight lang=shell&amp;gt;&lt;br /&gt;
# delete generations older than 30 days&lt;br /&gt;
$ nix-collect-garbage --delete-older-than 30d&lt;br /&gt;
&lt;br /&gt;
# delete ALL previous generations - you can no longer rollback after running this&lt;br /&gt;
$ nix-collect-garbage -d                       &lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
List generations:&lt;br /&gt;
&amp;lt;syntaxHighlight lang=shell&amp;gt;&lt;br /&gt;
# as root&lt;br /&gt;
$ nix-env --list-generations --profile /nix/var/nix/profiles/system&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Switch generations:&lt;br /&gt;
&amp;lt;syntaxHighlight lang=shell&amp;gt;&lt;br /&gt;
# as root switch to generation 204&lt;br /&gt;
$ nix-env --profile /nix/var/nix/profiles/system --switch-generation 204&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
delete broken generation(s):&lt;br /&gt;
&amp;lt;syntaxHighlight lang=shell&amp;gt;&lt;br /&gt;
# as root delete broken generations 205 and 206 &lt;br /&gt;
$ nix-env --profile /nix/var/nix/profiles/system --delete-generations 205 206&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can configure automatic garbage collection by setting the [https://search.nixos.org/options?query=nix.gc nix.gc] options in &amp;lt;code&amp;gt;/etc/nixos/configuration.nix&amp;lt;/code&amp;gt;. This is recommended, as it keeps the size of the Nix store down.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[NixOS modules]], a library for modular [[Overview of the Nix Expression Language#Expressions|Nix expressions]] which powers [[#Declarative Configuration|the declarative configuration of NixOS]].&lt;br /&gt;
* [[NixOS VM tests]], a library for creating reproducible infrastructure tests, based on [[Nixpkgs]], [[NixOS]], QEMU and Perl.&lt;br /&gt;
* [https://github.com/ryan4yin/nixos-and-flakes-book NixOS &amp;amp; Flakes Book] (Ryan4yin, 2023) - 🛠️ ❤️ An unofficial NixOS &amp;amp; Flakes book for beginners. &lt;br /&gt;
&lt;br /&gt;
[[Category:Pedias]]&lt;br /&gt;
[[Category:NixOS]]&lt;br /&gt;
[[Category:Nix]]&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=NixOS_system_configuration&amp;diff=22604</id>
		<title>NixOS system configuration</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=NixOS_system_configuration&amp;diff=22604"/>
		<updated>2025-06-08T17:58:54Z</updated>

		<summary type="html">&lt;p&gt;Pigs: Create page, move some content from Flakes, NixOs as a desktop, and Overview of the NixOS Linux distributions pages to here&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[NixOS]] uses a declarative configuration system that allows users to manage their entire operating system setup including installed packages, system services, user accounts, hardware settings, and more through configuration files. This page serves as an overview of how to work with and manage NixOS system configurations.&lt;br /&gt;
&lt;br /&gt;
For an introduction to declarative configuration, see the [[Overview of the NixOS Linux distribution#Declarative Configuration]] and the {{NixOS Manual|name=NixOS official manual|anchor=#ch-configuration}}.&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
&lt;br /&gt;
When you install NixOS, a default system configuration template is generated by the [[nixos-generate-config]] tool. This creates a basic &amp;lt;code&amp;gt;configuration.nix&amp;lt;/code&amp;gt; file along with a corresponding &amp;lt;code&amp;gt;hardware-configuration.nix&amp;lt;/code&amp;gt;, which captures detected hardware settings and filesystem definitions. After making changes to &amp;lt;code&amp;gt;configuration.nix&amp;lt;/code&amp;gt;, you can apply them using [[nixos-rebuild]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
# nixos-rebuild switch&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is a simple example of a NixOS system configuration:&lt;br /&gt;
&lt;br /&gt;
{{file|/etc/nixos/configuration.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
{ config, pkgs, ... }: &lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    # Import other configuration modules&lt;br /&gt;
    # (hardware-configuration.nix is autogenerated upon installation)&lt;br /&gt;
    # paths in nix expressions are always relative the file which defines them&lt;br /&gt;
    imports = [&lt;br /&gt;
        ./hardware-configuration.nix&lt;br /&gt;
        ./my-dev-tools.nix&lt;br /&gt;
        ./my-desktop-env.nix&lt;br /&gt;
        ./etc.nix&lt;br /&gt;
    ];&lt;br /&gt;
&lt;br /&gt;
    # Name your host machine&lt;br /&gt;
    networking.hostName = &amp;quot;mymachine&amp;quot;; &lt;br /&gt;
&lt;br /&gt;
    # Set your time zone.&lt;br /&gt;
    time.timeZone = &amp;quot;Europe/Utrecht&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
    # Enter keyboard layout&lt;br /&gt;
    services.xserver.layout = &amp;quot;us&amp;quot;;&lt;br /&gt;
    services.xserver.xkbVariant = &amp;quot;altgr-intl&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
    # Define user accounts&lt;br /&gt;
    users.users.myuser = {&lt;br /&gt;
      extraGroups = [ &amp;quot;wheel&amp;quot; &amp;quot;networkmanager&amp;quot; ];&lt;br /&gt;
      isNormalUser = true;&lt;br /&gt;
    };&lt;br /&gt;
    &lt;br /&gt;
    # Install some packages&lt;br /&gt;
    environment.systemPackages = with pkgs; [&lt;br /&gt;
      ddate&lt;br /&gt;
      testdisk&lt;br /&gt;
    ]; &lt;br /&gt;
 &lt;br /&gt;
    # Enable the OpenSSH daemon&lt;br /&gt;
    services.openssh.enable = true;&lt;br /&gt;
    &lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
To find NixOS module options, see https://search.nixos.org/options.&lt;br /&gt;
&lt;br /&gt;
== Defining NixOS as a flake ==&lt;br /&gt;
&lt;br /&gt;
[[Flakes]] offer an alternative, modern way to configure NixOS systems using a standardized and reproducible structure. With flakes, the system configuration — along with any additional inputs such as Nixpkgs or external modules — is managed declaratively within a &amp;lt;code&amp;gt;flake.nix&amp;lt;/code&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
Unlike the traditional configuration model, which relies on &amp;lt;code&amp;gt;/etc/nixos/configuration.nix&amp;lt;/code&amp;gt; and channels, flakes explicitly define their dependencies and configurations, making it easier to share, version, and reproduce complete NixOS system setups.&lt;br /&gt;
&lt;br /&gt;
By default, [[Nixos-rebuild|&amp;lt;code&amp;gt;nixos-rebuild switch&amp;lt;/code&amp;gt;]] will read its [[Overview_of_the_NixOS_Linux_distribution#Declarative_Configuration system configuration|configuration]] from &amp;lt;code&amp;gt;/etc/nixos/flake.nix&amp;lt;/code&amp;gt; if it is present.&lt;br /&gt;
&lt;br /&gt;
An example basic [[NixOS]] flake:&lt;br /&gt;
&lt;br /&gt;
{{file|flake.nix|nix|&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  inputs.nixpkgs.url = github:NixOS/nixpkgs/nixos-unstable;&lt;br /&gt;
  outputs = { self, nixpkgs }: {&lt;br /&gt;
    # replace &#039;joes-desktop&#039; with your hostname here.&lt;br /&gt;
    nixosConfigurations.joes-desktop = nixpkgs.lib.nixosSystem {&lt;br /&gt;
      modules = [ ./configuration.nix ];&lt;br /&gt;
    };&lt;br /&gt;
  };&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Accessing flake inputs ===&lt;br /&gt;
&lt;br /&gt;
If you want to pass on the flake inputs to external configuration files, you can use the &amp;lt;code&amp;gt;specialArgs&amp;lt;/code&amp;gt; attribute:&lt;br /&gt;
&lt;br /&gt;
{{file|flake.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  inputs.nixpkgs.url = github:NixOS/nixpkgs/nixos-unstable;&lt;br /&gt;
  inputs.home-manager.url = github:nix-community/home-manager;&lt;br /&gt;
&lt;br /&gt;
  outputs = { self, nixpkgs, ... }@inputs: {&lt;br /&gt;
    nixosConfigurations.fnord = nixpkgs.lib.nixosSystem {&lt;br /&gt;
      specialArgs = { inherit inputs; };&lt;br /&gt;
      modules = [ ./configuration.nix ];&lt;br /&gt;
    };&lt;br /&gt;
  };&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Then, you can access the flake inputs from your system configuration:&lt;br /&gt;
&lt;br /&gt;
{{file|configuration.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
{ config, lib, inputs, ... }: {&lt;br /&gt;
  # do something with home-manager here, for instance:&lt;br /&gt;
  imports = [ inputs.home-manager.nixosModules.default ];&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Specifying hostname ===&lt;br /&gt;
&lt;br /&gt;
By default &amp;lt;code&amp;gt;nixos-rebuild&amp;lt;/code&amp;gt; will use the current system hostname to look up the right NixOS configuration in &amp;lt;code&amp;gt;nixosConfigurations&amp;lt;/code&amp;gt;. You can also override this by using appending it to the flake parameter:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
# nixos-rebuild switch --flake /etc/nixos#joes-desktop&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To switch a remote host you can use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
$ nixos-rebuild --flake .#mymachine \&lt;br /&gt;
  --target-host mymachine-hostname \&lt;br /&gt;
  --build-host mymachine-hostname --fast \&lt;br /&gt;
  switch&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{note|Remote building has an issue that&#039;s [https://github.com/NixOS/nixpkgs/issues/134952#issuecomment-1367056358 resolved by setting the &amp;lt;code&amp;gt;--fast&amp;lt;/code&amp;gt; flag].}}&lt;br /&gt;
&lt;br /&gt;
== Tips and tricks ==&lt;br /&gt;
&lt;br /&gt;
=== Using a non-default configuration location ===&lt;br /&gt;
&lt;br /&gt;
By default, NixOS expects system configuration files to be located in &amp;lt;code&amp;gt;/etc/nixos/&amp;lt;/code&amp;gt;, with the primary configuration file at &amp;lt;code&amp;gt;/etc/nixos/configuration.nix&amp;lt;/code&amp;gt;. However, it is possible to manage your configuration from a different location.&lt;br /&gt;
&lt;br /&gt;
You can specify a different configuration file when rebuilding the system by providing the path via the &amp;lt;code&amp;gt;-I&amp;lt;/code&amp;gt; option:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
# nixos-rebuild switch -I nixos-config=/path/to/configuration.nix&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you are using [[Flakes]], specify the flake path instead:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
# nixos-rebuild switch --flake /path/to/flake.nix&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To set a custom configuration location declaratively, you can configure the &amp;lt;code&amp;gt;nix.nixPath&amp;lt;/code&amp;gt; option in your system configuration:&lt;br /&gt;
&lt;br /&gt;
{{file|/etc/nixos/configuration.nix|nix|&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  nix.nixPath = [ &amp;quot;path to config&amp;quot; ];&lt;br /&gt;
  ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Alternatively, you may also set the location with &amp;lt;code&amp;gt;NIX_PATH=&amp;quot;nixos-config=/path/to/configuration.nix&amp;quot;&amp;lt;/code&amp;gt; environment variable or by symlinking &amp;lt;code&amp;gt;/etc/nixos/configuration.nix&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Modularizing your configuration with modules ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;configuration.nix&amp;lt;/code&amp;gt; file itself is an instance of a [[NixOS modules|NixOS module]], and the NixOS module system makes it straightforward to split your configuration into multiple files for better organization and reusability. Modules can:&lt;br /&gt;
&lt;br /&gt;
* Import other modules&lt;br /&gt;
* Declare new configuration options&lt;br /&gt;
* Provide values for existing options (this is what most of a standard configuration.nix does)&lt;br /&gt;
* Reference option values from other modules (via the &amp;lt;code&amp;gt;config&amp;lt;/code&amp;gt; attribute passed to all modules)&lt;br /&gt;
&lt;br /&gt;
By declaring options for any values you wish to share between modules, you can structure your configuration into as many files as you like, importing them directly or indirectly from your root &amp;lt;code&amp;gt;configuration.nix&amp;lt;/code&amp;gt; file. This makes it easier to manage large or complex configurations by keeping related settings together.&lt;br /&gt;
&lt;br /&gt;
Additionally, you can import modules from remote sources if desired, for example using &amp;lt;/code&amp;gt;builtins.fetchTarball&amp;lt;/code&amp;gt; or similar functions, which is particularly useful for sharing configurations across multiple machines or pulling in reusable modules maintained elsewhere.&lt;br /&gt;
&lt;br /&gt;
Refer to [[NixOS modules]] page and {{NixOS Manual|name=NixOS Manual: Chapter - Package Management|anchor=#sec-writing-modules}} for more information on modules.&lt;br /&gt;
&lt;br /&gt;
=== Flake-specific tips ===&lt;br /&gt;
&lt;br /&gt;
==== Importing packages from multiple nixpkgs branches ====&lt;br /&gt;
&lt;br /&gt;
A NixOS config flake could be as follows (replace &amp;lt;hostname&amp;gt; with your hostname):&lt;br /&gt;
&lt;br /&gt;
{{file|flake.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  description = &amp;quot;NixOS configuration with two or more channels&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
 inputs = {&lt;br /&gt;
    nixpkgs.url = &amp;quot;github:NixOS/nixpkgs/nixos-24.11&amp;quot;;&lt;br /&gt;
    nixpkgs-unstable.url = &amp;quot;github:NixOS/nixpkgs/nixos-unstable&amp;quot;;&lt;br /&gt;
  };&lt;br /&gt;
&lt;br /&gt;
  outputs =&lt;br /&gt;
    { nixpkgs, nixpkgs-unstable, ... }:&lt;br /&gt;
    {&lt;br /&gt;
      nixosConfigurations.&amp;quot;&amp;lt;hostname&amp;gt;&amp;quot; = nixpkgs.lib.nixosSystem {&lt;br /&gt;
        modules = [&lt;br /&gt;
          {&lt;br /&gt;
            nixpkgs.overlays = [&lt;br /&gt;
              (final: prev: {&lt;br /&gt;
                unstable = nixpkgs-unstable.legacyPackages.${prev.system};&lt;br /&gt;
                # use this variant if unfree packages are needed:&lt;br /&gt;
                # unstable = import nixpkgs-unstable {&lt;br /&gt;
                #   inherit prev;&lt;br /&gt;
                #   system = prev.system;&lt;br /&gt;
                #   config.allowUnfree = true;&lt;br /&gt;
                # };&lt;br /&gt;
              })&lt;br /&gt;
            ];&lt;br /&gt;
          }&lt;br /&gt;
          ./configuration.nix&lt;br /&gt;
        ];&lt;br /&gt;
      };&lt;br /&gt;
    };&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{file|flake.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
# can now use &amp;quot;pkgs.package&amp;quot; or &amp;quot;pkgs.unstable.package&amp;quot;&lt;br /&gt;
{ pkgs, ... }:&lt;br /&gt;
{&lt;br /&gt;
  environment.systemPackages = [&lt;br /&gt;
    pkgs.firefox&lt;br /&gt;
    pkgs.unstable.chromium&lt;br /&gt;
  ];&lt;br /&gt;
  # ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
If the variable &amp;lt;code&amp;gt;nixpkgs&amp;lt;/code&amp;gt; points to the flake, you can also define &amp;lt;code&amp;gt;pkgs&amp;lt;/code&amp;gt; with overlays with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
pkgs = import nixpkgs { system = &amp;quot;x86_64-linux&amp;quot;; overlays = [ /*the overlay in question*/ ]; };&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Pinning the flake registry on NixOS ====&lt;br /&gt;
&lt;br /&gt;
When you use flakes, Nix resolves flake inputs using the [https://github.com/NixOS/flake-registry flake registry], a mapping of named flake URLs to specific locations (e.g. what &amp;lt;code&amp;gt;nixpkgs&amp;lt;/code&amp;gt; resolves to).&lt;br /&gt;
&lt;br /&gt;
By default, &amp;lt;code&amp;gt;nixpkgs&amp;lt;/code&amp;gt; tracks &amp;lt;code&amp;gt;nixpkgs-unstable&amp;lt;/code&amp;gt;. This can lead to silent changes in dependency resolution and increase build times as it has to fetch the latest versions.&lt;br /&gt;
&lt;br /&gt;
You can lock the registry to your current system&#039;s Nixpkgs version by:&lt;br /&gt;
&lt;br /&gt;
{{file|configuration.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
{ inputs, ... }:&lt;br /&gt;
{&lt;br /&gt;
 nix.registry = {&lt;br /&gt;
    nixpkgs.flake = inputs.nixpkgs;&lt;br /&gt;
  };&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
To make sure the registry entry is &amp;quot;locked&amp;quot; by checking against a hash, use the following:&lt;br /&gt;
&lt;br /&gt;
{{file|configuration.nix|nix|&amp;lt;nowiki&amp;gt;&lt;br /&gt;
  nix.registry = {&lt;br /&gt;
    nixpkgs.to = {&lt;br /&gt;
      type = &amp;quot;path&amp;quot;;&lt;br /&gt;
      path = pkgs.path;&lt;br /&gt;
      narHash = builtins.readFile&lt;br /&gt;
          (pkgs.runCommandLocal &amp;quot;get-nixpkgs-hash&amp;quot;&lt;br /&gt;
            { nativeBuildInputs = [ pkgs.nix ]; }&lt;br /&gt;
            &amp;quot;nix-hash --type sha256 --sri ${pkgs.path} &amp;gt; $out&amp;quot;);&lt;br /&gt;
    };&lt;br /&gt;
  };&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
This has the unfortunate side-effect of requiring import-from-derivation and slowing down build times, however it may greatly speed up almost every eval. Full-time flakes users may be able to just use &amp;lt;code&amp;gt;narHash = pkgs.narHash&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== Getting &#039;&#039;Instant&#039;&#039; System Flakes Repl ====&lt;br /&gt;
&lt;br /&gt;
How to get a nix repl out of your system flake:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
$ nix repl&lt;br /&gt;
&lt;br /&gt;
nix-repl&amp;gt; :lf /path/to/flake&lt;br /&gt;
Added 18 variables.&lt;br /&gt;
&lt;br /&gt;
nix-repl&amp;gt; nixosConfigurations.myHost.config.networking.hostName&lt;br /&gt;
&amp;quot;myHost&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However, this won&#039;t be instant upon evaluation if any file changes have been done since your last configuration rebuild. Instead, if one puts:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxHighlight lang=nix&amp;gt;&lt;br /&gt;
nix.nixPath = let path = toString ./.; in [ &amp;quot;repl=${path}/repl.nix&amp;quot; &amp;quot;nixpkgs=${inputs.nixpkgs}&amp;quot; ];&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In their system &amp;lt;code&amp;gt;flake.nix&amp;lt;/code&amp;gt; configuration file, and includes the following file in their root directory flake as &amp;lt;code&amp;gt;repl.nix&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxHighlight lang=nix&amp;gt;&lt;br /&gt;
let&lt;br /&gt;
  flake = builtins.getFlake (toString ./.);&lt;br /&gt;
  nixpkgs = import &amp;lt;nixpkgs&amp;gt; { };&lt;br /&gt;
in&lt;br /&gt;
{ inherit flake; }&lt;br /&gt;
// flake&lt;br /&gt;
// builtins&lt;br /&gt;
// nixpkgs&lt;br /&gt;
// nixpkgs.lib&lt;br /&gt;
// flake.nixosConfigurations&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(Don&#039;t forget to &amp;lt;code&amp;gt;git add repl.nix &amp;amp;&amp;amp; nixos-rebuild  switch --flake &amp;quot;/etc/nixos&amp;quot;&amp;lt;/code&amp;gt;)&lt;br /&gt;
Then one can run (or bind a shell alias):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxHighlight lang=console&amp;gt;&lt;br /&gt;
$ source /etc/set-environment &amp;amp;&amp;amp; nix repl $(echo $NIX_PATH | perl -pe &#039;s|.*(/nix/store/.*-source/repl.nix).*|\1|&#039;)&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will launch a repl with access to &amp;lt;code&amp;gt;nixpkgs&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;lib&amp;lt;/code&amp;gt;, and the &amp;lt;code&amp;gt;flake&amp;lt;/code&amp;gt; options in a split of a second.&lt;br /&gt;
&lt;br /&gt;
An alternative approach to the above shell alias is omitting &amp;lt;code&amp;gt;repl&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;nix.nixPath&amp;lt;/code&amp;gt; and creating a [[Shell Scripts|shell script]]:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxHighlight lang=nix&amp;gt;&lt;br /&gt;
nix.nixPath = [ &amp;quot;nixpkgs=${inputs.nixpkgs}&amp;quot; ];&lt;br /&gt;
environment.systemPackages = let&lt;br /&gt;
  repl_path = toString ./.;&lt;br /&gt;
  my-nix-fast-repl = pkgs.writeShellScriptBin &amp;quot;my-nix-fast-repl&amp;quot; &#039;&#039;&lt;br /&gt;
    source /etc/set-environment&lt;br /&gt;
    nix repl &amp;quot;${repl_path}/repl.nix&amp;quot; &amp;quot;$@&amp;quot;&lt;br /&gt;
  &#039;&#039;;&lt;br /&gt;
in [&lt;br /&gt;
  my-nix-fast-repl&lt;br /&gt;
];&lt;br /&gt;
&amp;lt;/syntaxHighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
&lt;br /&gt;
* [[Updating NixOS]] - Updating the set of [[Nixpkgs]] the system uses&lt;br /&gt;
&lt;br /&gt;
* [[NixOS as a dekstop]] - Configuration tips for setting up NixOS as a desktop&lt;br /&gt;
&lt;br /&gt;
* [[Nixos-rebuild]] - Command to apply changes to system configuration&lt;br /&gt;
&lt;br /&gt;
* [[Home Manager]] - A system for per-user configuration environments&lt;br /&gt;
&lt;br /&gt;
* [[NixOS configuration editors]] - Recommendations for improving NixOS configuration experience&lt;br /&gt;
&lt;br /&gt;
* [[Configuration Collection]] - Community member&#039;s NixOS confiugration files for inspiration&lt;br /&gt;
&lt;br /&gt;
[[Category:NixOS]]&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=Btrfs&amp;diff=22522</id>
		<title>Btrfs</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=Btrfs&amp;diff=22522"/>
		<updated>2025-06-08T05:48:27Z</updated>

		<summary type="html">&lt;p&gt;Pigs: Include trim support section&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[https://btrfs.readthedocs.io/en/latest/ btrfs] is a modern copy on write (CoW) filesystem for Linux aimed at implementing advanced features while also focusing on fault tolerance, repair and easy administration.&lt;br /&gt;
&lt;br /&gt;
{{note| Use [https://github.com/nix-community/disko/ disko] to manage your NixOS storage layout declaratively. The following shows a manual approach as seen in traditional Linux distributions.}}&lt;br /&gt;
&lt;br /&gt;
= Installation of NixOS on btrfs =&lt;br /&gt;
&lt;br /&gt;
{{note|The following example is for EFI enabled systems. Adjust commands accordingly for a BIOS installation.}}&lt;br /&gt;
&lt;br /&gt;
== Partition the disk ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
# printf &amp;quot;label: gpt\n,550M,U\n,,L\n&amp;quot; | sfdisk /dev/sdX&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Format partitions and create subvolumes ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
# nix-shell -p btrfs-progs&lt;br /&gt;
# mkfs.fat -F 32 /dev/sdX1&lt;br /&gt;
&lt;br /&gt;
# mkfs.btrfs /dev/sdX2&lt;br /&gt;
# mkdir -p /mnt&lt;br /&gt;
# mount /dev/sdX2 /mnt&lt;br /&gt;
# btrfs subvolume create /mnt/root&lt;br /&gt;
# btrfs subvolume create /mnt/home&lt;br /&gt;
# btrfs subvolume create /mnt/nix&lt;br /&gt;
# umount /mnt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Mount the partitions and subvolumes ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
# mount -o compress=zstd,subvol=root /dev/sdX2 /mnt&lt;br /&gt;
# mkdir /mnt/{home,nix}&lt;br /&gt;
# mount -o compress=zstd,subvol=home /dev/sdX2 /mnt/home&lt;br /&gt;
# mount -o compress=zstd,noatime,subvol=nix /dev/sdX2 /mnt/nix&lt;br /&gt;
&lt;br /&gt;
# mkdir /mnt/boot&lt;br /&gt;
# mount /dev/sdX1 /mnt/boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Install NixOS ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
# nixos-generate-config --root /mnt&lt;br /&gt;
# nano /mnt/etc/nixos/configuration.nix # manually add mount options (see Compression below for an example)&lt;br /&gt;
# nixos-install&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Configuration =&lt;br /&gt;
&lt;br /&gt;
== Compression ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;nixos-generate-config&amp;lt;/code&amp;gt; doesn&#039;t detect mount options automatically. To enable compression, you must specify them manually and other mount options in your &amp;lt;code&amp;gt;configuration.nix&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
{{file|/etc/nixos/configuration.nix|nix|&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
fileSystems = {&lt;br /&gt;
  &amp;quot;/&amp;quot;.options = [ &amp;quot;compress=zstd&amp;quot; ];&lt;br /&gt;
  &amp;quot;/home&amp;quot;.options = [ &amp;quot;compress=zstd&amp;quot; ];&lt;br /&gt;
  &amp;quot;/nix&amp;quot;.options = [ &amp;quot;compress=zstd&amp;quot; &amp;quot;noatime&amp;quot; ];&lt;br /&gt;
  &amp;quot;/swap&amp;quot;.options = [ &amp;quot;noatime&amp;quot; ];&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Btrfs supports a few compression algorithms, each with different trade-offs:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;zstd&amp;lt;/code&amp;gt;: Good compression ratio and performance, especially for general-purpose workloads. You can specify compression levels, as example &amp;lt;code&amp;gt;compress=zstd:3&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;lzo&amp;lt;/code&amp;gt;: Faster but provides lower compression ratios. Good for low powered systems or where performance is important.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;zlib&amp;lt;/code&amp;gt;: Higher compression ratio but slower performance. Less commonly used nowadays in favor of zstd.&lt;br /&gt;
&lt;br /&gt;
You can find more details on the official [https://btrfs.readthedocs.io/en/latest/Compression.html Btrfs Compression Documentation].&lt;br /&gt;
&lt;br /&gt;
{{note| Compression is applied only to newly written data. Existing data won&#039;t be compressed unless rewritten. (e.g., &amp;lt;code&amp;gt;btrfs filesystem defrag -r -v -czstd /path&amp;lt;/code&amp;gt;)}}&lt;br /&gt;
&lt;br /&gt;
== Swap file ==&lt;br /&gt;
&lt;br /&gt;
Creating a separate subvolume for the swap file is optional. It is not required for functionality but can help with organization or snapshot management. Be sure to regenerate your &amp;lt;code&amp;gt;hardware-configuration.nix&amp;lt;/code&amp;gt; if you choose to do this.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;console&amp;quot;&amp;gt;&lt;br /&gt;
# mkdir -p /mnt&lt;br /&gt;
# mount /dev/sdXY /mnt&lt;br /&gt;
# btrfs subvolume create /mnt/swap&lt;br /&gt;
# umount /mnt&lt;br /&gt;
# mkdir /swap&lt;br /&gt;
# mount -o noatime,subvol=swap /dev/sdXY /swap&lt;br /&gt;
# nixos-generate-config&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Finally, define a swap file in your configuration and run &amp;lt;code&amp;gt;nixos-rebuild switch&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
{{file|/etc/nixos/configuration.nix|nix|&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
swapDevices = [{ &lt;br /&gt;
  device = &amp;quot;/swap/swapfile&amp;quot;; &lt;br /&gt;
  size = 8*1024; # Creates an 8GB swap file &lt;br /&gt;
}];&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
NixOS will automatically create the swap file with the appropriate attributes for Btrfs including disabling copy on write. &lt;br /&gt;
&lt;br /&gt;
{{note| On systems where you do need to manually prepare a swap file on Btrfs, you can use &amp;lt;code&amp;gt;btrfs filesystem mkswapfile&amp;lt;/code&amp;gt; utility, e.g.: &amp;lt;br&amp;gt;&amp;lt;code&amp;gt;# btrfs filesystem mkswapfile --uuid clear /swap/swapfile&amp;lt;/code&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
For more NixOS swap configuration options, see [[Swap]]. Additonal Btrfs swapfile usage can be found at [https://btrfs.readthedocs.io/en/latest/Swapfile.html the Btrfs docs].&lt;br /&gt;
&lt;br /&gt;
== Scrubbing ==&lt;br /&gt;
&lt;br /&gt;
Btrfs filesystems by default keep checksums for all files, to monitor if the file has changed due to hardware malfunctions or other external effects.&lt;br /&gt;
&lt;br /&gt;
Scrubbing is the process of checking file consistency, which may use checksums and/or duplicated copies of data, from raid for example. Scrubbing may be done &amp;quot;online&amp;quot;, meaning you don&#039;t need to unmount a subvolume to scrub it.&lt;br /&gt;
&lt;br /&gt;
You can enable automatic scrubbing withː&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
services.btrfs.autoScrub.enable = true;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Automatic scrubbing by default is performed once a month, but you can change that withː&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
services.btrfs.autoScrub.interval = &amp;quot;weekly&amp;quot;;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;interval&amp;lt;/code&amp;gt; syntax is defined by [https://www.freedesktop.org/software/systemd/man/systemd.time.html#Calendar%20Events systemd.timer&#039;s Calendar Events]&lt;br /&gt;
&lt;br /&gt;
By default, autoscrub will scrub all detected btrfs mount points. However, in case of mounted nested subvolumes (e.g. the example above where &amp;lt;code&amp;gt;/nix&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;/home&amp;lt;/code&amp;gt; are nested subvolumes under &amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt;), you only need to scrub the topmost one. So an example configuration may look like this:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
services.btrfs.autoScrub = {&lt;br /&gt;
  enable = true;&lt;br /&gt;
  interval = &amp;quot;monthly&amp;quot;;&lt;br /&gt;
  fileSystems = [ &amp;quot;/&amp;quot; ];&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result of the periodic auto scrub will be saved to the system journal, and you can check the status of the last scrubː&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
btrfs scrub status /&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also start a scrub in the background manuallyː&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
btrfs scrub start /&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
You can check the status of the ongoing scrubbing process with the same &amp;lt;code&amp;gt;status&amp;lt;/code&amp;gt; command as above.&lt;br /&gt;
&lt;br /&gt;
== Deduplication ==&lt;br /&gt;
&lt;br /&gt;
Files with (partially) equal contents can be deduplicated using [https://github.com/Zygo/bees bees] or [https://github.com/markfasheh/duperemove duperemove].&lt;br /&gt;
&lt;br /&gt;
bees can be configured in &amp;lt;code&amp;gt;configuration.nix&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
services.beesd.filesystems = {&lt;br /&gt;
  root = {&lt;br /&gt;
    spec = &amp;quot;LABEL=root&amp;quot;;&lt;br /&gt;
    hashTableSizeMB = 2048;&lt;br /&gt;
    verbosity = &amp;quot;crit&amp;quot;;&lt;br /&gt;
    extraOptions = [ &amp;quot;--loadavg-target&amp;quot; &amp;quot;5.0&amp;quot; ];&lt;br /&gt;
  };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will run the daemon in the background. To disable auto-start, use &amp;lt;code&amp;gt;systemd.services.&amp;quot;beesd@root&amp;quot;.wantedBy = lib.mkForce [ ];&amp;lt;/code&amp;gt; for each filesystem.&lt;br /&gt;
&lt;br /&gt;
= Usage =&lt;br /&gt;
&lt;br /&gt;
== Subvolumes ==&lt;br /&gt;
&lt;br /&gt;
To display all subvolumes within a mounted btrfs filesystem:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
btrfs subvolume list -t /mnt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To create a new subvolume at a specified location:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
btrfs subvolume create /mnt/nixos&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To remove an existing subvolume:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
btrfs subvolume delete /mnt/nixos&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Top level vs nested subvolumes ===&lt;br /&gt;
&lt;br /&gt;
In btrfs, subvolumes can be created either at the top level of the filesystem or within other subvolumes&lt;br /&gt;
&lt;br /&gt;
* Top level subvolumes are created directly under the filesystem&#039;s root. By default, the root volume id is 5. Top level subvolumes are easier to snapshotted, rolled back or destroyed independently. This is good for things such as &amp;lt;code&amp;gt;/home&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;/nix&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* Nested subvolumes are created inside an existing subvolume or directory within the filesystem. All nested subvolumes inherit the mount status of their parent unless mounted seperately. This layout is useful for organizing related subvolumes under a common namespace. For example, a top-level subvolume such as &amp;lt;code&amp;gt;/srv/nfs&amp;lt;/code&amp;gt; can contain multiple nested subvolumes like &amp;lt;code&amp;gt;/srv/nfs/export1&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;/srv/nfs/export2&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Snapshots ==&lt;br /&gt;
&lt;br /&gt;
A snapshot in btrfs is simply a subvolume that shares its data (and metadata) with some other subvolume, using btrfs&#039;s CoW capabilities. Because of that, there is no special location for snapshots and you can decide where you want to store them. It can be a simple directory inside the root subvolume, or a directory inside a dedicated &amp;quot;snapshots&amp;quot; subvolume.&lt;br /&gt;
&lt;br /&gt;
For this example we are going to store snapshots in a directory &amp;lt;code&amp;gt;/snapshots&amp;lt;/code&amp;gt;, that has to be created beforehand with &amp;lt;code&amp;gt;sudo mkdir /snapshots&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To take a read-only (&amp;lt;code&amp;gt;-r&amp;lt;/code&amp;gt;) snapshot called &amp;lt;code&amp;gt;home_snapshot_202302&amp;lt;/code&amp;gt; of the subvolume mounted at &amp;lt;code&amp;gt;/home&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
btrfs subvolume snapshot -r /home /snapshots/home_snapshot_202302&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also snapshot the root subvolume. But keep in mind that nested subvolumes are &#039;&#039;&#039;not&#039;&#039;&#039; part of a snapshot. So if you have subvolumes &amp;lt;code&amp;gt;/nix /home&amp;lt;/code&amp;gt;, taking a snapshot of &amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt; will not include them.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
btrfs subvolume snapshot -r / /snapshots/nixos_snapshot_202302&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make snapshot read-write againː&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
btrfs property set -ts /snapshots/home_snapshot_202302 ro false&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However, changing read-only property of a snapshot in-place may [//lore.kernel.org/linux-btrfs/06e92a0b-e71b-eb21-edb5-9d2a5513b718@gmail.com/ causes issues] with any future incremental send/receive. Instead, a read-only snapshot itself (being a simple subvolume) can be snapshotted again as a read-write snapshot like this:&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
btrfs subvolume snapshot /snapshots/home_snapshot_202302 /snapshots/home_snapshot_202302_rw&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or it can be restored directly to &amp;lt;code&amp;gt;/home&amp;lt;/code&amp;gt; straight away like this:&lt;br /&gt;
{{warning|1=this will delete the current &amp;lt;code&amp;gt;/home&amp;lt;/code&amp;gt; and restore the snapshot! &amp;lt;code&amp;gt;/home&amp;lt;/code&amp;gt; must be unmounted for this operation}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
btrfs subvolume delete /home&lt;br /&gt;
btrfs subvolume snapshot /snapshots/home_snapshot_202302 /home&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
After this you can mount &amp;lt;code&amp;gt;/home&amp;lt;/code&amp;gt; again.&lt;br /&gt;
&lt;br /&gt;
== Transfer snapshot ==&lt;br /&gt;
&lt;br /&gt;
Sending the snapshot &amp;lt;code&amp;gt;/snapshots/nixos_snapshot_202302&amp;lt;/code&amp;gt; compressed to a remote host via ssh at &amp;lt;code&amp;gt;root@192.168.178.110&amp;lt;/code&amp;gt; and saving it to a subvolume mounted on a directory at &amp;lt;code&amp;gt;/mnt/nixos&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo btrfs send /snapshots/nixos_snapshot_202302 | zstd | ssh root@192.168.178.110 &#039;zstd -d | btrfs receive /mnt/nixos&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If both the sender and receiver side have Btrfs with the same compression algorithm and level, you can instead use &amp;lt;code&amp;gt;send --compressed-data&amp;lt;/code&amp;gt; to avoid decompressing and recompressing the data.&lt;br /&gt;
&lt;br /&gt;
= Tips and tricks =&lt;br /&gt;
&lt;br /&gt;
== Backup ==&lt;br /&gt;
&lt;br /&gt;
[[Btrbk]] is a tool for creating snapshots and remote backups of btrfs subvolumes. &lt;br /&gt;
&lt;br /&gt;
== Installation with encryption ==&lt;br /&gt;
&lt;br /&gt;
Using [https://en.wikipedia.org/wiki/Linux_Unified_Key_Setup Luks2]:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
cryptsetup --verify-passphrase -v luksFormat &amp;quot;$DISK&amp;quot;p2 &lt;br /&gt;
&lt;br /&gt;
cryptsetup open &amp;quot;$DISK&amp;quot;p2 enc&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can use any device partition for your bootloader. Note that this bootloader is unencrypted by default:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;mkfs.vfat -n BOOT &amp;quot;$DISK&amp;quot;p1&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Creating subvolumes ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mkfs.btrfs /dev/mapper/enc # Creating btrfs partition&lt;br /&gt;
&lt;br /&gt;
mount -t btrfs /dev/mapper/enc /mnt&lt;br /&gt;
&lt;br /&gt;
# Create the subvolumes &lt;br /&gt;
&lt;br /&gt;
btrfs subvolume create /mnt/root # The subvolume for /&lt;br /&gt;
&lt;br /&gt;
btrfs subvolume create /mnt/home # The subvolume for /home, which should be backed up&lt;br /&gt;
&lt;br /&gt;
btrfs subvolume create /mnt/nix # The subvolume for /nix, which needs to be persistent but is not worth backing up, as it’s trivial to reconstruct&lt;br /&gt;
&lt;br /&gt;
btrfs subvolume create /mnt/log # The subvolume for /var/log.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unmount to mount on the subvolumes for the next steps:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;umount /mnt&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Once the subvolumes have been created, mount them with the desired options.&lt;br /&gt;
&lt;br /&gt;
Example with [https://facebook.github.io/zstd/ Zstandard compression] and noatime:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mount -o subvol=root,compress=zstd,noatime /dev/mapper/enc /mnt &lt;br /&gt;
&lt;br /&gt;
mkdir /mnt/home&lt;br /&gt;
&lt;br /&gt;
mount -o subvol=home,compress=zstd,noatime /dev/mapper/enc /mnt/home&lt;br /&gt;
&lt;br /&gt;
mkdir /mnt/nix&lt;br /&gt;
&lt;br /&gt;
mount -o subvol=nix,compress=zstd,noatime /dev/mapper/enc /mnt/nix&lt;br /&gt;
&lt;br /&gt;
mkdir -p /mnt/var/log&lt;br /&gt;
&lt;br /&gt;
mount -o subvol=log,compress=zstd,noatime /dev/mapper/enc /mnt/var/log&lt;br /&gt;
&lt;br /&gt;
# do not forget to create and mount the bootloader&lt;br /&gt;
&lt;br /&gt;
mkdir /mnt/boot&lt;br /&gt;
&lt;br /&gt;
mount &amp;quot;$DISK&amp;quot;p1 /mnt/boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Configure &amp;lt;code&amp;gt;hardware-configuration.nix&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight  lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
 # enable btrfs support&lt;br /&gt;
 boot.supportedFilesystems = [ &amp;quot;btrfs&amp;quot; ];&lt;br /&gt;
&lt;br /&gt;
 fileSystems.&amp;quot;/var/log&amp;quot; =&lt;br /&gt;
    { device = &amp;quot;/dev/disk/by-uuid/X&amp;quot;;&lt;br /&gt;
      fsType = &amp;quot;btrfs&amp;quot;;&lt;br /&gt;
      # enable noatime and zstd to the other subvolumes aswell&lt;br /&gt;
      options = [ &amp;quot;subvol=log&amp;quot; &amp;quot;compress=zstd&amp;quot; &amp;quot;noatime&amp;quot; ];&lt;br /&gt;
      # to have a correct log order&lt;br /&gt;
      neededForBoot = true;&lt;br /&gt;
    };&lt;br /&gt;
&amp;lt;/syntaxhighlight &amp;gt;&lt;br /&gt;
Generate Nixconfig:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
nixos-generate-config --root /mnt&lt;br /&gt;
&amp;lt;/syntaxhighlight &amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Convert Ext3/Ext4 system partition to Btrfs ==&lt;br /&gt;
&lt;br /&gt;
{{Warning|Note that migrating your existing root filesystem can cause data loss or make your system unbootable. Make sure to backup the partition or your files. Proceed only if you know what you&#039;re doing!}}&lt;br /&gt;
&lt;br /&gt;
To convert the existing filesystem (Ext3/4) to Btrfs, boot into a NixOS live system and run the following commandː&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot;&amp;gt;&lt;br /&gt;
fsck -f /dev/sdXY&lt;br /&gt;
btrfs-convert /dev/sdXY&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;Replace the device path with the target partition. Converting larger filesystems can take a long time.&lt;br /&gt;
&lt;br /&gt;
Next, mount the converted filesystem and chroot into itː&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot;&amp;gt;&lt;br /&gt;
mount /dev/sdXY /mnt&lt;br /&gt;
nixos-enter --root /mnt&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;Replace the partition UUID with the new one, which can be obtained using the command &amp;lt;code&amp;gt;blkid&amp;lt;/code&amp;gt;, in &amp;lt;code&amp;gt;/etc/nixos/hardware-configuration.nix&amp;lt;/code&amp;gt; and also change the filesystem to &amp;lt;code&amp;gt;btrfs&amp;lt;/code&amp;gt;.&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
  fileSystems.&amp;quot;/&amp;quot; =&lt;br /&gt;
    { device = &amp;quot;/dev/disk/by-uuid/44444444-4444-4444-8888-888888888888&amp;quot;;&lt;br /&gt;
      fsType = &amp;quot;btrfs&amp;quot;;&lt;br /&gt;
    };&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;Apply the changes&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot;&amp;gt;&lt;br /&gt;
nixos-rebuild boot&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;If the Grub bootloader is used and it doesn&#039;t get reinstalled correctly, you can run the following command inside chrootː&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot;&amp;gt;&lt;br /&gt;
grub-install /dev/sdX&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;If the conversion was successful and no rollback is required, the backup image which was stored by btrfs-convert can be removed withː&amp;lt;syntaxhighlight lang=&amp;quot;sh&amp;quot;&amp;gt;&lt;br /&gt;
btrfs subvolume delete /btrfs/ext2_saved&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== TRIM support ===&lt;br /&gt;
&lt;br /&gt;
{{main|Filesystems#SSD TRIM support}}&lt;br /&gt;
&lt;br /&gt;
Refer to [https://btrfs.readthedocs.io/en/latest/Trim.html btrfs docs] on how Trim works with btrfs through the &amp;lt;code&amp;gt;discard&amp;lt;/code&amp;gt; mount option.&lt;br /&gt;
&lt;br /&gt;
[[Category: Configuration]]&lt;br /&gt;
[[Category:Filesystem]]&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
	<entry>
		<id>https://wiki.nixos.org/w/index.php?title=Filesystems&amp;diff=22521</id>
		<title>Filesystems</title>
		<link rel="alternate" type="text/html" href="https://wiki.nixos.org/w/index.php?title=Filesystems&amp;diff=22521"/>
		<updated>2025-06-08T05:41:11Z</updated>

		<summary type="html">&lt;p&gt;Pigs: /* SSD TRIM support */ don&amp;#039;t mention filesystem specific mount options&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[category:filesystem]]&lt;br /&gt;
{{ic|fileSystems}} is a NixOS[[Category:NixOS]] option that allows the user to mount filesystems at specific mount points. The mounted filesystems may also be encrypted. Also see [https://nixos.org/manual/nixos/stable/options.html#opt-fileSystems the fileSystem option documentation].&lt;br /&gt;
&lt;br /&gt;
For boot mount options, [https://manpages.ubuntu.com/manpages/noble/en/man8/mount.8.html#filesystem-independent%20mount%20options check here].&lt;br /&gt;
&lt;br /&gt;
Common example filesystem mount. You can put this in configuration.nix:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
 fileSystems.&amp;quot;/mnt/exampleDrive&amp;quot; = {&lt;br /&gt;
   device = &amp;quot;/dev/disk/by-uuid/4f999afe-6114-4531-ba37-4bf4a00efd9e&amp;quot;;&lt;br /&gt;
   fsType = &amp;quot;exfat&amp;quot;;&lt;br /&gt;
   options = [ # If you don&#039;t have this options attribute, it&#039;ll default to &amp;quot;defaults&amp;quot; &lt;br /&gt;
     # boot options for fstab. Search up fstab mount options you can use&lt;br /&gt;
     &amp;quot;users&amp;quot; # Allows any user to mount and unmount&lt;br /&gt;
     &amp;quot;nofail&amp;quot; # Prevent system from failing if this drive doesn&#039;t mount&lt;br /&gt;
     &amp;quot;exec&amp;quot; # Permit execution of binaries and other executable files&lt;br /&gt;
   ];&lt;br /&gt;
 };&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Making disk visible in your file explorer ==&lt;br /&gt;
You might not see the disk in your file explorer (ie GNOME Nautilus). Add to the options: &amp;lt;code&amp;gt;x-gvfs-show&amp;lt;/code&amp;gt; and it&#039;ll show up.&lt;br /&gt;
&lt;br /&gt;
== Porting /etc/fstab ==&lt;br /&gt;
&lt;br /&gt;
The options specified in /etc/fstab may not be fully compatible with NixOS fileSystems options. For example, here are some options NixOS doesn&#039;t recognize that are available on some Linux distributions:&lt;br /&gt;
* iocharset&lt;br /&gt;
* rw (but it seems to not be needed)&lt;br /&gt;
* uid with username rather than actual uid&lt;br /&gt;
&lt;br /&gt;
== Mount order ==&lt;br /&gt;
&lt;br /&gt;
Without any specification, the mount order is up to the implementation (probably alphabetic).&lt;br /&gt;
&lt;br /&gt;
Should the order in which filesystems are mounted is important, users should make use of the [https://nixos.org/manual/nixos/stable/options.html#opt-fileSystems._name_.depends {{ic|fileSystems.&amp;lt;mount&amp;gt;.depends}} option]. This is useful for example in [[#Bind mounts]]&lt;br /&gt;
&lt;br /&gt;
== Bind mounts ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
Bind mounting allows a filesystem hierarchy or a file to be mounted at a different mount point. Unlike a symbolic link, a bind mount does not exist on the filesystem itself.&amp;lt;ref&amp;gt;[https://en.wikipedia.org/wiki/Mount_(Unix)#Bind_mounting Wikipedia - Bind mount]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are used to make files or folders available in other parts of the filesystem hierarchy. In order to do so both source and target filesystems have to be mounted first.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;nix&amp;quot;&amp;gt;&lt;br /&gt;
fileSystems.&amp;quot;/mnt/datastore&amp;quot;.label = &amp;quot;datastore&amp;quot;;&lt;br /&gt;
fileSystems.&amp;quot;/mnt/aggregator&amp;quot;.label = &amp;quot;aggregator&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
####################&lt;br /&gt;
# Bind mounts&lt;br /&gt;
&lt;br /&gt;
# Mount /mnt/datastore/applications/app1 on /mnt/aggregator/app1&lt;br /&gt;
# Accessing /mnt/aggregator/app1 will actually access /mnt/datastore/...&lt;br /&gt;
fileSystems.&amp;quot;/mnt/aggregator/app1&amp;quot; = {&lt;br /&gt;
  depends = [&lt;br /&gt;
      # The mounts above have to be mounted in this given order&lt;br /&gt;
      &amp;quot;/mnt/datastore&amp;quot; &lt;br /&gt;
      &amp;quot;/mnt/aggregator&amp;quot; &lt;br /&gt;
  ];&lt;br /&gt;
  device = &amp;quot;/mnt/datastore/applications/app1&amp;quot;;&lt;br /&gt;
  fsType = &amp;quot;none&amp;quot;;&lt;br /&gt;
  options = [&lt;br /&gt;
    &amp;quot;bind&amp;quot;&lt;br /&gt;
    &amp;quot;ro&amp;quot; # The filesystem hierarchy will be read-only when accessed from /mnt/aggregator/app1&lt;br /&gt;
  ];&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Tips and tricks ==&lt;br /&gt;
&lt;br /&gt;
=== SSD TRIM support ===&lt;br /&gt;
&lt;br /&gt;
On NixOS, [https://en.wikipedia.org/wiki/Trim_(computing) TRIM] support is enabled by default by the {{nixos:option|services.fstrim.enable}} option. This periodically discards unused blocks on supported storage devices, helping to maintain SSD performance over time.&lt;br /&gt;
&lt;br /&gt;
The trimming schedule is controlled by the {{nixos:option|services.fstrim.interval}} option. Continuous trimming (as set by the &amp;lt;code&amp;gt;discard&amp;lt;/code&amp;gt;, see &amp;lt;code&amp;gt;man mount(8)&amp;lt;/code&amp;gt;) mount option is not recommended as it can negatively impact SSD performance.&lt;br /&gt;
 &lt;br /&gt;
Additionally, setting &amp;lt;code&amp;gt;noatime&amp;lt;/code&amp;gt; can reduce the number of disk writes and can improve system performance.&lt;br /&gt;
&lt;br /&gt;
{{file|/etc/nixos/configuration.nix|nix|&lt;br /&gt;
&amp;lt;nowiki&amp;gt;&lt;br /&gt;
fileSystems.&amp;quot;/&amp;quot;.options = [ &amp;quot;noatime&amp;quot; ];&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pigs</name></author>
	</entry>
</feed>