mirror of
https://codeberg.org/mhwombat/nix-book.git
synced 2026-05-13 20:21:13 +08:00
temp
This commit is contained in:
parent
1780a19954
commit
9b6a45eb86
3 changed files with 30 additions and 57 deletions
79
index.html
79
index.html
|
|
@ -215,15 +215,10 @@
|
|||
</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>
|
||||
<ul class="sectlevel4">
|
||||
<li><a href="#devshell-impure">If the nix derivation requires <code>nixpkgs</code></a></li>
|
||||
<li><a href="#_access_a_non_flake_package_not_in_nixpkgs">10.5.1. Access a non-flake package (not in nixpkgs)</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#_special_situations">10.6. Special situations</a></li>
|
||||
<li><a href="#_an_old_style_nix_shell_with_access_to_a_flake">10.7. An (old-style) Nix shell with access to a flake</a></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>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
|
@ -4982,11 +4977,11 @@ hello-nix
|
|||
<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="background-color: #ffffcc"> <span style="color: #19177C">hello-nix</span> <span style="color: #666666">=</span> {
|
||||
</span><span style="background-color: #ffffcc"> <span style="color: #19177C">url</span> <span style="color: #666666">=</span> <span style="color: #BA2121">"git+https://codeberg.org/mhwombat/hello-nix"</span>;
|
||||
</span><span style="background-color: #ffffcc"> <span style="color: #19177C">flake</span> <span style="color: #666666">=</span> <span style="color: #880000">false</span>;
|
||||
</span><span style="background-color: #ffffcc"> };
|
||||
</span> };
|
||||
<span style="color: #19177C">hello-nix</span> <span style="color: #666666">=</span> {
|
||||
<span style="color: #19177C">url</span> <span style="color: #666666">=</span> <span style="color: #BA2121">"git+https://codeberg.org/mhwombat/hello-nix"</span>;
|
||||
<span style="color: #19177C">flake</span> <span style="color: #666666">=</span> <span style="color: #880000">false</span>;
|
||||
};
|
||||
};
|
||||
|
||||
<span style="color: #19177C">outputs</span> <span style="color: #666666">=</span> { self, nixpkgs, flake-utils, hello-nix }:
|
||||
flake-utils<span style="color: #666666">.</span>lib<span style="color: #666666">.</span>eachDefaultSystem (system:
|
||||
|
|
@ -4994,8 +4989,8 @@ hello-nix
|
|||
<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="background-color: #ffffcc"> <span style="color: #19177C">helloNix</span> <span style="color: #666666">=</span> <span style="color: #008000">import</span> hello-nix { <span style="color: #008000; font-weight: bold">inherit</span> pkgs; };
|
||||
</span> <span style="color: #008000; font-weight: bold">in</span>
|
||||
<span style="color: #19177C">helloNix</span> <span style="color: #666666">=</span> <span style="color: #008000">import</span> hello-nix { <span style="color: #008000; font-weight: bold">inherit</span> pkgs; };
|
||||
<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> {
|
||||
|
|
@ -5008,13 +5003,13 @@ hello-nix
|
|||
<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-again $out/bin</span>
|
||||
<span style="color: #BA2121"> chmod +x $out/bin/hello-again</span>
|
||||
<span style="background-color: #ffffcc"> <span style="color: #BA2121">''</span>
|
||||
</span><span style="background-color: #ffffcc"><span style="color: #BA2121"> mkdir -p $out/bin</span>
|
||||
</span><span style="background-color: #ffffcc"><span style="color: #BA2121"> cp $src/hello-again $out/bin</span>
|
||||
</span><span style="color: #BA2121"> chmod +x $out/bin/hello-again</span>
|
||||
|
||||
<span style="color: #BA2121"> # modify the hello-again script so it can find hello-nix</span>
|
||||
<span style="color: #BA2121"> HELLO=$(type -p hello-nix)</span>
|
||||
<span style="background-color: #ffffcc"><span style="color: #BA2121"> # modify the hello-again script so it can find hello-nix</span>
|
||||
</span><span style="color: #BA2121"> HELLO=$(type -p hello-nix)</span>
|
||||
<span style="color: #BA2121"> sed "s_hello-nix_"$HELLO"_" --in-place $out/bin/hello-again</span>
|
||||
<span style="color: #BA2121"> ''</span>;
|
||||
|
||||
|
|
@ -5035,8 +5030,15 @@ hello-nix
|
|||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>We already covered how to add a non-flake input to a flake and build it in <a href="#devshell-nix-non-flake">Section 10.4.6, “Access a non-flake package (not in nixpkgs)”</a>;
|
||||
Lines 5-8 and 17 were explained in <a href="#devshell-nix-non-flake">Section 10.4.6, “Access a non-flake package (not in nixpkgs)”</a>.</p>
|
||||
<p>Lines 5-8 and 17 were explained in <a href="#devshell-nix-non-flake">Section 10.4.6, “Access a non-flake package (not in nixpkgs)”</a>.
|
||||
As expected, we need to add <code>helloNix</code> as a build input, which we do in line 36.
|
||||
That does make it available at build and runtime, but it doesn’t put it on the path,
|
||||
so our <code>hello-again</code> script won’t be able to find it.</p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>There are various ways to deal with this problem.
|
||||
In this case we simply edited the script as we install it,
|
||||
by specifying the full path to <code>hello-nix</code>.</p>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>Here’s a demonstration using the shell.</p>
|
||||
|
|
@ -5044,46 +5046,19 @@ Lines 5-8 and 17 were explained in <a href="#devshell-nix-non-flake">Section 10.
|
|||
<div class="literalblock">
|
||||
<div class="content">
|
||||
<pre class="nowrap">$ hello-nix # this will fail
|
||||
bash: line 34: hello-nix: command not found
|
||||
bash: line 40: hello-nix: command not found
|
||||
$ nix develop
|
||||
building '/nix/store/q7fkc1pi5bv5nm26iaqqxps8av935cfi-hello-again-env.drv'...
|
||||
$ hello-nix
|
||||
Hello from your nix package!</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect4">
|
||||
<h5 id="devshell-impure">If the nix derivation requires <code>nixpkgs</code></h5>
|
||||
<div class="paragraph">
|
||||
<p>In this case, we need to write the derivation ourselves.
|
||||
We can use <code>default.nix</code> as a model.
|
||||
Line 15 should be replaced with:</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre class="pygments highlight nowrap" style="background: #f8f8f8;"><code data-lang="nix"><span></span> <span style="color: #19177C">helloNix</span> <span style="color: #666666">=</span> pkgs<span style="color: #666666">.</span>stdenv<span style="color: #666666">.</span>mkDerivation {
|
||||
<span style="color: #19177C">name</span> <span style="color: #666666">=</span> <span style="color: #BA2121">"hello-nix"</span>;
|
||||
<span style="color: #19177C">src</span> <span style="color: #666666">=</span> hello-nix;
|
||||
<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-nix $out/bin/hello-nix</span>
|
||||
<span style="color: #BA2121"> chmod +x $out/bin/hello-nix</span>
|
||||
<span style="color: #BA2121"> ''</span>;
|
||||
};</code></pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>Unresolved directive in recipes/build/main.adoc - include::non-flake/main-generated.adoc[leveloffset=+1]</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect2">
|
||||
<h3 id="_special_situations">10.6. Special situations</h3>
|
||||
|
||||
</div>
|
||||
<div class="sect2">
|
||||
<h3 id="_an_old_style_nix_shell_with_access_to_a_flake">10.7. An (old-style) Nix shell with access to a flake</h3>
|
||||
<h3 id="_an_old_style_nix_shell_with_access_to_a_flake">10.6. An (old-style) Nix shell with access to a flake</h3>
|
||||
<div class="paragraph">
|
||||
<p>If you are maintaining legacy code,
|
||||
you may need to provide access to a flake in a <code>nix-shell</code>.
|
||||
|
|
@ -5141,7 +5116,7 @@ Hello from your flake!</pre>
|
|||
</div>
|
||||
<div id="footer">
|
||||
<div id="footer-text">
|
||||
Last updated 2025-09-13 15:16:26 IST
|
||||
Last updated 2025-09-13 15:27:16 IST
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
|
|
|||
|
|
@ -36,11 +36,11 @@
|
|||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1757771770,
|
||||
"narHash": "sha256-/JghEYWMoO5kV+CQREWs0W+z2g27fHFAkRIP3TQZ5dI=",
|
||||
"lastModified": 1757775813,
|
||||
"narHash": "sha256-mHYalJeeuYTtJNPijlm4IqmxslIB+DTz/wQvz2EB/S4=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "5f7451255f69dc631d3697f274406e936584d876",
|
||||
"rev": "1fb62b80407f458b29ba8168c11095858a250687",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
|
|||
|
|
@ -22,6 +22,4 @@ include::devshell/main.adoc[leveloffset=+1]
|
|||
|
||||
include::build/main.adoc[leveloffset=+1]
|
||||
|
||||
== Special situations
|
||||
|
||||
include::nix-shell/main-generated.adoc[leveloffset=+1]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue