This commit is contained in:
Amy de Buitléir 2025-09-15 14:48:15 +01:00
parent 0b4c31e79b
commit 3220cdc8dc
13 changed files with 55 additions and 191 deletions

View file

@ -244,7 +244,7 @@ pre.pygments .tok-il { color: #666666 } /* Literal.Number.Integer.Long */
<li><a href="#_running_programs_directly_without_installing_them">10.1. Running programs directly (without installing them)</a>
<ul class="sectlevel3">
<li><a href="#_run_a_top_level_package_from_the_nixpkgsnixos_repo">10.1.1. Run a top level package from the Nixpkgs/NixOS repo</a></li>
<li><a href="#flakeref">10.1.2. Flakes</a>
<li><a href="#flakeref">10.1.2. Run a flake</a>
<ul class="sectlevel4">
<li><a href="#_run_a_flake_defined_in_a_local_file">Run a flake defined in a local file</a></li>
<li><a href="#_run_a_flake_defined_in_a_remote_git_repo">Run a flake defined in a remote git repo</a></li>
@ -274,9 +274,8 @@ pre.pygments .tok-il { color: #666666 } /* Literal.Number.Integer.Long */
<li><a href="#_access_a_top_level_package_from_the_nixpkgsnixos_repo_3">10.4.1. Access a top level package from the Nixpkgs/NixOS repo</a></li>
<li><a href="#_access_a_flake_3">10.4.2. Access a flake</a></li>
<li><a href="#_access_a_haskell_library_package_in_the_nixpkgs_repo_without_a_cabal_file_2">10.4.3. Access a Haskell library package in the nixpkgs repo (without a <code>.cabal</code> file)</a></li>
<li><a href="#_access_to_a_haskell_package_defined_in_a_flake">10.4.4. Access to a Haskell package defined in a flake</a></li>
<li><a href="#_set_an_environment_variable">10.4.5. Set an environment variable</a></li>
<li><a href="#devshell-nix-non-flake">10.4.6. Access a non-flake package (not in nixpkgs)</a>
<li><a href="#_set_an_environment_variable">10.4.4. Set an environment variable</a></li>
<li><a href="#devshell-nix-non-flake">10.4.5. Access a non-flake package (not in nixpkgs)</a>
<ul class="sectlevel4">
<li><a href="#devshell-pure">If the nix derivation does not require nixpkgs</a></li>
<li><a href="#devshell-impure">If the nix derivation requires <code>nixpkgs</code></a></li>
@ -4351,7 +4350,7 @@ including defining environments that you will use more than once.</p>
</div>
</div>
<div class="sect3">
<h4 id="flakeref">10.1.2. Flakes</h4>
<h4 id="flakeref">10.1.2. Run a flake</h4>
<div class="sect4">
<h5 id="_run_a_flake_defined_in_a_local_file">Run a flake defined in a local file</h5>
<div class="literalblock">
@ -4393,6 +4392,7 @@ To run a specific branch, use the command below.</p>
<div class="literalblock">
<div class="content">
<pre class="nowrap">$ nix run https://codeberg.org/mhwombat/hello-flake/archive/main.zip
unpacking 'https://codeberg.org/mhwombat/hello-flake/archive/main.zip' into the Git cache...
Hello from your flake!</pre>
</div>
</div>
@ -4402,6 +4402,7 @@ Hello from your flake!</pre>
<div class="literalblock">
<div class="content">
<pre class="nowrap">$ nix run https://codeberg.org/mhwombat/hello-flake/archive/main.tar.gz
unpacking 'https://codeberg.org/mhwombat/hello-flake/archive/main.tar.gz' into the Git cache...
Hello from your flake!</pre>
</div>
</div>
@ -4437,7 +4438,7 @@ $ cowsay "moo"
<h4 id="_access_a_flake">10.2.2. Access a flake</h4>
<div class="paragraph">
<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, &#8220;Flakes&#8221;</a>.</p>
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>
</div>
<div class="literalblock">
<div class="content">
@ -4493,7 +4494,7 @@ cowsay<span class="tok-w"> </span><span class="tok-s2">&quot;Pretty cool, huh?&q
<h4 id="_access_a_flake_2">10.3.2. Access a flake</h4>
<div class="paragraph">
<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, &#8220;Flakes&#8221;</a>.</p>
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>
</div>
<div class="listingblock">
<div class="title">Script</div>
@ -4673,7 +4674,7 @@ $ cowsay "Moo!" # Works in development environment
<h4 id="_access_a_flake_3">10.4.2. Access a flake</h4>
<div class="paragraph">
<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, &#8220;Flakes&#8221;</a>.</p>
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>
</div>
<div class="listingblock">
<div class="title">flake.nix</div>
@ -4779,10 +4780,10 @@ we see that this flake provides both a package and an app called <code>hello</co
</div>
<div class="literalblock">
<div class="content">
<pre class="nowrap">$ hello-flake
<pre class="nowrap">$ hello-flake # Won't work; dependency not available
bash: line 40: hello-flake: command not found
$ nix develop
$ hello-flake
$ hello-flake # Works in development environment
Hello from your flake!</pre>
</div>
</div>
@ -4833,23 +4834,25 @@ together with the <em>high-level workflow</em> described in <a href="#_developme
<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="normal">21</span>
<span class="normal">22</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>
pandoc-columns<span class="tok-o">.</span><span class="tok-ss">url</span> <span class="tok-o">=</span> <span class="tok-s2">&quot;/home/amy/github/pandoc-columns&quot;</span><span class="tok-p">;</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>
<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> pandoc-columns <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="hll"> <span class="tok-ss">customGhc</span> <span class="tok-o">=</span> pkgs<span class="tok-o">.</span>haskellPackages<span class="tok-o">.</span>ghcWithPackages <span class="tok-p">(</span>p<span class="tok-p">:</span> <span class="tok-k">with</span> p<span class="tok-p">;</span> <span class="tok-p">[</span> extra <span class="tok-p">]);</span>
</span> <span class="tok-k">in</span>
<span class="hll"> <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> <span class="tok-ss">customGhc</span> <span class="tok-o">=</span> pkgs<span class="tok-o">.</span>haskellPackages<span class="tok-o">.</span>ghcWithPackages <span class="tok-p">(</span>p<span class="tok-p">:</span> <span class="tok-k">with</span> p<span class="tok-p">;</span> <span class="tok-p">[</span> pandoc-columns <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> customGhc <span class="tok-p">];</span>
</span> <span class="tok-p">};</span>
<span class="hll"> <span class="tok-ss">default</span> <span class="tok-o">=</span> pkgs<span class="tok-o">.</span>mkShell <span class="tok-p">{</span>
</span> <span class="tok-ss">buildInputs</span> <span class="tok-o">=</span> <span class="tok-p">[</span> customGhc <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>
@ -4868,12 +4871,12 @@ together with the <em>high-level workflow</em> described in <a href="#_developme
<span class="normal">3</span>
<span class="normal">4</span>
<span class="normal">5</span>
<span class="normal">6</span></pre></div></td><td class="code"><div><pre><span></span><span class="tok-kr">import</span><span class="tok-w"> </span><span class="tok-nn">Data.List.Extra</span>
<span class="normal">6</span></pre></div></td><td class="code"><div><pre><span></span><span class="tok-kr">import</span><span class="tok-w"> </span><span class="tok-nn">Text.Pandoc.Filters.Columns</span>
<span class="tok-nf">main</span><span class="tok-w"> </span><span class="tok-ow">::</span><span class="tok-w"> </span><span class="tok-kt">IO</span><span class="tok-w"> </span><span class="tok-nb">()</span>
<span class="tok-nf">main</span><span class="tok-w"> </span><span class="tok-ow">=</span><span class="tok-w"> </span><span class="tok-kr">do</span>
<span class="tok-w"> </span><span class="tok-n">print</span><span class="tok-w"> </span><span class="tok-o">$</span><span class="tok-w"> </span><span class="tok-n">lower</span><span class="tok-w"> </span><span class="tok-s">&quot;ABCDE&quot;</span>
<span class="tok-w"> </span><span class="tok-n">print</span><span class="tok-w"> </span><span class="tok-o">$</span><span class="tok-w"> </span><span class="tok-n">upper</span><span class="tok-w"> </span><span class="tok-s">&quot;XYZ&quot;</span>
<span class="tok-w"> </span><span class="tok-n">putStrLn</span><span class="tok-w"> </span><span class="tok-s">&quot;Prove we have access to the pandoc-columns package&quot;</span>
<span class="tok-w"> </span><span class="tok-n">print</span><span class="tok-w"> </span><span class="tok-o">$</span><span class="tok-w"> </span><span class="tok-n">defaultColSpec</span>
</pre></div></td></tr></table></div></code></pre>
</div>
</div>
@ -4898,147 +4901,7 @@ $ runghc Main.hs # Works in development environemnt
</div>
</div>
<div class="sect3">
<h4 id="_access_to_a_haskell_package_defined_in_a_flake">10.4.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>)
that are defined as flakes on my hard drive.
We are using <code>haskell-flake</code>, so the development environment is
set up automatically; no need to define <code>devShells</code>.</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>
<span class="normal">22</span>
<span class="normal">23</span>
<span class="normal">24</span>
<span class="normal">25</span>
<span class="normal">26</span>
<span class="normal">27</span>
<span class="normal">28</span>
<span class="normal">29</span>
<span class="normal">30</span>
<span class="normal">31</span>
<span class="normal">32</span>
<span class="normal">33</span>
<span class="normal">34</span></pre></div></td><td class="code"><div><pre><span></span><span class="tok-p">{</span>
<span class="tok-ss">description</span> <span class="tok-o">=</span> <span class="tok-s2">&quot;Pandoc build system for maths web&quot;</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/nixpkgs-unstable&quot;</span><span class="tok-p">;</span>
flake-parts<span class="tok-o">.</span><span class="tok-ss">url</span> <span class="tok-o">=</span> <span class="tok-s2">&quot;github:hercules-ci/flake-parts&quot;</span><span class="tok-p">;</span>
haskell-flake<span class="tok-o">.</span><span class="tok-ss">url</span> <span class="tok-o">=</span> <span class="tok-s2">&quot;github:srid/haskell-flake&quot;</span><span class="tok-p">;</span>
pandoc-linear-table<span class="tok-o">.</span><span class="tok-ss">url</span> <span class="tok-o">=</span> <span class="tok-s2">&quot;/home/amy/github/pandoc-linear-table&quot;</span><span class="tok-p">;</span>
pandoc-logic-proof<span class="tok-o">.</span><span class="tok-ss">url</span> <span class="tok-o">=</span> <span class="tok-s2">&quot;/home/amy/github/pandoc-logic-proof&quot;</span><span class="tok-p">;</span>
pandoc-columns<span class="tok-o">.</span><span class="tok-ss">url</span> <span class="tok-o">=</span> <span class="tok-s2">&quot;/home/amy/github/pandoc-columns&quot;</span><span class="tok-p">;</span>
pandoc-query<span class="tok-o">.</span><span class="tok-ss">url</span> <span class="tok-o">=</span> <span class="tok-s2">&quot;/home/amy/codeberg/pandoc-query&quot;</span><span class="tok-p">;</span>
<span class="tok-p">};</span>
<span class="tok-ss">outputs</span> <span class="tok-o">=</span> inputs<span class="tok-p">@{</span> self<span class="tok-p">,</span> nixpkgs<span class="tok-p">,</span> flake-parts<span class="tok-p">,</span> pandoc-linear-table<span class="tok-p">,</span> pandoc-logic-proof<span class="tok-p">,</span> pandoc-columns<span class="tok-p">,</span> pandoc-query<span class="tok-p">,</span> <span class="tok-o">...</span> <span class="tok-p">}:</span>
flake-parts<span class="tok-o">.</span>lib<span class="tok-o">.</span>mkFlake <span class="tok-p">{</span> <span class="tok-k">inherit</span> inputs<span class="tok-p">;</span> <span class="tok-p">}</span> <span class="tok-p">{</span>
<span class="tok-ss">systems</span> <span class="tok-o">=</span> nixpkgs<span class="tok-o">.</span>lib<span class="tok-o">.</span>systems<span class="tok-o">.</span>flakeExposed<span class="tok-p">;</span>
<span class="tok-ss">imports</span> <span class="tok-o">=</span> <span class="tok-p">[</span> inputs<span class="tok-o">.</span>haskell-flake<span class="tok-o">.</span>flakeModule <span class="tok-p">];</span>
<span class="tok-ss">perSystem</span> <span class="tok-o">=</span> <span class="tok-p">{</span> self&#39;<span class="tok-p">,</span> pkgs<span class="tok-p">,</span> <span class="tok-o">...</span> <span class="tok-p">}:</span> <span class="tok-p">{</span>
haskellProjects<span class="tok-o">.</span><span class="tok-ss">default</span> <span class="tok-o">=</span> <span class="tok-p">{</span>
<span class="tok-c1"># use my versions of some Haskell pagkages instead of the nixpkgs versions</span>
<span class="tok-ss">packages</span> <span class="tok-o">=</span> <span class="tok-p">{</span>
pandoc-linear-table<span class="tok-o">.</span><span class="tok-ss">source</span> <span class="tok-o">=</span> inputs<span class="tok-o">.</span>pandoc-linear-table<span class="tok-p">;</span>
pandoc-logic-proof<span class="tok-o">.</span><span class="tok-ss">source</span> <span class="tok-o">=</span> inputs<span class="tok-o">.</span>pandoc-logic-proof<span class="tok-p">;</span>
pandoc-columns<span class="tok-o">.</span><span class="tok-ss">source</span> <span class="tok-o">=</span> inputs<span class="tok-o">.</span>pandoc-columns<span class="tok-p">;</span>
pandoc-query<span class="tok-o">.</span><span class="tok-ss">source</span> <span class="tok-o">=</span> inputs<span class="tok-o">.</span>pandoc-query<span class="tok-p">;</span>
<span class="tok-p">};</span>
<span class="tok-p">};</span>
<span class="tok-c1"># haskell-flake doesn&#39;t set the default package, but you can do it here.</span>
packages<span class="tok-o">.</span><span class="tok-ss">default</span> <span class="tok-o">=</span> self&#39;<span class="tok-o">.</span>packages<span class="tok-o">.</span>pandoc-maths-web<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>Here&#8217;s a demonstration using the shell.</p>
</div>
<div class="literalblock">
<div class="content">
<pre class="nowrap">$ nix develop
$ cabal info pandoc-columns
Warning: The package list for 'hackage.haskell.org' is 22 days old.
Run 'cabal update' to get the latest list of available packages.
* pandoc-columns (program and library)
Synopsis: A pandoc filter that provides a Markdown extension for
columns.
Versions available: 0.2.0.5
Versions installed: [ Not installed ]
Homepage: https://github.com/mhwombat/pandoc-columns
Bug reports: https://github.com/mhwombat/pandoc-columns/issues
Description: For more information and a tutorial on how to use this
package, please see the README at
&lt;https://github.com/mhwombat/pandoc-columns#readme&gt;.
Category: Text
License: BSD-3-Clause
Author: Amy de Buitléir
Maintainer: amy@nualeargais.ie
Source repo: https://github.com/mhwombat/pandoc-columns.git
Executables: pandoc-columns
Dependencies: base &gt;=4.16.4 &amp;&amp; &lt;4.17, pandoc-types &gt;=1.22.2 &amp;&amp; &lt;1.23,
pandoc &gt;=2.19.2 &amp;&amp; &lt;2.20, base &gt;=4.16.4 &amp;&amp; &lt;4.17,
pandoc-types &gt;=1.22.2 &amp;&amp; &lt;1.23, pandoc-columns
Cached: No
Modules:
Text.Pandoc.Filters.Columns</pre>
</div>
</div>
<div class="paragraph">
<p>FINISH</p>
</div>
<div class="paragraph">
<p>FINISH</p>
</div>
<div class="paragraph">
<p>FINISH</p>
</div>
<div class="paragraph">
<p>FINISH</p>
</div>
<div class="paragraph">
<p>FINISH</p>
</div>
<div class="paragraph">
<p>FINISH</p>
</div>
<div class="paragraph">
<p>FINISH</p>
</div>
<div class="paragraph">
<p>FINISH</p>
</div>
</div>
<div class="sect3">
<h4 id="_set_an_environment_variable">10.4.5. Set an environment variable</h4>
<h4 id="_set_an_environment_variable">10.4.4. Set an environment variable</h4>
<div class="paragraph">
<p>Set the value of the environment variable FOO to “bar”.</p>
</div>
@ -5105,10 +4968,10 @@ FOO=bar</pre>
</div>
</div>
<div class="sect3">
<h4 id="devshell-nix-non-flake">10.4.6. Access a non-flake package (not in nixpkgs)</h4>
<h4 id="devshell-nix-non-flake">10.4.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;Flakes&#8221;</a>.</p>
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>
</div>
<div class="paragraph">
<p>The <code>hello-nix</code> <a href="https://codeberg.org/mhwombat/hello-nix">repo</a> provides a <code>default.nix</code>.
@ -5126,7 +4989,7 @@ If instead it requires <code>&lt;nixpkgs&gt;</code>, it is not pure and we canno
</div>
<div class="paragraph">
<p>then it requires <code>nixpkgs</code> so we cannot use it.
Instead, we have to write our own derivation (see <a href="#devshell-impure">Section 10.4.6.2, &#8220;If the nix derivation requires <code>nixpkgs</code>&#8221;</a>).</p>
Instead, we have to write our own derivation (see <a href="#devshell-impure">Section 10.4.5.2, &#8220;If the nix derivation requires <code>nixpkgs</code>&#8221;</a>).</p>
</div>
<div class="paragraph">
<p>Fortunately the file begins with</p>
@ -5139,7 +5002,7 @@ Instead, we have to write our own derivation (see <a href="#devshell-impure">Sec
<div class="paragraph">
<p>then it accepts a package set as an argument,
only using <code>&lt;nixpkgs&gt;</code> if no argument is provided.
We can use it directly to build <code>hello-nix</code> (see <a href="#devshell-pure">Section 10.4.6.1, &#8220;If the nix derivation does not require nixpkgs&#8221;</a>).</p>
We can use it directly to build <code>hello-nix</code> (see <a href="#devshell-pure">Section 10.4.5.1, &#8220;If the nix derivation does not require nixpkgs&#8221;</a>).</p>
</div>
<div class="sect4">
<h5 id="devshell-pure">If the nix derivation does not require nixpkgs</h5>
@ -5378,10 +5241,10 @@ building '/nix/store/rlg4ym95l3jh9mv2mc1yd6qf0i2px844-hello-with-cow.drv'...
<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, &#8220;Flakes&#8221;</a>.</p>
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>
</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, &#8220;Access a non-flake package (not in nixpkgs)&#8221;</a>;
<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.5, &#8220;Access a non-flake package (not in nixpkgs)&#8221;</a>;
here we will focus on making it available at runtime.
We will write a flake to package a very simple shell script.
All it does is invoke <code>hello-nix</code>, which is the input we added <a href="#devshell-nix-non-flake">earlier</a>.</p>
@ -5511,7 +5374,7 @@ hello-nix
</div>
</div>
<div class="paragraph">
<p>Lines 5-8 and 17 were explained in <a href="#devshell-nix-non-flake">Section 10.4.6, &#8220;Access a non-flake package (not in nixpkgs)&#8221;</a>.
<p>Lines 5-8 and 17 were explained in <a href="#devshell-nix-non-flake">Section 10.4.5, &#8220;Access a non-flake package (not in nixpkgs)&#8221;</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&#8217;t put it on the path,
so our <code>hello-again</code> script won&#8217;t be able to find it.</p>
@ -5598,7 +5461,7 @@ Hello from your flake!</pre>
</div>
<div id="footer">
<div id="footer-text">
Last updated 2025-09-14 20:52:56 IST
Last updated 2025-09-15 14:41:47 IST
</div>
</div>
</body>

View file

@ -42,7 +42,7 @@ directly available.
....
$# echo executable=$(which hello-flake) > temp.sh # save variable
$ exit
$ hello-flake # Won't work outside development shell
$ hello-flake # Fails outside development shell
....
However, we can still run the command using the store path we found

View file

@ -99,7 +99,7 @@ $# cat hello-flake
Let's test the modified script.
....
$ ./hello-flake # Won't work
$ ./hello-flake # Fails
....
What went wrong? Remember that we are in a _development_ shell. Since
@ -140,7 +140,7 @@ $ exit
Let's try `nix run`.
....
$ nix run # Won't work
$ nix run # Fails
....
What went wrong?

View file

@ -70,7 +70,7 @@ Let's enter a shell with the Glasgow Haskell Compiler ("ghc") and try to run the
....
$# echo '$ nix shell nixpkgs#ghc'
$# nix shell nixpkgs#ghc --command sh
$ runghc Main.hs # Won't work
$ runghc Main.hs # Fails
....
The error message tells us that we need the module `Network.HostName`.
@ -81,7 +81,7 @@ Let's exit that shell and try again, this time adding the `hostname` package.
$# echo '$ exit'
$# echo '$ nix shell nixpkgs#ghc nixpkgs#hostname'
$# nix shell nixpkgs#ghc nixpkgs#hostname --command sh
$ runghc Main.hs # Won't work
$ runghc Main.hs # Fails
....
That reason that failed is that we asked for the wrong package.
@ -95,7 +95,7 @@ Let's try that again, with the correct package.
$# echo '$ exit'
$# echo '$ nix shell nixpkgs#ghc nixpkgs#haskellPackages.hostname'
$# nix shell nixpkgs#ghc nixpkgs#haskellPackages.hostname --command sh
$ runghc Main.hs # Won't work
$ runghc Main.hs # Fails
....
Now what's wrong?

View file

@ -101,7 +101,7 @@ We won't write `flake.nix` just yet.
First we'll try building the package manually.
(If you didn't run the `nix shell` command from <<python-nix-shell,earlier>>, do so now.)
....
$ python -m build # Won't work
$ python -m build # Fails
....
The missing module error happens because we don't have `build` available
@ -198,7 +198,7 @@ $# cat flake.nix
Let's try out the new flake.
....
$ nix build # Won't work
$ nix build # Fails
....
Nix flakes only "`see`" files that are part of the repository.

View file

@ -42,7 +42,7 @@ we see that this flake provides both a package and an app called `hello`.
Here's a demonstration using the shell.
....
$ hello-flake # Won't work; dependency not available
$ hello-flake # Fails; dependency not available
$# ../../../../../start-shell nix develop <<EOL
$ hello-flake # Works in development environment
$# EOL

View file

@ -72,11 +72,11 @@
},
"nixpkgs_2": {
"locked": {
"lastModified": 1757876592,
"narHash": "sha256-P8XdKg87fR5PpCjIgMH+05PDwhdmlNrigsvChdHfyaw=",
"lastModified": 1757942231,
"narHash": "sha256-yM1FFsRiyESij/lzbdBMCUoFOKMoShHu0CAexnBWzTM=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "5ad881b15fb2b63c2f127533ca59f840fcc24c3f",
"rev": "dd16e0b60390586a261a4e28fc180a91212fe010",
"type": "github"
},
"original": {

View file

@ -1,6 +1,6 @@
import Data.List.Extra
import Text.Pandoc.Filters.Columns
main :: IO ()
main = do
print $ lower "ABCDE"
print $ upper "XYZ"
putStrLn "Prove we have access to the pandoc-columns package"
print $ defaultColSpec

View file

@ -2,13 +2,14 @@
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
pandoc-columns.url = "/home/amy/github/pandoc-columns";
};
outputs = { self, nixpkgs, flake-utils }:
outputs = { self, nixpkgs, flake-utils, pandoc-columns }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
customGhc = pkgs.haskellPackages.ghcWithPackages (p: with p; [ extra ]);
customGhc = pkgs.haskellPackages.ghcWithPackages (p: with p; [ pandoc-columns ]);
in
{
devShells = rec {

View file

@ -38,7 +38,7 @@ include::Main.hs[]
Here's a demonstration using the program.
....
$ runghc Main.hs # Won't work; dependency not available
$ runghc Main.hs # Fails; dependency not available
$# ../../../../../start-shell nix develop <<EOL
$ runghc Main.hs # Works in development environemnt
$# EOL

View file

@ -6,7 +6,7 @@ include::flake/main-generated.adoc[leveloffset=+1]
include::haskell-pkg/main-generated.adoc[leveloffset=+1]
include::haskell-flake/main-generated.adoc[leveloffset=+1]
// TODO include::haskell-flake/main-generated.adoc[leveloffset=+1]
include::env-var/main-generated.adoc[leveloffset=+1]

View file

@ -19,7 +19,7 @@ $# cat flake.nix
Here's a demonstration using the shell.
....
$ cowsay "Moo!" # Won't work; dependency not available
$ cowsay "Moo!" # Fails; dependency not available
$# ../../../../../start-shell nix develop <<EOL
$ cowsay "Moo!" # Works in development environment
$# EOL

View file

@ -7,7 +7,7 @@ $ nix run nixpkgs#cowsay "Moo!"
....
[#flakeref]
== Flakes
== Run a flake
=== Run a flake defined in a local file