This commit is contained in:
Amy de Buitléir 2025-09-15 18:02:05 +01:00
parent a1b18e5fc7
commit d351582364
6 changed files with 179 additions and 24 deletions

View file

@ -291,8 +291,9 @@ pre.pygments .tok-il { color: #666666 } /* Literal.Number.Integer.Long */
<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_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>
<li><a href="#_access_a_haskell_library_package_in_the_nixpkgs_repo">10.5.3. Access a Haskell library package in the nixpkgs repo</a></li>
<li><a href="#_access_to_a_haskell_package_defined_in_a_flake">10.5.4. Access to a Haskell package defined in a flake</a></li>
<li><a href="#_access_a_non_flake_package_not_in_nixpkgs">10.5.5. 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>
@ -324,7 +325,8 @@ and as a downloadable
<p>I would like to thank the patient people on the
<a href="https://discourse.nixos.org/">NixOS Discourse Forum</a>
who answered my many questions,
especially <code>cdepillabout</code>, <code>FedericoSchonborn</code>, <code>tejing</code> and <code>smkuehnhold</code>.</p>
especially <code>cdepillabout</code>, <code>FedericoSchonborn</code>, <code>tejing</code> and <code>smkuehnhold</code>.
Any mistakes in this book are my own, however.</p>
</div>
</div>
</div>
@ -5260,16 +5262,7 @@ hello-flake
<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 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>
<div class="paragraph">
<p>There are various ways to deal with this problem.
In this case we simply edited the script (lines 30-32) as we install it,
by specifying the full path to <code>hello-nix</code>.</p>
</div>
<div class="paragraph">
<p>Let&#8217;s take a closer look at the <code>buildInputs</code> expression from line 35.</p>
Let&#8217;s take a closer look at the <code>buildInputs</code> expression from line 35.</p>
</div>
<div class="literalblock">
<div class="content">
@ -5282,6 +5275,14 @@ 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.
(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>Line 35 does make <code>hello-flake</code> 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.
There are various ways to deal with this problem.
In this case we simply edited the script (lines 30-32) as we install it,
by specifying the full path to <code>hello-nix</code>.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
@ -5310,12 +5311,17 @@ I'm a flake, and I'm running a command defined in a another flake.
Hello from your flake!</pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_access_a_haskell_library_package_in_the_nixpkgs_repo">10.5.3. Access a Haskell library package in the nixpkgs repo</h4>
<div class="paragraph">
<p>Unresolved directive in recipes/build/main.adoc - include::haskell-pkg/main-generated.adoc[leveloffset=+1]</p>
<p>If you use <code>haskell-flake</code> (see <a href="#haskell-flake">Section 9.1.5, &#8220;The Nix flake&#8221;</a>)
nothing special needs to be added to <code>flake.nix</code>.
Simply list your Haskell package dependencies to your cabal file as you normally would.</p>
</div>
</div>
<div class="sect3">
<h4 id="_access_to_a_haskell_package_defined_in_a_flake">10.5.3. Access to a Haskell package defined in a flake</h4>
<h4 id="_access_to_a_haskell_package_defined_in_a_flake">10.5.4. 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>)
@ -5394,12 +5400,9 @@ set up automatically; no need to define <code>devShells</code>.</p>
</pre></div></td></tr></table></div></code></pre>
</div>
</div>
<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.4. Access a non-flake package (not in nixpkgs)</h4>
<h4 id="_access_a_non_flake_package_not_in_nixpkgs">10.5.5. 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, &#8220;Run a flake&#8221;</a>.</p>
@ -5630,7 +5633,7 @@ Hello from your flake!</pre>
</div>
<div id="footer">
<div id="footer-text">
Last updated 2025-09-15 17:37:10 IST
Last updated 2025-09-15 17:54:57 IST
</div>
</div>
</body>

View file

@ -29,6 +29,7 @@ I would like to thank the patient people on the
https://discourse.nixos.org/[NixOS Discourse Forum]
who answered my many questions,
especially `cdepillabout`, `FedericoSchonborn`, `tejing` and `smkuehnhold`.
Any mistakes in this book are my own, however.
include::intro/main.adoc[leveloffset=+1]

View file

@ -4,10 +4,8 @@ include::nixpkg/main.adoc[leveloffset=+1]
include::flake/main-generated.adoc[leveloffset=+1]
include::haskell-pkg/main-generated.adoc[leveloffset=+1]
include::haskell-pkg/main.adoc[leveloffset=+1]
include::haskell-flake/main-generated.adoc[leveloffset=+1]
include::env-var/main-generated.adoc[leveloffset=+1]
include::nix-non-flake/main-generated.adoc[leveloffset=+1]

View file

@ -13,12 +13,16 @@ $ git commit -a -m temp
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 <<#flakeref>>.
[source,nix,linenums,highlight='5,16']
[source,nix,linenums,highlight='5,8,16']
.flake.nix
....
$# cat flake.nix
....
Line 5 adds `hello-flake` as an input to this flake.
Line 8 allows the output function to reference `hello-flake`.
Line 16 adds `hello-flake` as a build input for this flake.
Let's take a closer look at the `buildInputs` expression from line 16.
....

View file

@ -0,0 +1,128 @@
{
"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": 1757952092,
"narHash": "sha256-BcfTLFCU7elUJ2dwyt0iTjxsz/XLh+8ZygDcFwy6xPE=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "fd76dc9e7c68ac7c3941ba2af2bedcd79c5cf4ed",
"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
}

View file

@ -0,0 +1,21 @@
{
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 ];
};
};
}
);
}