mirror of
https://codeberg.org/mhwombat/nix-book.git
synced 2026-01-07 22:37:23 +08:00
temp
This commit is contained in:
parent
f82b300885
commit
5dcadd370e
6 changed files with 224 additions and 158 deletions
125
index.html
125
index.html
|
|
@ -286,8 +286,9 @@ pre.pygments .tok-il { color: #666666 } /* Literal.Number.Integer.Long */
|
|||
<li><a href="#_buildruntime_environments">10.5. Build/runtime environments</a>
|
||||
<ul class="sectlevel3">
|
||||
<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_to_a_haskell_package_defined_in_a_flake">10.5.2. Access to a Haskell package defined in a flake</a></li>
|
||||
<li><a href="#_access_a_non_flake_package_not_in_nixpkgs">10.5.3. Access a non-flake package (not in nixpkgs)</a></li>
|
||||
<li><a href="#_access_a_flake_4">10.5.2. Access a flake</a></li>
|
||||
<li><a href="#_access_to_a_haskell_package_defined_in_a_flake">10.5.3. Access to a Haskell package defined in a flake</a></li>
|
||||
<li><a href="#_access_a_non_flake_package_not_in_nixpkgs">10.5.4. 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>
|
||||
|
|
@ -5128,15 +5129,127 @@ Line 15 should be replaced with:</p>
|
|||
<div class="paragraph">
|
||||
<p>See <a href="#_introducing_a_dependency">Section 8.2, “Introducing a dependency”</a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect3">
|
||||
<h4 id="_access_a_flake_4">10.5.2. Access a flake</h4>
|
||||
<div class="paragraph">
|
||||
<p>Unresolved directive in recipes/build/main.adoc - include::flake/main-generated.adoc[leveloffset=+1]</p>
|
||||
<p>In this example, we will use 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, “Run a flake”</a>.</p>
|
||||
</div>
|
||||
<div class="listingblock">
|
||||
<div class="title">flake.nix</div>
|
||||
<div class="content">
|
||||
<pre class="pygments highlight nowrap"><code data-lang="nix"><div class="lineno"><table class="linenotable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal"> 1</span>
|
||||
<span class="normal"> 2</span>
|
||||
<span class="normal"> 3</span>
|
||||
<span class="normal"> 4</span>
|
||||
<span class="normal"> 5</span>
|
||||
<span class="normal"> 6</span>
|
||||
<span class="normal"> 7</span>
|
||||
<span class="normal"> 8</span>
|
||||
<span class="normal"> 9</span>
|
||||
<span class="normal">10</span>
|
||||
<span class="normal">11</span>
|
||||
<span class="normal">12</span>
|
||||
<span class="normal">13</span>
|
||||
<span class="normal">14</span>
|
||||
<span class="normal">15</span>
|
||||
<span class="normal">16</span>
|
||||
<span class="normal">17</span>
|
||||
<span class="normal">18</span>
|
||||
<span class="normal">19</span>
|
||||
<span class="normal">20</span>
|
||||
<span class="normal">21</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">"github:NixOS/nixpkgs"</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">"github:numtide/flake-utils"</span><span class="tok-p">;</span>
|
||||
<span class="hll"> hello-flake<span class="tok-o">.</span><span class="tok-ss">url</span> <span class="tok-o">=</span> <span class="tok-s2">"git+https://codeberg.org/mhwombat/hello-flake"</span><span class="tok-p">;</span>
|
||||
</span> <span class="tok-p">};</span>
|
||||
|
||||
<span class="tok-ss">outputs</span> <span class="tok-o">=</span> <span class="tok-p">{</span> self<span class="tok-p">,</span> nixpkgs<span class="tok-p">,</span> flake-utils<span class="tok-p">,</span> hello-flake <span class="tok-p">}:</span>
|
||||
flake-utils<span class="tok-o">.</span>lib<span class="tok-o">.</span>eachDefaultSystem <span class="tok-p">(</span>system<span class="tok-p">:</span>
|
||||
<span class="tok-k">let</span>
|
||||
<span class="tok-ss">pkgs</span> <span class="tok-o">=</span> <span class="tok-nb">import</span> nixpkgs <span class="tok-p">{</span> <span class="tok-k">inherit</span> system<span class="tok-p">;</span> <span class="tok-p">};</span>
|
||||
<span class="tok-k">in</span>
|
||||
<span class="tok-p">{</span>
|
||||
<span class="tok-ss">devShells</span> <span class="tok-o">=</span> <span class="tok-k">rec</span> <span class="tok-p">{</span>
|
||||
<span class="tok-ss">default</span> <span class="tok-o">=</span> pkgs<span class="tok-o">.</span>mkShell <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-p">};</span>
|
||||
<span class="tok-p">}</span>
|
||||
<span class="tok-p">);</span>
|
||||
<span class="tok-p">}</span>
|
||||
</pre></div></td></tr></table></div></code></pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>Let’s take a closer look at the <code>buildInputs</code> expression from line 16.</p>
|
||||
</div>
|
||||
<div class="literalblock">
|
||||
<div class="content">
|
||||
<pre class="nowrap">hello-flake.packages.${system}.hello</pre>
|
||||
</div>
|
||||
</div>
|
||||
<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&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>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>Here’s a demonstration using the flake.</p>
|
||||
</div>
|
||||
<div class="literalblock">
|
||||
<div class="content">
|
||||
<pre class="nowrap">$ nix run
|
||||
error: flake 'git+file:///home/amy/codeberg/nix-book?dir=source/recipes/build/flake/tempwork' does not provide attribute 'apps.x86_64-linux.default', 'defaultApp.x86_64-linux', 'packages.x86_64-linux.default' or 'defaultPackage.x86_64-linux'</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p>Unresolved directive in recipes/build/main.adoc - include::haskell-pkg/main-generated.adoc[leveloffset=+1]</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect3">
|
||||
<h4 id="_access_to_a_haskell_package_defined_in_a_flake">10.5.2. Access to a Haskell package defined in a flake</h4>
|
||||
<h4 id="_access_to_a_haskell_package_defined_in_a_flake">10.5.3. Access to a Haskell package defined in a flake</h4>
|
||||
<div class="paragraph">
|
||||
<p>In this example we will access three Haskell packages
|
||||
(<code>pandoc-linear-table</code>, <code>pandoc-logic-proof</code>, and <code>pandoc-columns</code>)
|
||||
|
|
@ -5220,7 +5333,7 @@ set up automatically; no need to define <code>devShells</code>.</p>
|
|||
</div>
|
||||
</div>
|
||||
<div class="sect3">
|
||||
<h4 id="_access_a_non_flake_package_not_in_nixpkgs">10.5.3. Access a non-flake package (not in nixpkgs)</h4>
|
||||
<h4 id="_access_a_non_flake_package_not_in_nixpkgs">10.5.4. 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, “Run a flake”</a>.</p>
|
||||
|
|
@ -5455,7 +5568,7 @@ Hello from your flake!</pre>
|
|||
</div>
|
||||
<div id="footer">
|
||||
<div id="footer-text">
|
||||
Last updated 2025-09-15 15:27:34 IST
|
||||
Last updated 2025-09-15 15:31:24 IST
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
|
|
|||
128
source/recipes/build/flake/tempwork/flake.lock
generated
128
source/recipes/build/flake/tempwork/flake.lock
generated
|
|
@ -1,128 +0,0 @@
|
|||
{
|
||||
"nodes": {
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1731533236,
|
||||
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-utils_2": {
|
||||
"inputs": {
|
||||
"systems": "systems_2"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1731533236,
|
||||
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"hello-flake": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils_2",
|
||||
"nixpkgs": "nixpkgs"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1757875192,
|
||||
"narHash": "sha256-JBkm6NAOYjR3Sc3BxJ2ijrTqW8Ga0NlN9GPUJ/NUsGM=",
|
||||
"ref": "refs/heads/main",
|
||||
"rev": "2d9363f255c44a41be2e5291dd624e078e7f4139",
|
||||
"revCount": 25,
|
||||
"type": "git",
|
||||
"url": "https://codeberg.org/mhwombat/hello-flake"
|
||||
},
|
||||
"original": {
|
||||
"type": "git",
|
||||
"url": "https://codeberg.org/mhwombat/hello-flake"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1757873102,
|
||||
"narHash": "sha256-kYhNxLlYyJcUouNRazBufVfBInMWMyF+44xG/xar2yE=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "88cef159e47c0dc56f151593e044453a39a6e547",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs_2": {
|
||||
"locked": {
|
||||
"lastModified": 1757945769,
|
||||
"narHash": "sha256-z/SdByTaDnEx4Zj0pyMwzY+uKxV/2TpQQ6ZKijKc2t0=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "62b2408b85dc46dab0b8ca4250471b9cb23425f0",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"hello-flake": "hello-flake",
|
||||
"nixpkgs": "nixpkgs_2"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"systems_2": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
{
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
hello-flake.url = "git+https://codeberg.org/mhwombat/hello-flake";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, flake-utils, hello-flake }:
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
in
|
||||
{
|
||||
devShells = rec {
|
||||
default = pkgs.mkShell {
|
||||
buildInputs = [ hello-flake.packages.${system}.hello ];
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
@ -11,9 +11,7 @@
|
|||
outputs = { self, nixpkgs, flake-utils, hello-nix }:
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
};
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
helloNix = import hello-nix { inherit pkgs; };
|
||||
in
|
||||
{
|
||||
|
|
|
|||
77
source/recipes/devshell/nix-non-flake/tempwork/flake.lock
generated
Normal file
77
source/recipes/devshell/nix-non-flake/tempwork/flake.lock
generated
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
{
|
||||
"nodes": {
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1731533236,
|
||||
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"hello-nix": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1757705465,
|
||||
"narHash": "sha256-sJCQ9+8Dy+QF9ISaupp42+mGbuXtFyqbX85tWzeNPOI=",
|
||||
"ref": "refs/heads/main",
|
||||
"rev": "56044f61231c996e4ab795de1da89e5f79db3f4f",
|
||||
"revCount": 5,
|
||||
"type": "git",
|
||||
"url": "https://codeberg.org/mhwombat/hello-nix"
|
||||
},
|
||||
"original": {
|
||||
"type": "git",
|
||||
"url": "https://codeberg.org/mhwombat/hello-nix"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1757945769,
|
||||
"narHash": "sha256-z/SdByTaDnEx4Zj0pyMwzY+uKxV/2TpQQ6ZKijKc2t0=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "62b2408b85dc46dab0b8ca4250471b9cb23425f0",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"hello-nix": "hello-nix",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
27
source/recipes/devshell/nix-non-flake/tempwork/flake.nix
Normal file
27
source/recipes/devshell/nix-non-flake/tempwork/flake.nix
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
hello-nix = {
|
||||
url = "git+https://codeberg.org/mhwombat/hello-nix";
|
||||
flake = false;
|
||||
};
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, flake-utils, hello-nix }:
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
pkgs = import nixpkgs {
|
||||
inherit system;
|
||||
};
|
||||
helloNix = import hello-nix { inherit pkgs; };
|
||||
in
|
||||
{
|
||||
devShells = rec {
|
||||
default = pkgs.mkShell {
|
||||
packages = [ helloNix ];
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue