mirror of
https://codeberg.org/mhwombat/nix-book.git
synced 2026-01-04 04:35:27 +08:00
temp
This commit is contained in:
parent
3e2a61c802
commit
d4eb863b3c
2 changed files with 126 additions and 7 deletions
127
index.html
127
index.html
|
|
@ -215,7 +215,8 @@
|
|||
</li>
|
||||
<li><a href="#_buildruntime_environments">10.5. Build/runtime environments</a>
|
||||
<ul class="sectlevel3">
|
||||
<li><a href="#_access_a_non_flake_package_not_in_nixpkgs">10.5.1. Access a non-flake package (not in nixpkgs)</a></li>
|
||||
<li><a href="#_access_a_top_level_package_from_the_nixpkgsnixos_repo_4">10.5.1. Access a top level package from the Nixpkgs/NixOS repo</a></li>
|
||||
<li><a href="#_access_a_non_flake_package_not_in_nixpkgs">10.5.2. Access a non-flake package (not in nixpkgs)</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#_an_old_style_nix_shell_with_access_to_a_flake">10.6. An (old-style) Nix shell with access to a flake</a></li>
|
||||
|
|
@ -4878,8 +4879,124 @@ Line 15 should be replaced with:</p>
|
|||
</div>
|
||||
<div class="sect2">
|
||||
<h3 id="_buildruntime_environments">10.5. Build/runtime environments</h3>
|
||||
<div class="sect3">
|
||||
<h4 id="_access_a_top_level_package_from_the_nixpkgsnixos_repo_4">10.5.1. Access a top level package from the Nixpkgs/NixOS repo</h4>
|
||||
<div class="listingblock">
|
||||
<div class="title">hello-with-cow</div>
|
||||
<div class="content">
|
||||
<pre class="pygments highlight nowrap" style="background: #f8f8f8;"><code data-lang="shell"><div class="lineno"><table class="linenotable"><tr><td class="linenos"><div class="linenodiv"><pre><span style="color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px;">1</span>
|
||||
<span style="color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px;">2</span>
|
||||
<span style="color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px;">3</span></pre></div></td><td class="code"><div><pre style="line-height: 125%;"><span></span><span style="color: #3D7B7B; font-style: italic">#!/usr/bin/env sh</span>
|
||||
|
||||
cowsay<span style="color: #bbbbbb"> </span><span style="color: #BA2121">"Hello from your flake!"</span>
|
||||
</pre></div></td></tr></table></div></code></pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="title">flake.nix</div>
|
||||
<div class="content">
|
||||
<pre class="pygments highlight nowrap" style="background: #f8f8f8;"><code data-lang="nix"><div class="lineno"><table class="linenotable"><tr><td class="linenos"><div class="linenodiv"><pre><span style="color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px;"> 1</span>
|
||||
<span style="color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px;"> 2</span>
|
||||
<span style="color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px;"> 3</span>
|
||||
<span style="color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px;"> 4</span>
|
||||
<span style="color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px;"> 5</span>
|
||||
<span style="color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px;"> 6</span>
|
||||
<span style="color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px;"> 7</span>
|
||||
<span style="color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px;"> 8</span>
|
||||
<span style="color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px;"> 9</span>
|
||||
<span style="color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px;">10</span>
|
||||
<span style="color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px;">11</span>
|
||||
<span style="color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px;">12</span>
|
||||
<span style="color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px;">13</span>
|
||||
<span style="color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px;">14</span>
|
||||
<span style="color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px;">15</span>
|
||||
<span style="color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px;">16</span>
|
||||
<span style="color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px;">17</span>
|
||||
<span style="color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px;">18</span>
|
||||
<span style="color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px;">19</span>
|
||||
<span style="color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px;">20</span>
|
||||
<span style="color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px;">21</span>
|
||||
<span style="color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px;">22</span>
|
||||
<span style="color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px;">23</span>
|
||||
<span style="color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px;">24</span>
|
||||
<span style="color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px;">25</span>
|
||||
<span style="color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px;">26</span>
|
||||
<span style="color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px;">27</span>
|
||||
<span style="color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px;">28</span>
|
||||
<span style="color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px;">29</span>
|
||||
<span style="color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px;">30</span>
|
||||
<span style="color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px;">31</span>
|
||||
<span style="color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px;">32</span>
|
||||
<span style="color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px;">33</span>
|
||||
<span style="color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px;">34</span>
|
||||
<span style="color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px;">35</span>
|
||||
<span style="color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px;">36</span>
|
||||
<span style="color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px;">37</span>
|
||||
<span style="color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px;">38</span>
|
||||
<span style="color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px;">39</span></pre></div></td><td class="code"><div><pre style="line-height: 125%;"><span></span>{
|
||||
<span style="color: #19177C">inputs</span> <span style="color: #666666">=</span> {
|
||||
nixpkgs<span style="color: #666666">.</span><span style="color: #19177C">url</span> <span style="color: #666666">=</span> <span style="color: #BA2121">"github:NixOS/nixpkgs"</span>;
|
||||
flake-utils<span style="color: #666666">.</span><span style="color: #19177C">url</span> <span style="color: #666666">=</span> <span style="color: #BA2121">"github:numtide/flake-utils"</span>;
|
||||
};
|
||||
|
||||
<span style="color: #19177C">outputs</span> <span style="color: #666666">=</span> { self, nixpkgs, flake-utils }:
|
||||
flake-utils<span style="color: #666666">.</span>lib<span style="color: #666666">.</span>eachDefaultSystem (system:
|
||||
<span style="color: #008000; font-weight: bold">let</span>
|
||||
<span style="color: #19177C">pkgs</span> <span style="color: #666666">=</span> <span style="color: #008000">import</span> nixpkgs { <span style="color: #008000; font-weight: bold">inherit</span> system; };
|
||||
<span style="color: #008000; font-weight: bold">in</span>
|
||||
{
|
||||
<span style="color: #19177C">packages</span> <span style="color: #666666">=</span> <span style="color: #008000; font-weight: bold">rec</span> {
|
||||
<span style="color: #19177C">hello</span> <span style="color: #666666">=</span> pkgs<span style="color: #666666">.</span>stdenv<span style="color: #666666">.</span>mkDerivation <span style="color: #008000; font-weight: bold">rec</span> {
|
||||
<span style="background-color: #ffffcc"> <span style="color: #19177C">name</span> <span style="color: #666666">=</span> <span style="color: #BA2121">"hello-flake"</span>;
|
||||
</span>
|
||||
<span style="color: #19177C">src</span> <span style="color: #666666">=</span> ./.;
|
||||
|
||||
<span style="color: #19177C">unpackPhase</span> <span style="color: #666666">=</span> <span style="color: #BA2121">"true"</span>;
|
||||
|
||||
<span style="color: #19177C">buildPhase</span> <span style="color: #666666">=</span> <span style="color: #BA2121">":"</span>;
|
||||
|
||||
<span style="color: #19177C">installPhase</span> <span style="color: #666666">=</span>
|
||||
<span style="color: #BA2121">''</span>
|
||||
<span style="color: #BA2121"> mkdir -p $out/bin</span>
|
||||
<span style="color: #BA2121"> cp $src/hello-flake $out/bin/hello-flake</span>
|
||||
<span style="color: #BA2121"> chmod +x $out/bin/hello-flake</span>
|
||||
<span style="color: #BA2121"> ''</span>;
|
||||
};
|
||||
<span style="color: #19177C">default</span> <span style="color: #666666">=</span> hello;
|
||||
};
|
||||
|
||||
<span style="color: #19177C">apps</span> <span style="color: #666666">=</span> <span style="color: #008000; font-weight: bold">rec</span> {
|
||||
<span style="color: #19177C">hello</span> <span style="color: #666666">=</span> flake-utils<span style="color: #666666">.</span>lib<span style="color: #666666">.</span>mkApp { <span style="color: #19177C">drv</span> <span style="color: #666666">=</span> self<span style="color: #666666">.</span>packages<span style="color: #666666">.</span><span style="color: #A45A77; font-weight: bold">${</span>system<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #666666">.</span>hello; };
|
||||
<span style="color: #19177C">default</span> <span style="color: #666666">=</span> hello;
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
</pre></div></td></tr></table></div></code></pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>Unresolved directive in recipes/build/main.adoc - include::nixpkg/main-generated.adoc[leveloffset=+1]</p>
|
||||
<p>Here’s a demonstration using the flake.</p>
|
||||
</div>
|
||||
<div class="literalblock">
|
||||
<div class="content">
|
||||
<pre class="nowrap">$ nix run
|
||||
this derivation will be built:
|
||||
/nix/store/k2w6258690zjhdf6y59vfpfiz7d67jb1-hello-flake.drv
|
||||
building '/nix/store/k2w6258690zjhdf6y59vfpfiz7d67jb1-hello-flake.drv'...
|
||||
error: builder for '/nix/store/k2w6258690zjhdf6y59vfpfiz7d67jb1-hello-flake.drv' failed with exit code 1;
|
||||
last 8 log lines:
|
||||
> Running phase: unpackPhase
|
||||
> Running phase: patchPhase
|
||||
> Running phase: updateAutotoolsGnuConfigScriptsPhase
|
||||
> Running phase: configurePhase
|
||||
> no configure script, doing nothing
|
||||
> Running phase: buildPhase
|
||||
> Running phase: installPhase
|
||||
> cp: cannot stat '/nix/store/mhmgp4r3vihp0ar76ik7ah5q9djzhrdf-tempwork/hello-flake': No such file or directory
|
||||
For full logs, run:
|
||||
nix log /nix/store/k2w6258690zjhdf6y59vfpfiz7d67jb1-hello-flake.drv</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>Unresolved directive in recipes/build/main.adoc - include::flake/main-generated.adoc[leveloffset=+1]</p>
|
||||
|
|
@ -4893,8 +5010,9 @@ Line 15 should be replaced with:</p>
|
|||
<div class="paragraph">
|
||||
<p>Unresolved directive in recipes/build/main.adoc - include::env-var/main-generated.adoc[leveloffset=+1]</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect3">
|
||||
<h4 id="_access_a_non_flake_package_not_in_nixpkgs">10.5.1. Access a non-flake package (not in nixpkgs)</h4>
|
||||
<h4 id="_access_a_non_flake_package_not_in_nixpkgs">10.5.2. Access a non-flake package (not in nixpkgs)</h4>
|
||||
<div class="paragraph">
|
||||
<p>In this example, we will use a nix package (not a flake) defined in a remote git repo.
|
||||
However, you can use any of the flake reference styles defined in <a href="#flakeref">Section 10.1.2, “Flakes”</a>.</p>
|
||||
|
|
@ -5048,6 +5166,7 @@ by specifying the full path to <code>hello-nix</code>.</p>
|
|||
<pre class="nowrap">$ hello-nix # this will fail
|
||||
bash: line 40: hello-nix: command not found
|
||||
$ nix develop
|
||||
building '/nix/store/0qzgar07id1cpygx9yyxfsvls1w2jf0c-hello-again-env.drv'...
|
||||
$ hello-nix
|
||||
Hello from your nix package!</pre>
|
||||
</div>
|
||||
|
|
@ -5116,7 +5235,7 @@ Hello from your flake!</pre>
|
|||
</div>
|
||||
<div id="footer">
|
||||
<div id="footer-text">
|
||||
Last updated 2025-09-13 15:27:16 IST
|
||||
Last updated 2025-09-13 16:14:15 IST
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
{
|
||||
packages = rec {
|
||||
hello = pkgs.stdenv.mkDerivation rec {
|
||||
name = "hello-flake";
|
||||
name = "hello-with-cow";
|
||||
|
||||
src = ./.;
|
||||
|
||||
|
|
@ -23,8 +23,8 @@
|
|||
installPhase =
|
||||
''
|
||||
mkdir -p $out/bin
|
||||
cp $src/hello-flake $out/bin/hello-flake
|
||||
chmod +x $out/bin/hello-flake
|
||||
cp $src/hello-with-cow $out/bin
|
||||
chmod +x $out/bin/hello-with-cow
|
||||
'';
|
||||
};
|
||||
default = hello;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue