mirror of
https://github.com/foo-dogsquared/wiki.git
synced 2025-01-31 01:57:54 +00:00
218 lines
54 KiB
HTML
218 lines
54 KiB
HTML
<!DOCTYPE html><html><head><meta name="viewport" content="width=device-width"/><meta charSet="utf-8"/><title>Nix flakes</title><script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script><script id="MathJax-script" async="" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script><script type="text/x-mathjax-config">
|
|
MathJax = {
|
|
tex: {
|
|
inlineMath: [ ['$','$'], ['\(','\)'] ],
|
|
displayMath: [ ['$$','$$'], ['[',']'] ]
|
|
},
|
|
options = {
|
|
processHtmlClass = "math"
|
|
}
|
|
}
|
|
</script><meta name="next-head-count" content="6"/><link rel="preload" href="/wiki/_next/static/css/52fc2ba29703df73922c.css" as="style"/><link rel="stylesheet" href="/wiki/_next/static/css/52fc2ba29703df73922c.css" data-n-g=""/><noscript data-n-css=""></noscript><link rel="preload" href="/wiki/_next/static/chunks/main-ae4733327bd95c4ac325.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/webpack-50bee04d1dc61f8adf5b.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/framework.9d524150d48315f49e80.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/commons.0e1c3f9aa780c2dfe9f0.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/pages/_app-8e3d0c58a60ec788aa69.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/940643274e605e7596ecea1f2ff8d83317a3fb76.4841a16762f602a59f00.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/pages/%5B%5B...slug%5D%5D-1aa198f87ede1cd0e1dc.js" as="script"/></head><body><div id="__next"><main><h1>Nix flakes</h1><section class="post-metadata"><span>Date: <!-- -->2021-07-18 22:34:11 +08:00</span><span>Date modified: <!-- -->2022-05-22 21:24:01 +08:00</span></section><nav class="toc"><ol class="toc-level toc-level-1"><li class="toc-item toc-item-h1"><a href="/wiki/tools.nix.flakes#exploring-a-nix-flake" class="toc-link toc-link-h1">Exploring a Nix flake</a></li><li class="toc-item toc-item-h1"><a href="/wiki/tools.nix.flakes#selected-list-of-attributes-for-outputs" class="toc-link toc-link-h1">Selected list of attributes for outputs</a></li><li class="toc-item toc-item-h1"><a href="/wiki/tools.nix.flakes#flake-templates" class="toc-link toc-link-h1">Flake templates</a></li><li class="toc-item toc-item-h1"><a href="/wiki/tools.nix.flakes#nix-registry" class="toc-link toc-link-h1">Nix registry</a></li><li class="toc-item toc-item-h1"><a href="/wiki/tools.nix.flakes#more-information-about-flakes" class="toc-link toc-link-h1">More information about flakes</a></li></ol></nav><div class="special-block block-note"><p>As of 2021-06-30, the version used for this note is at v2.3 so it needs to be invoked with the unstable version.
|
|
</p></div><p>What are Nix flakes?
|
|
</p><p>A self-contained Nix module that takes inputs (can be from other flakes) and create outputs.
|
|
It is comparable to <a href="https://guix.gnu.org/manual/en/html_node/Channels.html">Guix channels</a> (or the NUR) in the way any arbitrary value can be exported, thus extending a Nix module in any direction the author can make it to.
|
|
Also, it supercedes Nix channels as a way to manage your system.
|
|
</p><p>So, why use flakes?
|
|
</p><ul><li><p>Since it is self-contained, it is easier to compose and develop environments for projects.
|
|
</p></li><li><p>It is more declarative compared to Nix channels.
|
|
</p></li><li><p>Provides a structure for discoverability through exploring the output.
|
|
</p></li><li><p>In case you're using <a href="/wiki/linux.distros.nixos">NixOS</a>, it also provides an easier way to extend it with third-party custom modules.
|
|
</p></li></ul><h1 id="exploring-a-nix-flake">Exploring a Nix flake</h1><p>To get started with a flake, you can quickly create one with <code class="inline-verbatim">nix flake init</code>.
|
|
This will create <code class="inline-verbatim">flake.nix</code> which is also required for Nix to recognize the project as a flake.
|
|
</p><p>Here's the skeleton of a flake.
|
|
</p><pre class="src-block"><code class="language-nix">{
|
|
description = "A basic flake.";
|
|
inputs = {};
|
|
outputs = {};
|
|
}
|
|
</code></pre><p>It is really just an attribute set that mainly deals with three attributes:
|
|
</p><ul><li><p><code class="inline-verbatim">description</code> which is self-descriptive enough to see what's it for. ;p
|
|
</p></li><li><p><code class="inline-verbatim">inputs</code> which contains inputs (that are other flakes) to be used for...
|
|
</p></li><li><p>...the <code class="inline-verbatim">outputs</code> which is a set or a function that returns an attribute set to be exported.
|
|
</p></li></ul><p>Here's a real example of a basic flake.
|
|
</p><pre class="src-block"><code class="language-nix">{
|
|
description = "A basic flake with some real inputs this time.";
|
|
inputs = {
|
|
nixpkgs.url = "github:NixOS/nixpkgs";
|
|
|
|
home-manager.url = "github:nix-community/home-manager";
|
|
home-manager.inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
outputs = attrs@{ self, nixpkgs, home-manager, ... }: {
|
|
homeManagerConfiguration = import ./hmUsers;
|
|
packages.x86_64-linux = {
|
|
hello = nixpkgs.pkgs.hello;
|
|
};
|
|
};
|
|
}
|
|
</code></pre><p>The flake requires other flakes from the nixpkgs and home-manager as indicated from the URL.
|
|
This will get the latest revision of both inputs.
|
|
</p><p>This is not ideal as it will get the latest revisions every time it requests the inputs.
|
|
While you can pin the version by adding more information (e.g., <code class="inline-verbatim">nixpkgs.url = "github:NixOS/nixpkgs/nixos-21.11"</code>, <code class="inline-verbatim">home-manager.url = "github:nix-community/home-manager/781d25b315def05cd7ede3765226c54216f0b1fe"</code>), this isn't really necessary for the most part as we have lockfiles to secure our dependencies version.
|
|
These lockfiles can be found at <code class="inline-verbatim">flake.lock</code> where complete metadata for the flakes are found.
|
|
</p><h1 id="selected-list-of-attributes-for-outputs">Selected list of attributes for outputs</h1><p>While you can export attributes of any type, there are common attributes you'll mostly see.
|
|
</p><p>As an example, here's the flake of my NixOS configuration.
|
|
</p><pre class="src-block"><code class="language-shell">nix flake show github:foo-dogsquared/nixos-config | nix run nixpkgs#gnused -- 's/\x1b\[[0-9;]*m//g'
|
|
</code></pre><div class="exampe">github:foo-dogsquared/nixos-config/12077bfc601e5465e343e590a830e8d3cb6a1a59
|
|
├───devShells
|
|
│ ├───aarch64-darwin
|
|
│ │ ├───flatpak: development environment 'nix-shell'
|
|
│ │ ├───hugo: development environment 'nix-shell'
|
|
│ │ └───rust: development environment 'nix-shell'
|
|
│ ├───aarch64-linux
|
|
│ │ ├───flatpak: development environment 'nix-shell'
|
|
│ │ ├───hugo: development environment 'nix-shell'
|
|
│ │ └───rust: development environment 'nix-shell'
|
|
│ ├───i686-linux
|
|
│ │ ├───flatpak: development environment 'nix-shell'
|
|
│ │ ├───hugo: development environment 'nix-shell'
|
|
│ │ └───rust: development environment 'nix-shell'
|
|
│ ├───x86_64-darwin
|
|
│ │ ├───flatpak: development environment 'nix-shell'
|
|
│ │ ├───hugo: development environment 'nix-shell'
|
|
│ │ └───rust: development environment 'nix-shell'
|
|
│ └───x86_64-linux
|
|
│ ├───flatpak: development environment 'nix-shell'
|
|
│ ├───hugo: development environment 'nix-shell'
|
|
│ └───rust: development environment 'nix-shell'
|
|
├───homeManagerConfigurations: unknown
|
|
├───homeManagerModules: unknown
|
|
├───lib: unknown
|
|
├───nixosConfigurations
|
|
│ └───ni: NixOS configuration
|
|
├───nixosModules
|
|
│ ├───agenix: NixOS module
|
|
│ ├───archiving: NixOS module
|
|
│ ├───desktop: NixOS module
|
|
│ ├───dev: NixOS module
|
|
│ ├───hardware-setup: NixOS module
|
|
│ ├───themes: NixOS module
|
|
│ └───users: NixOS module
|
|
└───packages
|
|
├───aarch64-darwin
|
|
│ ├───doggo: package 'doggo-0.4.1'
|
|
│ ├───gnome-shell-extension-burn-my-windows: package 'gnome-shell-extension-burn-my-windows-2'
|
|
│ ├───gnome-shell-extension-desktop-cube: package 'gnome-shell-extension-desktop-cube-5'
|
|
│ ├───gnome-shell-extension-fly-pie: package 'gnome-shell-extension-fly-pie-12'
|
|
│ ├───gnome-shell-extension-pop-shell: package 'gnome-shell-extension-pop-shell-unstable-2021-11-30'
|
|
│ ├───libcs50: package 'libcs50-10.1.1'
|
|
│ ├───llama: package 'llama-1.0.2'
|
|
│ ├───neo: package 'neo-0.6'
|
|
│ ├───pop-launcher: package 'pop-launcher-1.1.0'
|
|
│ ├───pop-launcher-plugin-duckduckgo-bangs: package 'pop-launcher-plugin-duckduckgo-bangs-1.3.0'
|
|
│ ├───sioyek: package 'sioyek-1.0.0'
|
|
│ └───tic-80: package 'tic-80-unstable-2021-12-18'
|
|
├───aarch64-linux
|
|
│ ├───doggo: package 'doggo-0.4.1'
|
|
│ ├───gnome-shell-extension-burn-my-windows: package 'gnome-shell-extension-burn-my-windows-2'
|
|
│ ├───gnome-shell-extension-desktop-cube: package 'gnome-shell-extension-desktop-cube-5'
|
|
│ ├───gnome-shell-extension-fly-pie: package 'gnome-shell-extension-fly-pie-12'
|
|
│ ├───gnome-shell-extension-pop-shell: package 'gnome-shell-extension-pop-shell-unstable-2021-11-30'
|
|
│ ├───libcs50: package 'libcs50-10.1.1'
|
|
│ ├───llama: package 'llama-1.0.2'
|
|
│ ├───neo: package 'neo-0.6'
|
|
│ ├───pop-launcher: package 'pop-launcher-1.1.0'
|
|
│ ├───pop-launcher-plugin-duckduckgo-bangs: package 'pop-launcher-plugin-duckduckgo-bangs-1.3.0'
|
|
│ ├───sioyek: package 'sioyek-1.0.0'
|
|
│ └───tic-80: package 'tic-80-unstable-2021-12-18'
|
|
├───i686-linux
|
|
│ ├───doggo: package 'doggo-0.4.1'
|
|
│ ├───gnome-shell-extension-burn-my-windows: package 'gnome-shell-extension-burn-my-windows-2'
|
|
│ ├───gnome-shell-extension-desktop-cube: package 'gnome-shell-extension-desktop-cube-5'
|
|
│ ├───gnome-shell-extension-fly-pie: package 'gnome-shell-extension-fly-pie-12'
|
|
│ ├───gnome-shell-extension-pop-shell: package 'gnome-shell-extension-pop-shell-unstable-2021-11-30'
|
|
│ ├───libcs50: package 'libcs50-10.1.1'
|
|
│ ├───llama: package 'llama-1.0.2'
|
|
│ ├───neo: package 'neo-0.6'
|
|
│ ├───pop-launcher: package 'pop-launcher-1.1.0'
|
|
│ ├───pop-launcher-plugin-duckduckgo-bangs: package 'pop-launcher-plugin-duckduckgo-bangs-1.3.0'
|
|
│ ├───sioyek: package 'sioyek-1.0.0'
|
|
│ └───tic-80: package 'tic-80-unstable-2021-12-18'
|
|
├───x86_64-darwin
|
|
│ ├───doggo: package 'doggo-0.4.1'
|
|
│ ├───gnome-shell-extension-burn-my-windows: package 'gnome-shell-extension-burn-my-windows-2'
|
|
│ ├───gnome-shell-extension-desktop-cube: package 'gnome-shell-extension-desktop-cube-5'
|
|
│ ├───gnome-shell-extension-fly-pie: package 'gnome-shell-extension-fly-pie-12'
|
|
│ ├───gnome-shell-extension-pop-shell: package 'gnome-shell-extension-pop-shell-unstable-2021-11-30'
|
|
│ ├───libcs50: package 'libcs50-10.1.1'
|
|
│ ├───llama: package 'llama-1.0.2'
|
|
│ ├───neo: package 'neo-0.6'
|
|
│ ├───pop-launcher: package 'pop-launcher-1.1.0'
|
|
│ ├───pop-launcher-plugin-duckduckgo-bangs: package 'pop-launcher-plugin-duckduckgo-bangs-1.3.0'
|
|
│ ├───sioyek: package 'sioyek-1.0.0'
|
|
│ └───tic-80: package 'tic-80-unstable-2021-12-18'
|
|
└───x86_64-linux
|
|
├───doggo: package 'doggo-0.4.1'
|
|
├───gnome-shell-extension-burn-my-windows: package 'gnome-shell-extension-burn-my-windows-2'
|
|
├───gnome-shell-extension-desktop-cube: package 'gnome-shell-extension-desktop-cube-5'
|
|
├───gnome-shell-extension-fly-pie: package 'gnome-shell-extension-fly-pie-12'
|
|
├───gnome-shell-extension-pop-shell: package 'gnome-shell-extension-pop-shell-unstable-2021-11-30'
|
|
├───libcs50: package 'libcs50-10.1.1'
|
|
├───llama: package 'llama-1.0.2'
|
|
├───neo: package 'neo-0.6'
|
|
├───pop-launcher: package 'pop-launcher-1.1.0'
|
|
├───pop-launcher-plugin-duckduckgo-bangs: package 'pop-launcher-plugin-duckduckgo-bangs-1.3.0'
|
|
├───sioyek: package 'sioyek-1.0.0'
|
|
└───tic-80: package 'tic-80-unstable-2021-12-18'
|
|
</div><ul><li><p><code class="inline-verbatim">defaultPackage.${system}.${package}</code> (or <code class="inline-verbatim">packages.${system}.${package}</code>) is mainly expected for packages.
|
|
This allows for easy building — e.g., <code class="inline-verbatim">nix build nixpkgs#hello</code> will refer to <code class="inline-verbatim">defaultPackage.${system}.hello</code>.
|
|
Another command that expects this is <code class="inline-verbatim">nix run ${PACKAGE}</code> (e.g., <code class="inline-verbatim">nix run nixpkgs#hello</code>).
|
|
</p></li><li><p><code class="inline-verbatim">nixosConfigurations.${host}</code> is a NixOS host configuration.
|
|
Each attribute contain a set similar to the traditional set from <code class="inline-verbatim">/etc/nixos/configuration.nix</code>.
|
|
This is very beneficial for quickly installing only with flakes — e.g., <code class="inline-verbatim">nixos-install --flake github:foo-dogsquared/nixos-config#zilch</code> will install with <code class="inline-verbatim">nixosConfigurations.zilch</code>.
|
|
However, attributes should be created with <code class="inline-verbatim">lib.nixosSystem</code> from <code class="inline-verbatim">nixpkgs</code> flake.
|
|
</p></li><li><p><code class="inline-verbatim">nixosModules.${module}</code> is a <a href="roam:NixOS modules">roam:NixOS modules</a>, allowing you to extend NixOS further.
|
|
These are expected to be similar NixOS modules from nixpkgs.
|
|
</p></li><li><p><code class="inline-verbatim">templates.${name}</code> is a template that has the attribute <code class="inline-verbatim">path</code> and <code class="inline-verbatim">description</code>.
|
|
See <a href="/wiki/Flake%20templates">Flake templates</a> for more details about how it's used.
|
|
</p></li><li><p><code class="inline-verbatim">devShell.${system}</code> is expected to be a derivation (mostly with <code class="inline-verbatim">mkShell</code>).
|
|
This is the default development environment to be used.
|
|
This is mostly expected for projects providing an easy way to bootstrap for development (e.g., with <code class="inline-verbatim">nix develop ${FLAKE}</code>).
|
|
</p></li><li><p><code class="inline-verbatim">devShells.${system}.${name}</code> is an attribute set of derivations (mostly from <code class="inline-verbatim">mkShell</code>).
|
|
This is similar to <code class="inline-verbatim">devShell</code> except this is where <code class="inline-verbatim">nix develop</code> subcommand finds if an attribute name is given.
|
|
</p></li></ul><h1 id="flake-templates">Flake templates</h1><ul><li><p>Flakes can have templates to get started with.
|
|
They can be used with <code class="inline-verbatim">nix flake init ${TEMPLATE}</code>.
|
|
</p></li><li><p>You can export it in your flakes through the <code class="inline-verbatim">templates</code> attribute.
|
|
<code class="inline-verbatim">templates</code> is expected to be an attribute set with each attribute representing a template.
|
|
</p></li><li><p>By default, we have the <code class="inline-verbatim">templates</code> flake from the global registry pointed to <a href="https://github.com/NixOS/templates">NixOS/templates</a> Git repo.
|
|
</p></li></ul><h1 id="nix-registry">Nix registry</h1><p>Per the Nix manual:
|
|
</p><blockquote><p>Flake registries are a convenience feature that allows you to refer to flakes using symbolic identifiers such as <code class="inline-verbatim">nixpkgs</code>, rather than full URLs such as <code class="inline-verbatim">git://github.com/NixOS/nixpkgs</code>.
|
|
</p></blockquote><p>Here's an example of the registry list with some overriden flakes such as the <code class="inline-verbatim">nixpkgs</code> flake following from my <a href="https://github.com/foo-dogsquared/nixos-config">NixOS configuration</a>.
|
|
</p><pre class="src-block"><code class="language-shell">nix registry list
|
|
</code></pre><div class="exampe">system flake:agenix path:/nix/store/yka795vkb7ny5fnybf8dafbypcjfmi9n-source?lastModified=1638837456&narHash=sha256-WHLOxthAGx%2fwXw3QUa%2flFE3mr6cQtnXfFYZ0DNyYwt4=&rev=57806bf7e340f4cae705c91748d4fdf8519293a9
|
|
system flake:config path:/nix/store/3nlagaj6748w4ffxx4vp5jss2k571f8i-source?lastModified=1640442672&narHash=sha256-Gkt2On9szrFlOo6QiYMOA90qTp4PICd7STHFhGA4bCs=
|
|
system flake:home-manager path:/nix/store/ijh6v700kpssfyw44v4awbm2gmjx26qs-source?lastModified=1640296831&narHash=sha256-Mu32vTcfZru4VrvgnpvQKmwC4uY0oF3vnnC2o9SgnRU=&rev=f15b151ca1c4aea23515c241051d71f1b5cf97c8
|
|
system flake:nixpkgs path:/nix/store/lgfhg4n6445yizgf0xjirb4bc4j86fr9-source?lastModified=1640269308&narHash=sha256-vBVwv3+kPrxbNyfo48cB5cc5%2f4tq5zlJGas%2fqw8XNBE=&rev=0c408a087b4751c887e463e3848512c12017be25
|
|
global flake:agda github:agda/agda
|
|
global flake:blender-bin github:edolstra/nix-warez?dir=blender
|
|
global flake:dreampkgs github:nix-community/dreampkgs
|
|
global flake:dwarffs github:edolstra/dwarffs
|
|
global flake:fenix github:nix-community/fenix
|
|
global flake:flake-utils github:flake-utils/numtide
|
|
global flake:gemini github:nix-community/flake-gemini
|
|
global flake:home-manager github:nix-community/home-manager
|
|
global flake:hydra github:NixOS/hydra
|
|
global flake:mach-nix github:DavHau/mach-nix
|
|
global flake:nimble github:nix-community/flake-nimble
|
|
global flake:nix github:NixOS/nix
|
|
global flake:nixops github:NixOS/nixops
|
|
global flake:nixos-hardware github:NixOS/nixos-hardware
|
|
global flake:nixos-homepage github:NixOS/nixos-homepage/flake
|
|
global flake:nur github:nix-community/NUR
|
|
global flake:nixpkgs github:NixOS/nixpkgs/nixpkgs-unstable
|
|
global flake:templates github:NixOS/templates
|
|
global flake:patchelf github:NixOS/patchelf
|
|
global flake:nix-serve github:edolstra/nix-serve
|
|
global flake:nickel github:tweag/nickel
|
|
</div><p>So how does a flake registry work?
|
|
</p><ul><li><p>It is managed through <code class="inline-verbatim">nix registry</code> subcommand or set <code class="inline-verbatim">nix.registry</code> in your system configuration.
|
|
</p></li><li><p>Registries are primarily written as JSON files in certain files (e.g., <code class="inline-verbatim">$XDG_CONFIG_HOME/nix/registry</code>, <code class="inline-verbatim">/etc/nix/registry.json</code>).
|
|
For more information, see the <a href="https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-registry.html#registry-format">registry format from the manual</a>.
|
|
Unlike the traditional Nix channels, the inclusion of arbitrary files and their locations doesn't seem to affect the reproducibility since it is mostly used as a convenience feature after all.
|
|
</p></li><li><p>The flakes from default registry are mostly getting the latest revisions of the flake per invocation so it is best practice to pin them (e.g., <code class="inline-verbatim">nix registry pin</code>, through <code class="inline-verbatim">nix.registry</code> while setting the NixOS systems in <code class="inline-verbatim">flake.nix</code>).
|
|
</p></li><li><p>There are primarily three registries to worry about: user, system, and global.
|
|
</p></li><li><p>This is also the reason it downloads something why each time you invoke a Nix-related command (e.g., <code class="inline-verbatim">nix search</code>, <code class="inline-verbatim">nix edit</code>).
|
|
</p></li></ul><h1 id="more-information-about-flakes">More information about flakes</h1><ul><li><p>We can modify our inputs.
|
|
In the above example, we made <code class="inline-verbatim">home-manager</code> to use our version of <code class="inline-verbatim">nixpkgs</code> which will make it easier to sync.
|
|
</p></li></ul><section><h2>Backlinks</h2><ul><li><a href="/wiki/packages.nix">Nix packages</a></li><li><a href="/wiki/tools.nix">Nix package manager</a></li></ul></section></main></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{"metadata":{"date":"2021-07-18 22:34:11 +08:00","date_modified":"2022-05-22 21:24:01 +08:00","language":"en","source":""},"title":"Nix flakes","hast":{"type":"root","children":[{"type":"element","tagName":"nav","properties":{"className":"toc"},"children":[{"type":"element","tagName":"ol","properties":{"className":"toc-level toc-level-1"},"children":[{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h1","properties":{"id":"exploring-a-nix-flake"},"children":[{"type":"text","value":"Exploring a Nix flake"}]}]},"properties":{"className":"toc-item toc-item-h1"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h1","href":"/tools.nix.flakes#exploring-a-nix-flake"},"children":[{"type":"text","value":"Exploring a Nix flake"}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h1","properties":{"id":"selected-list-of-attributes-for-outputs"},"children":[{"type":"text","value":"Selected list of attributes for outputs"}]}]},"properties":{"className":"toc-item toc-item-h1"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h1","href":"/tools.nix.flakes#selected-list-of-attributes-for-outputs"},"children":[{"type":"text","value":"Selected list of attributes for outputs"}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h1","properties":{"id":"flake-templates"},"children":[{"type":"text","value":"Flake templates"}]}]},"properties":{"className":"toc-item toc-item-h1"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h1","href":"/tools.nix.flakes#flake-templates"},"children":[{"type":"text","value":"Flake templates"}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h1","properties":{"id":"nix-registry"},"children":[{"type":"text","value":"Nix registry"}]}]},"properties":{"className":"toc-item toc-item-h1"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h1","href":"/tools.nix.flakes#nix-registry"},"children":[{"type":"text","value":"Nix registry"}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h1","properties":{"id":"more-information-about-flakes"},"children":[{"type":"text","value":"More information about flakes"}]}]},"properties":{"className":"toc-item toc-item-h1"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h1","href":"/tools.nix.flakes#more-information-about-flakes"},"children":[{"type":"text","value":"More information about flakes"}]}]}]}]},{"type":"element","tagName":"div","properties":{"className":["special-block","block-note"]},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"As of 2021-06-30, the version used for this note is at v2.3 so it needs to be invoked with the unstable version.\n"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"What are Nix flakes?\n"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"A self-contained Nix module that takes inputs (can be from other flakes) and create outputs.\nIt is comparable to "},{"type":"element","tagName":"a","properties":{"href":"https://guix.gnu.org/manual/en/html_node/Channels.html"},"children":[{"type":"text","value":"Guix channels"}]},{"type":"text","value":" (or the NUR) in the way any arbitrary value can be exported, thus extending a Nix module in any direction the author can make it to.\nAlso, it supercedes Nix channels as a way to manage your system.\n"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"So, why use flakes?\n"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Since it is self-contained, it is easier to compose and develop environments for projects.\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"It is more declarative compared to Nix channels.\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Provides a structure for discoverability through exploring the output.\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"In case you're using "},{"type":"element","tagName":"a","properties":{"href":"/linux.distros.nixos"},"children":[{"type":"text","value":"NixOS"}]},{"type":"text","value":", it also provides an easier way to extend it with third-party custom modules.\n"}]}]}]},{"type":"element","tagName":"h1","properties":{"id":"exploring-a-nix-flake"},"children":[{"type":"text","value":"Exploring a Nix flake"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"To get started with a flake, you can quickly create one with "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"nix flake init"}]},{"type":"text","value":".\nThis will create "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"flake.nix"}]},{"type":"text","value":" which is also required for Nix to recognize the project as a flake.\n"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Here's the skeleton of a flake.\n"}]},{"type":"element","tagName":"pre","properties":{"className":["src-block"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-nix"]},"children":[{"type":"text","value":"{\n description = \"A basic flake.\";\n inputs = {};\n outputs = {};\n}\n"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"It is really just an attribute set that mainly deals with three attributes:\n"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"description"}]},{"type":"text","value":" which is self-descriptive enough to see what's it for. ;p\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"inputs"}]},{"type":"text","value":" which contains inputs (that are other flakes) to be used for...\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"...the "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"outputs"}]},{"type":"text","value":" which is a set or a function that returns an attribute set to be exported.\n"}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Here's a real example of a basic flake.\n"}]},{"type":"element","tagName":"pre","properties":{"className":["src-block"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-nix"]},"children":[{"type":"text","value":"{\n description = \"A basic flake with some real inputs this time.\";\n inputs = {\n nixpkgs.url = \"github:NixOS/nixpkgs\";\n\n home-manager.url = \"github:nix-community/home-manager\";\n home-manager.inputs.nixpkgs.follows = \"nixpkgs\";\n };\n outputs = attrs@{ self, nixpkgs, home-manager, ... }: {\n homeManagerConfiguration = import ./hmUsers;\n packages.x86_64-linux = {\n hello = nixpkgs.pkgs.hello;\n };\n };\n}\n"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"The flake requires other flakes from the nixpkgs and home-manager as indicated from the URL.\nThis will get the latest revision of both inputs.\n"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"This is not ideal as it will get the latest revisions every time it requests the inputs.\nWhile you can pin the version by adding more information (e.g., "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"nixpkgs.url = \"github:NixOS/nixpkgs/nixos-21.11\""}]},{"type":"text","value":", "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"home-manager.url = \"github:nix-community/home-manager/781d25b315def05cd7ede3765226c54216f0b1fe\""}]},{"type":"text","value":"), this isn't really necessary for the most part as we have lockfiles to secure our dependencies version.\nThese lockfiles can be found at "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"flake.lock"}]},{"type":"text","value":" where complete metadata for the flakes are found.\n"}]},{"type":"element","tagName":"h1","properties":{"id":"selected-list-of-attributes-for-outputs"},"children":[{"type":"text","value":"Selected list of attributes for outputs"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"While you can export attributes of any type, there are common attributes you'll mostly see.\n"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"As an example, here's the flake of my NixOS configuration.\n"}]},{"type":"element","tagName":"pre","properties":{"className":["src-block"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-shell"]},"children":[{"type":"text","value":"nix flake show github:foo-dogsquared/nixos-config | nix run nixpkgs#gnused -- 's/\\x1b\\[[0-9;]*m//g'\n"}]}]},{"type":"element","tagName":"div","properties":{"className":["exampe"]},"children":[{"type":"text","value":"github:foo-dogsquared/nixos-config/12077bfc601e5465e343e590a830e8d3cb6a1a59\n├───devShells\n│ ├───aarch64-darwin\n│ │ ├───flatpak: development environment 'nix-shell'\n│ │ ├───hugo: development environment 'nix-shell'\n│ │ └───rust: development environment 'nix-shell'\n│ ├───aarch64-linux\n│ │ ├───flatpak: development environment 'nix-shell'\n│ │ ├───hugo: development environment 'nix-shell'\n│ │ └───rust: development environment 'nix-shell'\n│ ├───i686-linux\n│ │ ├───flatpak: development environment 'nix-shell'\n│ │ ├───hugo: development environment 'nix-shell'\n│ │ └───rust: development environment 'nix-shell'\n│ ├───x86_64-darwin\n│ │ ├───flatpak: development environment 'nix-shell'\n│ │ ├───hugo: development environment 'nix-shell'\n│ │ └───rust: development environment 'nix-shell'\n│ └───x86_64-linux\n│ ├───flatpak: development environment 'nix-shell'\n│ ├───hugo: development environment 'nix-shell'\n│ └───rust: development environment 'nix-shell'\n├───homeManagerConfigurations: unknown\n├───homeManagerModules: unknown\n├───lib: unknown\n├───nixosConfigurations\n│ └───ni: NixOS configuration\n├───nixosModules\n│ ├───agenix: NixOS module\n│ ├───archiving: NixOS module\n│ ├───desktop: NixOS module\n│ ├───dev: NixOS module\n│ ├───hardware-setup: NixOS module\n│ ├───themes: NixOS module\n│ └───users: NixOS module\n└───packages\n ├───aarch64-darwin\n │ ├───doggo: package 'doggo-0.4.1'\n │ ├───gnome-shell-extension-burn-my-windows: package 'gnome-shell-extension-burn-my-windows-2'\n │ ├───gnome-shell-extension-desktop-cube: package 'gnome-shell-extension-desktop-cube-5'\n │ ├───gnome-shell-extension-fly-pie: package 'gnome-shell-extension-fly-pie-12'\n │ ├───gnome-shell-extension-pop-shell: package 'gnome-shell-extension-pop-shell-unstable-2021-11-30'\n │ ├───libcs50: package 'libcs50-10.1.1'\n │ ├───llama: package 'llama-1.0.2'\n │ ├───neo: package 'neo-0.6'\n │ ├───pop-launcher: package 'pop-launcher-1.1.0'\n │ ├───pop-launcher-plugin-duckduckgo-bangs: package 'pop-launcher-plugin-duckduckgo-bangs-1.3.0'\n │ ├───sioyek: package 'sioyek-1.0.0'\n │ └───tic-80: package 'tic-80-unstable-2021-12-18'\n ├───aarch64-linux\n │ ├───doggo: package 'doggo-0.4.1'\n │ ├───gnome-shell-extension-burn-my-windows: package 'gnome-shell-extension-burn-my-windows-2'\n │ ├───gnome-shell-extension-desktop-cube: package 'gnome-shell-extension-desktop-cube-5'\n │ ├───gnome-shell-extension-fly-pie: package 'gnome-shell-extension-fly-pie-12'\n │ ├───gnome-shell-extension-pop-shell: package 'gnome-shell-extension-pop-shell-unstable-2021-11-30'\n │ ├───libcs50: package 'libcs50-10.1.1'\n │ ├───llama: package 'llama-1.0.2'\n │ ├───neo: package 'neo-0.6'\n │ ├───pop-launcher: package 'pop-launcher-1.1.0'\n │ ├───pop-launcher-plugin-duckduckgo-bangs: package 'pop-launcher-plugin-duckduckgo-bangs-1.3.0'\n │ ├───sioyek: package 'sioyek-1.0.0'\n │ └───tic-80: package 'tic-80-unstable-2021-12-18'\n ├───i686-linux\n │ ├───doggo: package 'doggo-0.4.1'\n │ ├───gnome-shell-extension-burn-my-windows: package 'gnome-shell-extension-burn-my-windows-2'\n │ ├───gnome-shell-extension-desktop-cube: package 'gnome-shell-extension-desktop-cube-5'\n │ ├───gnome-shell-extension-fly-pie: package 'gnome-shell-extension-fly-pie-12'\n │ ├───gnome-shell-extension-pop-shell: package 'gnome-shell-extension-pop-shell-unstable-2021-11-30'\n │ ├───libcs50: package 'libcs50-10.1.1'\n │ ├───llama: package 'llama-1.0.2'\n │ ├───neo: package 'neo-0.6'\n │ ├───pop-launcher: package 'pop-launcher-1.1.0'\n │ ├───pop-launcher-plugin-duckduckgo-bangs: package 'pop-launcher-plugin-duckduckgo-bangs-1.3.0'\n │ ├───sioyek: package 'sioyek-1.0.0'\n │ └───tic-80: package 'tic-80-unstable-2021-12-18'\n ├───x86_64-darwin\n │ ├───doggo: package 'doggo-0.4.1'\n │ ├───gnome-shell-extension-burn-my-windows: package 'gnome-shell-extension-burn-my-windows-2'\n │ ├───gnome-shell-extension-desktop-cube: package 'gnome-shell-extension-desktop-cube-5'\n │ ├───gnome-shell-extension-fly-pie: package 'gnome-shell-extension-fly-pie-12'\n │ ├───gnome-shell-extension-pop-shell: package 'gnome-shell-extension-pop-shell-unstable-2021-11-30'\n │ ├───libcs50: package 'libcs50-10.1.1'\n │ ├───llama: package 'llama-1.0.2'\n │ ├───neo: package 'neo-0.6'\n │ ├───pop-launcher: package 'pop-launcher-1.1.0'\n │ ├───pop-launcher-plugin-duckduckgo-bangs: package 'pop-launcher-plugin-duckduckgo-bangs-1.3.0'\n │ ├───sioyek: package 'sioyek-1.0.0'\n │ └───tic-80: package 'tic-80-unstable-2021-12-18'\n └───x86_64-linux\n ├───doggo: package 'doggo-0.4.1'\n ├───gnome-shell-extension-burn-my-windows: package 'gnome-shell-extension-burn-my-windows-2'\n ├───gnome-shell-extension-desktop-cube: package 'gnome-shell-extension-desktop-cube-5'\n ├───gnome-shell-extension-fly-pie: package 'gnome-shell-extension-fly-pie-12'\n ├───gnome-shell-extension-pop-shell: package 'gnome-shell-extension-pop-shell-unstable-2021-11-30'\n ├───libcs50: package 'libcs50-10.1.1'\n ├───llama: package 'llama-1.0.2'\n ├───neo: package 'neo-0.6'\n ├───pop-launcher: package 'pop-launcher-1.1.0'\n ├───pop-launcher-plugin-duckduckgo-bangs: package 'pop-launcher-plugin-duckduckgo-bangs-1.3.0'\n ├───sioyek: package 'sioyek-1.0.0'\n └───tic-80: package 'tic-80-unstable-2021-12-18'\n"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"defaultPackage.${system}.${package}"}]},{"type":"text","value":" (or "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"packages.${system}.${package}"}]},{"type":"text","value":") is mainly expected for packages.\n This allows for easy building — e.g., "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"nix build nixpkgs#hello"}]},{"type":"text","value":" will refer to "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"defaultPackage.${system}.hello"}]},{"type":"text","value":".\n Another command that expects this is "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"nix run ${PACKAGE}"}]},{"type":"text","value":" (e.g., "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"nix run nixpkgs#hello"}]},{"type":"text","value":").\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"nixosConfigurations.${host}"}]},{"type":"text","value":" is a NixOS host configuration.\n Each attribute contain a set similar to the traditional set from "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"/etc/nixos/configuration.nix"}]},{"type":"text","value":".\n This is very beneficial for quickly installing only with flakes — e.g., "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"nixos-install --flake github:foo-dogsquared/nixos-config#zilch"}]},{"type":"text","value":" will install with "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"nixosConfigurations.zilch"}]},{"type":"text","value":".\n However, attributes should be created with "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"lib.nixosSystem"}]},{"type":"text","value":" from "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"nixpkgs"}]},{"type":"text","value":" flake.\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"nixosModules.${module}"}]},{"type":"text","value":" is a "},{"type":"element","tagName":"a","properties":{"href":"roam:NixOS modules"},"children":[{"type":"text","value":"roam:NixOS modules"}]},{"type":"text","value":", allowing you to extend NixOS further.\n These are expected to be similar NixOS modules from nixpkgs.\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"templates.${name}"}]},{"type":"text","value":" is a template that has the attribute "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"path"}]},{"type":"text","value":" and "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"description"}]},{"type":"text","value":".\n See "},{"type":"element","tagName":"a","properties":{"href":"/Flake%20templates"},"children":[{"type":"text","value":"Flake templates"}]},{"type":"text","value":" for more details about how it's used.\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"devShell.${system}"}]},{"type":"text","value":" is expected to be a derivation (mostly with "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"mkShell"}]},{"type":"text","value":").\n This is the default development environment to be used.\n This is mostly expected for projects providing an easy way to bootstrap for development (e.g., with "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"nix develop ${FLAKE}"}]},{"type":"text","value":").\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"devShells.${system}.${name}"}]},{"type":"text","value":" is an attribute set of derivations (mostly from "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"mkShell"}]},{"type":"text","value":").\n This is similar to "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"devShell"}]},{"type":"text","value":" except this is where "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"nix develop"}]},{"type":"text","value":" subcommand finds if an attribute name is given.\n"}]}]}]},{"type":"element","tagName":"h1","properties":{"id":"flake-templates"},"children":[{"type":"text","value":"Flake templates"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Flakes can have templates to get started with.\n They can be used with "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"nix flake init ${TEMPLATE}"}]},{"type":"text","value":".\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"You can export it in your flakes through the "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"templates"}]},{"type":"text","value":" attribute.\n "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"templates"}]},{"type":"text","value":" is expected to be an attribute set with each attribute representing a template.\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"By default, we have the "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"templates"}]},{"type":"text","value":" flake from the global registry pointed to "},{"type":"element","tagName":"a","properties":{"href":"https://github.com/NixOS/templates"},"children":[{"type":"text","value":"NixOS/templates"}]},{"type":"text","value":" Git repo.\n"}]}]}]},{"type":"element","tagName":"h1","properties":{"id":"nix-registry"},"children":[{"type":"text","value":"Nix registry"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Per the Nix manual:\n"}]},{"type":"element","tagName":"blockquote","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Flake registries are a convenience feature that allows you to refer to flakes using symbolic identifiers such as "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"nixpkgs"}]},{"type":"text","value":", rather than full URLs such as "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"git://github.com/NixOS/nixpkgs"}]},{"type":"text","value":".\n"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Here's an example of the registry list with some overriden flakes such as the "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"nixpkgs"}]},{"type":"text","value":" flake following from my "},{"type":"element","tagName":"a","properties":{"href":"https://github.com/foo-dogsquared/nixos-config"},"children":[{"type":"text","value":"NixOS configuration"}]},{"type":"text","value":".\n"}]},{"type":"element","tagName":"pre","properties":{"className":["src-block"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-shell"]},"children":[{"type":"text","value":"nix registry list\n"}]}]},{"type":"element","tagName":"div","properties":{"className":["exampe"]},"children":[{"type":"text","value":"system flake:agenix path:/nix/store/yka795vkb7ny5fnybf8dafbypcjfmi9n-source?lastModified=1638837456\u0026narHash=sha256-WHLOxthAGx%2fwXw3QUa%2flFE3mr6cQtnXfFYZ0DNyYwt4=\u0026rev=57806bf7e340f4cae705c91748d4fdf8519293a9\nsystem flake:config path:/nix/store/3nlagaj6748w4ffxx4vp5jss2k571f8i-source?lastModified=1640442672\u0026narHash=sha256-Gkt2On9szrFlOo6QiYMOA90qTp4PICd7STHFhGA4bCs=\nsystem flake:home-manager path:/nix/store/ijh6v700kpssfyw44v4awbm2gmjx26qs-source?lastModified=1640296831\u0026narHash=sha256-Mu32vTcfZru4VrvgnpvQKmwC4uY0oF3vnnC2o9SgnRU=\u0026rev=f15b151ca1c4aea23515c241051d71f1b5cf97c8\nsystem flake:nixpkgs path:/nix/store/lgfhg4n6445yizgf0xjirb4bc4j86fr9-source?lastModified=1640269308\u0026narHash=sha256-vBVwv3+kPrxbNyfo48cB5cc5%2f4tq5zlJGas%2fqw8XNBE=\u0026rev=0c408a087b4751c887e463e3848512c12017be25\nglobal flake:agda github:agda/agda\nglobal flake:blender-bin github:edolstra/nix-warez?dir=blender\nglobal flake:dreampkgs github:nix-community/dreampkgs\nglobal flake:dwarffs github:edolstra/dwarffs\nglobal flake:fenix github:nix-community/fenix\nglobal flake:flake-utils github:flake-utils/numtide\nglobal flake:gemini github:nix-community/flake-gemini\nglobal flake:home-manager github:nix-community/home-manager\nglobal flake:hydra github:NixOS/hydra\nglobal flake:mach-nix github:DavHau/mach-nix\nglobal flake:nimble github:nix-community/flake-nimble\nglobal flake:nix github:NixOS/nix\nglobal flake:nixops github:NixOS/nixops\nglobal flake:nixos-hardware github:NixOS/nixos-hardware\nglobal flake:nixos-homepage github:NixOS/nixos-homepage/flake\nglobal flake:nur github:nix-community/NUR\nglobal flake:nixpkgs github:NixOS/nixpkgs/nixpkgs-unstable\nglobal flake:templates github:NixOS/templates\nglobal flake:patchelf github:NixOS/patchelf\nglobal flake:nix-serve github:edolstra/nix-serve\nglobal flake:nickel github:tweag/nickel\n"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"So how does a flake registry work?\n"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"It is managed through "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"nix registry"}]},{"type":"text","value":" subcommand or set "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"nix.registry"}]},{"type":"text","value":" in your system configuration.\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Registries are primarily written as JSON files in certain files (e.g., "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"$XDG_CONFIG_HOME/nix/registry"}]},{"type":"text","value":", "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"/etc/nix/registry.json"}]},{"type":"text","value":").\n For more information, see the "},{"type":"element","tagName":"a","properties":{"href":"https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-registry.html#registry-format"},"children":[{"type":"text","value":"registry format from the manual"}]},{"type":"text","value":".\n Unlike the traditional Nix channels, the inclusion of arbitrary files and their locations doesn't seem to affect the reproducibility since it is mostly used as a convenience feature after all.\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"The flakes from default registry are mostly getting the latest revisions of the flake per invocation so it is best practice to pin them (e.g., "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"nix registry pin"}]},{"type":"text","value":", through "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"nix.registry"}]},{"type":"text","value":" while setting the NixOS systems in "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"flake.nix"}]},{"type":"text","value":").\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"There are primarily three registries to worry about: user, system, and global.\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"This is also the reason it downloads something why each time you invoke a Nix-related command (e.g., "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"nix search"}]},{"type":"text","value":", "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"nix edit"}]},{"type":"text","value":").\n "}]}]}]},{"type":"element","tagName":"h1","properties":{"id":"more-information-about-flakes"},"children":[{"type":"text","value":"More information about flakes"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"We can modify our inputs.\n In the above example, we made "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"home-manager"}]},{"type":"text","value":" to use our version of "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"nixpkgs"}]},{"type":"text","value":" which will make it easier to sync.\n"}]}]}]}]},"backlinks":[{"path":"/packages.nix","title":"Nix packages"},{"path":"/tools.nix","title":"Nix package manager"}]},"__N_SSG":true},"page":"/[[...slug]]","query":{"slug":["tools.nix.flakes"]},"buildId":"Ie9t5zutrXP6Of75Cb5xF","assetPrefix":"/wiki","nextExport":false,"isFallback":false,"gsp":true}</script><script nomodule="" src="/wiki/_next/static/chunks/polyfills-99d808df29361cf7ffb1.js"></script><script src="/wiki/_next/static/chunks/main-ae4733327bd95c4ac325.js" async=""></script><script src="/wiki/_next/static/chunks/webpack-50bee04d1dc61f8adf5b.js" async=""></script><script src="/wiki/_next/static/chunks/framework.9d524150d48315f49e80.js" async=""></script><script src="/wiki/_next/static/chunks/commons.0e1c3f9aa780c2dfe9f0.js" async=""></script><script src="/wiki/_next/static/chunks/pages/_app-8e3d0c58a60ec788aa69.js" async=""></script><script src="/wiki/_next/static/chunks/940643274e605e7596ecea1f2ff8d83317a3fb76.4841a16762f602a59f00.js" async=""></script><script src="/wiki/_next/static/chunks/pages/%5B%5B...slug%5D%5D-1aa198f87ede1cd0e1dc.js" async=""></script><script src="/wiki/_next/static/Ie9t5zutrXP6Of75Cb5xF/_buildManifest.js" async=""></script><script src="/wiki/_next/static/Ie9t5zutrXP6Of75Cb5xF/_ssgManifest.js" async=""></script></body></html> |