This commit is contained in:
Amy de Buitléir 2025-09-15 17:37:11 +01:00
parent b572ded8d8
commit 781aa484a1
2 changed files with 60 additions and 49 deletions

View file

@ -190,7 +190,11 @@ pre.pygments .tok-il { color: #666666 } /* Literal.Number.Integer.Long */
<li><a href="#_with_expressions">2.16. With expressions</a></li>
</ul>
</li>
<li><a href="#_hello_flake">3. Hello, flake!</a></li>
<li><a href="#_hello_flake">3. Hello, flake!</a>
<ul class="sectlevel2">
<li><a href="#_flake_outputs">3.1. Flake outputs</a></li>
</ul>
</li>
<li><a href="#_the_hello_flake_repo">4. The hello-flake repo</a></li>
<li><a href="#_flake_structure">5. Flake structure</a>
<ul class="sectlevel2">
@ -1927,6 +1931,50 @@ that the package remains in the store for future use.</p>
Hello from your flake!</pre>
</div>
</div>
<div class="sect2">
<h3 id="_flake_outputs">3.1. Flake outputs</h3>
<div class="paragraph">
<p>You can find out what packages and apps a flake provides using the <code>nix flake show</code> command.</p>
</div>
<div class="literalblock">
<div class="content">
<pre class="nowrap">$ nix flake show --all-systems git+https://codeberg.org/mhwombat/hello-flake
git+https://codeberg.org/mhwombat/hello-flake?ref=refs/heads/main&amp;rev=2d9363f255c44a41be2e5291dd624e078e7f4139
├───apps
│ ├───aarch64-darwin
│ │ ├───default: app: no description
│ │ └───hello: app: no description
│ ├───aarch64-linux
│ │ ├───default: app: no description
│ │ └───hello: app: no description
│ ├───x86_64-darwin
│ │ ├───default: app: no description
│ │ └───hello: app: no description
│ └───x86_64-linux
│ ├───default: app: no description
│ └───hello: app: no description
└───packages
├───aarch64-darwin
│ ├───default: package 'hello-flake'
│ └───hello: package 'hello-flake'
├───aarch64-linux
│ ├───default: package 'hello-flake'
│ └───hello: package 'hello-flake'
├───x86_64-darwin
│ ├───default: package 'hello-flake'
│ └───hello: package 'hello-flake'
└───x86_64-linux
├───default: package 'hello-flake'
└───hello: package 'hello-flake'</pre>
</div>
</div>
<div class="paragraph">
<p>Examining the output of this command,
we see that this flake supports multiple architectures
(aarch64-darwin, aarch64-linux, x86_64-darwin and x86_64-linux)
and provides both a package and an app called <code>hello</code>.</p>
</div>
</div>
</div>
</div>
<div class="sect1">
@ -4744,46 +4792,8 @@ However, you can use any of the flake reference styles defined in <a href="#flak
<div class="paragraph">
<p>Why is the first part <code>hello-flake</code> and the last part <code>hello</code>?
The first part refers to the name we assigned in the input section of our flake,
and the last part is the name of the package or app we want.</p>
</div>
<div class="paragraph">
<p>You can find the outputs of a flake using the <code>nix flake show</code> command.</p>
</div>
<div class="literalblock">
<div class="content">
<pre class="nowrap">$ nix flake show git+https://codeberg.org/mhwombat/hello-flake
git+https://codeberg.org/mhwombat/hello-flake?ref=refs/heads/main&amp;rev=2d9363f255c44a41be2e5291dd624e078e7f4139
├───apps
│ ├───aarch64-darwin
│ │ ├───default: app: no description
│ │ └───hello: app: no description
│ ├───aarch64-linux
│ │ ├───default: app: no description
│ │ └───hello: app: no description
│ ├───x86_64-darwin
│ │ ├───default: app: no description
│ │ └───hello: app: no description
│ └───x86_64-linux
│ ├───default: app: no description
│ └───hello: app: no description
└───packages
├───aarch64-darwin
│ ├───default omitted (use '--all-systems' to show)
│ └───hello omitted (use '--all-systems' to show)
├───aarch64-linux
│ ├───default omitted (use '--all-systems' to show)
│ └───hello omitted (use '--all-systems' to show)
├───x86_64-darwin
│ ├───default omitted (use '--all-systems' to show)
│ └───hello omitted (use '--all-systems' to show)
└───x86_64-linux
├───default: package 'hello-flake'
└───hello: package 'hello-flake'</pre>
</div>
</div>
<div class="paragraph">
<p>Examining the output of this command,
we see that this flake provides both a package and an app called <code>hello</code>.</p>
and the last part is the name of the package or app we want.
(See <a href="#_flake_outputs">Section 3.1, &#8220;Flake outputs&#8221;</a> for how to identify flake outputs.)</p>
</div>
<div class="paragraph">
<p>Here&#8217;s a demonstration using the shell.</p>
@ -4791,7 +4801,7 @@ we see that this flake provides both a package and an app called <code>hello</co
<div class="literalblock">
<div class="content">
<pre class="nowrap">$ hello-flake # Fails; dependency not available
bash: line 40: hello-flake: command not found
bash: line 31: hello-flake: command not found
$ nix develop
$ hello-flake # Works in development environment
Hello from your flake!</pre>
@ -5197,8 +5207,7 @@ hello-flake
<span class="normal">43</span>
<span class="normal">44</span>
<span class="normal">45</span>
<span class="normal">46</span>
<span class="normal">47</span></pre></div></td><td class="code"><div><pre><span></span><span class="tok-p">{</span>
<span class="normal">46</span></pre></div></td><td class="code"><div><pre><span></span><span class="tok-p">{</span>
<span class="tok-ss">inputs</span> <span class="tok-o">=</span> <span class="tok-p">{</span>
nixpkgs<span class="tok-o">.</span><span class="tok-ss">url</span> <span class="tok-o">=</span> <span class="tok-s2">&quot;github:NixOS/nixpkgs&quot;</span><span class="tok-p">;</span>
flake-utils<span class="tok-o">.</span><span class="tok-ss">url</span> <span class="tok-o">=</span> <span class="tok-s2">&quot;github:numtide/flake-utils&quot;</span><span class="tok-p">;</span>
@ -5232,7 +5241,6 @@ hello-flake
</span><span class="hll"><span class="tok-s tok-s-Multiline"> sed &quot;s_hello-flake_&quot;$HELLO&quot;_&quot; --in-place $out/bin/hello-again</span>
</span><span class="tok-s tok-s-Multiline"> &#39;&#39;</span><span class="tok-p">;</span>
<span class="hll"> <span class="tok-ss">buildInputs</span> <span class="tok-o">=</span> <span class="tok-p">[</span> hello-flake<span class="tok-o">.</span>packages<span class="tok-o">.</span><span class="tok-si">${</span>system<span class="tok-si">}</span><span class="tok-o">.</span>hello <span class="tok-p">];</span>
</span> <span class="tok-p">};</span>
<span class="tok-ss">default</span> <span class="tok-o">=</span> hello<span class="tok-p">;</span>
@ -5251,7 +5259,7 @@ hello-flake
<div class="paragraph">
<p>Line 5 adds <code>hello-flake</code> as an input to this flake,
Line 8 allows the output function to reference <code>hello-flake</code>.
As expected, we need to add <code>hello-flake</code> as a build input, which we do in line 36.
As expected, we need to add <code>hello-flake</code> as a build input, which we do in line 35.
That does make it available at build and runtime, but it doesn&#8217;t put it on the path,
so our <code>hello-again</code> script won&#8217;t be able to find it.</p>
</div>
@ -5284,6 +5292,9 @@ In that case, adding the dependency to <code>buildInputs</code> is sufficient.</
<div class="literalblock">
<div class="content">
<pre class="nowrap">$ nix run
this derivation will be built:
/nix/store/aymycx9z7b8qgi0avs73b8c5xc4jxwx3-hello-again.drv
building '/nix/store/aymycx9z7b8qgi0avs73b8c5xc4jxwx3-hello-again.drv'...
I'm a flake, and I'm running a command defined in a another flake.
Hello from your flake!</pre>
</div>
@ -5608,7 +5619,7 @@ Hello from your flake!</pre>
</div>
<div id="footer">
<div id="footer-text">
Last updated 2025-09-15 16:12:35 IST
Last updated 2025-09-15 17:34:09 IST
</div>
</div>
</body>

View file

@ -58,11 +58,11 @@ $# ${executable}
== Flake outputs
You can find the outputs of a flake using the `nix flake show` command.
You can find out what packages and apps a flake provides using the `nix flake show` command.
....
$# echo '$ nix flake show --all-systems git+https://codeberg.org/mhwombat/hello-flake'
$# nix flake show git+https://codeberg.org/mhwombat/hello-flake --quiet | sed -e 's/\x1b\[[0-9;]*m//g'
$# nix flake show --all-systems git+https://codeberg.org/mhwombat/hello-flake --quiet | sed -e 's/\x1b\[[0-9;]*m//g'
....
Examining the output of this command,