This commit is contained in:
Amy de Buitléir 2025-09-06 18:03:15 +01:00
parent fe36ee45a4
commit abb77f90f8
15 changed files with 207 additions and 262 deletions

View file

@ -172,14 +172,14 @@
<ul class="sectlevel2">
<li><a href="#_running_programs_directly_without_installing_them">10.1. Running programs directly (without installing them)</a>
<ul class="sectlevel3">
<li><a href="#_a_top_level_package_from_the_nixpkgsnixos_repo">10.1.1. A top level package from the Nixpkgs/NixOS repo</a></li>
<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>
<ul class="sectlevel4">
<li><a href="#_a_flake_defined_in_a_local_file">A flake defined in a local file</a></li>
<li><a href="#_a_flake_defined_in_a_remote_git_repo">A flake defined in a remote git repo</a></li>
<li><a href="#_a_flake_defined_in_a_zip_archive">A flake defined in a zip archive</a></li>
<li><a href="#_a_flake_defined_in_a_compressed_tar_archive">A flake defined in a compressed tar archive</a></li>
<li><a href="#_other_types_of_flake_references">Other types of flake references</a></li>
<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>
<li><a href="#_run_a_flake_defined_in_a_zip_archive">Run a flake defined in a zip archive</a></li>
<li><a href="#_run_a_flake_defined_in_a_compressed_tar_archive">Run a flake defined in a compressed tar archive</a></li>
<li><a href="#_run_other_types_of_flake_references">Run other types of flake references</a></li>
</ul>
</li>
</ul>
@ -200,27 +200,14 @@
</li>
<li><a href="#_development_shells">10.4. Development shells</a>
<ul class="sectlevel3">
<li><a href="#_a_top_level_package_from_the_nixpkgsnixos_repo_2">10.4.1. A top level package from the Nixpkgs/NixOS repo</a></li>
<li><a href="#_a_flake">10.4.2. A flake</a></li>
<li><a href="#_a_haskell_library_package_in_the_nixpkgs_repo_without_a_cabal_file">10.4.3. A Haskell library package in the nixpkgs repo (without a <code>.cabal</code> file)</a></li>
<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_on_your_local_computer">10.4.4. Access to a Haskell package on your local computer</a></li>
<li><a href="#_set_an_environment_variable">10.4.5. Set an environment variable</a></li>
</ul>
</li>
<li><a href="#_an_old_style_nix_shell_with_access_to_a_flake">10.5. An (old-style) Nix shell with access to a flake</a></li>
<li><a href="#_access_to_a_haskell_package_on_your_local_computer">10.6. Access to a Haskell package on your local computer</a>
<ul class="sectlevel3">
<li><a href="#_in_shell_nix">10.6.1. In <code>shell.nix</code></a></li>
</ul>
</li>
<li><a href="#_access_to_a_haskell_package_on_your_local_computer_with_inter_dependencies">10.7. Access to a Haskell package on your local computer, with inter-dependencies</a>
<ul class="sectlevel3">
<li><a href="#_in_shell_nix_2">10.7.1. In <code>shell.nix</code></a></li>
</ul>
</li>
<li><a href="#_set_an_environment_variable">10.8. Set an environment variable</a>
<ul class="sectlevel3">
<li><a href="#_in_shell_nix_3">10.8.1. In <code>shell.nix</code></a></li>
</ul>
</li>
</ul>
</li>
</ul>
@ -4039,7 +4026,7 @@ including defining environments that you will use more than once.</p>
<div class="sect2">
<h3 id="_running_programs_directly_without_installing_them">10.1. Running programs directly (without installing them)</h3>
<div class="sect3">
<h4 id="_a_top_level_package_from_the_nixpkgsnixos_repo">10.1.1. A top level package from the Nixpkgs/NixOS repo</h4>
<h4 id="_run_a_top_level_package_from_the_nixpkgsnixos_repo">10.1.1. Run a top level package from the Nixpkgs/NixOS repo</h4>
<div class="literalblock">
<div class="content">
<pre class="nowrap">$ nix run nixpkgs#cowsay "Moo!"
@ -4057,7 +4044,7 @@ including defining environments that you will use more than once.</p>
<div class="sect3">
<h4 id="flakeref">10.1.2. Flakes</h4>
<div class="sect4">
<h5 id="_a_flake_defined_in_a_local_file">A flake defined in a local file</h5>
<h5 id="_run_a_flake_defined_in_a_local_file">Run a flake defined in a local file</h5>
<div class="literalblock">
<div class="content">
<pre class="nowrap">$ nix run ~/codeberg/hello-flake
@ -4066,7 +4053,7 @@ Hello from your flake!</pre>
</div>
</div>
<div class="sect4">
<h5 id="_a_flake_defined_in_a_remote_git_repo">A flake defined in a remote git repo</h5>
<h5 id="_run_a_flake_defined_in_a_remote_git_repo">Run a flake defined in a remote git repo</h5>
<div class="literalblock">
<div class="content">
<pre class="nowrap">$ nix run git+https://codeberg.org/mhwombat/hello-flake
@ -4093,7 +4080,7 @@ To run a specific branch, use the command below.</p>
</div>
</div>
<div class="sect4">
<h5 id="_a_flake_defined_in_a_zip_archive">A flake defined in a zip archive</h5>
<h5 id="_run_a_flake_defined_in_a_zip_archive">Run a flake defined in a zip archive</h5>
<div class="literalblock">
<div class="content">
<pre class="nowrap">$ nix run https://codeberg.org/mhwombat/hello-flake/archive/main.zip
@ -4103,7 +4090,7 @@ Hello from your flake!</pre>
</div>
</div>
<div class="sect4">
<h5 id="_a_flake_defined_in_a_compressed_tar_archive">A flake defined in a compressed tar archive</h5>
<h5 id="_run_a_flake_defined_in_a_compressed_tar_archive">Run a flake defined in a compressed tar archive</h5>
<div class="literalblock">
<div class="content">
<pre class="nowrap">$ nix run https://codeberg.org/mhwombat/hello-flake/archive/main.tar.gz
@ -4113,7 +4100,7 @@ Hello from your flake!</pre>
</div>
</div>
<div class="sect4">
<h5 id="_other_types_of_flake_references">Other types of flake references</h5>
<h5 id="_run_other_types_of_flake_references">Run other types of flake references</h5>
<div class="paragraph">
<p>See <a href="https://nix.dev/manual/nix/stable/command-ref/new-cli/nix3-flake#flake-reference-attributes" class="bare">https://nix.dev/manual/nix/stable/command-ref/new-cli/nix3-flake#flake-reference-attributes</a>.</p>
</div>
@ -4318,7 +4305,7 @@ sanitized: &lt;strong&gt;some text&lt;/strong&gt;</pre>
<div class="sect2">
<h3 id="_development_shells">10.4. Development shells</h3>
<div class="sect3">
<h4 id="_a_top_level_package_from_the_nixpkgsnixos_repo_2">10.4.1. A top level package from the Nixpkgs/NixOS repo</h4>
<h4 id="_access_a_top_level_package_from_the_nixpkgsnixos_repo_3">10.4.1. Access a top level package from the Nixpkgs/NixOS repo</h4>
<div class="listingblock">
<div class="title">flake.nix</div>
<div class="content">
@ -4385,7 +4372,7 @@ $ cowsay "Moo!"
</div>
</div>
<div class="sect3">
<h4 id="_a_flake">10.4.2. A flake</h4>
<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>
@ -4503,7 +4490,7 @@ Hello from your flake!</pre>
</div>
</div>
<div class="sect3">
<h4 id="_a_haskell_library_package_in_the_nixpkgs_repo_without_a_cabal_file">10.4.3. A Haskell library package in the nixpkgs repo (without a <code>.cabal</code> file)</h4>
<h4 id="_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)</h4>
<div class="paragraph">
<p>Occasionally you might want to run a short Haskell program that depends on a Haskell library,
but you don&#8217;t want to bother writing a cabal file.</p>
@ -4598,6 +4585,136 @@ $ runghc Main.hs
"I have 3 cats, 2 dogs, and 0 zebras."</pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_access_to_a_haskell_package_on_your_local_computer">10.4.4. Access to a Haskell package on your local computer</h4>
<div class="paragraph">
<p>Ex: Access three Haskell packages
(<code>pandoc-linear-table</code>, <code>pandoc-logic-proof</code>, and <code>pandoc-columns</code>)
that are on my hard drive.</p>
</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></pre></div></td><td class="code"><div><pre style="line-height: 125%;"><span></span>{
<span style="color: #19177C">description</span> <span style="color: #666666">=</span> <span style="color: #BA2121">&quot;Pandoc build system for maths web&quot;</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">&quot;github:nixos/nixpkgs/nixpkgs-unstable&quot;</span>;
flake-parts<span style="color: #666666">.</span><span style="color: #19177C">url</span> <span style="color: #666666">=</span> <span style="color: #BA2121">&quot;github:hercules-ci/flake-parts&quot;</span>;
haskell-flake<span style="color: #666666">.</span><span style="color: #19177C">url</span> <span style="color: #666666">=</span> <span style="color: #BA2121">&quot;github:srid/haskell-flake&quot;</span>;
pandoc-linear-table<span style="color: #666666">.</span><span style="color: #19177C">url</span> <span style="color: #666666">=</span> <span style="color: #BA2121">&quot;/home/amy/github/pandoc-linear-table&quot;</span>;
pandoc-logic-proof<span style="color: #666666">.</span><span style="color: #19177C">url</span> <span style="color: #666666">=</span> <span style="color: #BA2121">&quot;/home/amy/github/pandoc-logic-proof&quot;</span>;
pandoc-columns<span style="color: #666666">.</span><span style="color: #19177C">url</span> <span style="color: #666666">=</span> <span style="color: #BA2121">&quot;/home/amy/github/pandoc-columns&quot;</span>;
pandoc-query<span style="color: #666666">.</span><span style="color: #19177C">url</span> <span style="color: #666666">=</span> <span style="color: #BA2121">&quot;/home/amy/codeberg/pandoc-query&quot;</span>;
};
<span style="color: #19177C">outputs</span> <span style="color: #666666">=</span> inputs@{ self, nixpkgs, flake-parts, pandoc-linear-table, pandoc-logic-proof, pandoc-columns, pandoc-query, <span style="color: #666666">...</span> }:
flake-parts<span style="color: #666666">.</span>lib<span style="color: #666666">.</span>mkFlake { <span style="color: #008000; font-weight: bold">inherit</span> inputs; } {
<span style="color: #19177C">systems</span> <span style="color: #666666">=</span> nixpkgs<span style="color: #666666">.</span>lib<span style="color: #666666">.</span>systems<span style="color: #666666">.</span>flakeExposed;
<span style="color: #19177C">imports</span> <span style="color: #666666">=</span> [ inputs<span style="color: #666666">.</span>haskell-flake<span style="color: #666666">.</span>flakeModule ];
<span style="color: #19177C">perSystem</span> <span style="color: #666666">=</span> { self&#39;, pkgs, <span style="color: #666666">...</span> }: {
haskellProjects<span style="color: #666666">.</span><span style="color: #19177C">default</span> <span style="color: #666666">=</span> {
<span style="color: #3D7B7B; font-style: italic"># use my versions of some Haskell pagkages instead of the nixpkgs versions</span>
<span style="color: #19177C">packages</span> <span style="color: #666666">=</span> {
pandoc-linear-table<span style="color: #666666">.</span><span style="color: #19177C">source</span> <span style="color: #666666">=</span> inputs<span style="color: #666666">.</span>pandoc-linear-table;
pandoc-logic-proof<span style="color: #666666">.</span><span style="color: #19177C">source</span> <span style="color: #666666">=</span> inputs<span style="color: #666666">.</span>pandoc-logic-proof;
pandoc-columns<span style="color: #666666">.</span><span style="color: #19177C">source</span> <span style="color: #666666">=</span> inputs<span style="color: #666666">.</span>pandoc-columns;
pandoc-query<span style="color: #666666">.</span><span style="color: #19177C">source</span> <span style="color: #666666">=</span> inputs<span style="color: #666666">.</span>pandoc-query;
};
};
<span style="color: #3D7B7B; font-style: italic"># haskell-flake doesn&#39;t set the default package, but you can do it here.</span>
packages<span style="color: #666666">.</span><span style="color: #19177C">default</span> <span style="color: #666666">=</span> self&#39;<span style="color: #666666">.</span>packages<span style="color: #666666">.</span>pandoc-maths-web;
};
};
}
</pre></div></td></tr></table></div></code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_set_an_environment_variable">10.4.5. Set an environment variable</h4>
<div class="paragraph">
<p>Set the value of the environment variable FOO to “bar”.</p>
</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></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">&quot;github:NixOS/nixpkgs&quot;</span>;
flake-utils<span style="color: #666666">.</span><span style="color: #19177C">url</span> <span style="color: #666666">=</span> <span style="color: #BA2121">&quot;github:numtide/flake-utils&quot;</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">devShells</span> <span style="color: #666666">=</span> <span style="color: #008000; font-weight: bold">rec</span> {
<span style="color: #19177C">default</span> <span style="color: #666666">=</span> pkgs<span style="color: #666666">.</span>mkShell {
<span style="color: #19177C">packages</span> <span style="color: #666666">=</span> [ pkgs<span style="color: #666666">.</span>cowsay ];
};
};
}
);
}
</pre></div></td></tr></table></div></code></pre>
</div>
</div>
<div class="paragraph">
<p>/// SKIP include::non-flake/main-generated.adoc[leveloffset=+1]</p>
</div>
@ -4648,131 +4765,6 @@ Hello from your flake!</pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_access_to_a_haskell_package_on_your_local_computer">10.6. Access to a Haskell package on your local computer</h3>
<div class="paragraph">
<p>Ex: Access three Haskell packages
(<code>pandoc-linear-table</code>, <code>pandoc-logic-proof</code>, and <code>pandoc-columns</code>)
that are on my hard drive.</p>
</div>
<div class="sect3">
<h4 id="_in_shell_nix">10.6.1. In <code>shell.nix</code></h4>
<div class="listingblock">
<div class="title">shell.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></pre></div></td><td class="code"><div><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">with</span> (<span style="color: #008000">import</span> &lt;nixpkgs&gt; {});
<span style="color: #008000; font-weight: bold">let</span>
<span style="color: #19177C">pandoc-linear-table</span> <span style="color: #666666">=</span> haskellPackages<span style="color: #666666">.</span>callCabal2nix <span style="color: #BA2121">&quot;pandoc-linear-table&quot;</span> /home/amy/github/pandoc-linear-table {};
<span style="color: #19177C">pandoc-logic-proof</span> <span style="color: #666666">=</span> haskellPackages<span style="color: #666666">.</span>callCabal2nix <span style="color: #BA2121">&quot;pandoc-logic-proof&quot;</span> /home/amy/github/pandoc-logic-proof {};
<span style="color: #19177C">pandoc-columns</span> <span style="color: #666666">=</span> haskellPackages<span style="color: #666666">.</span>callCabal2nix <span style="color: #BA2121">&quot;pandoc-columns&quot;</span> /home/amy/github/pandoc-columns {};
<span style="color: #008000; font-weight: bold">in</span>
mkShell {
<span style="color: #19177C">buildInputs</span> <span style="color: #666666">=</span> [
pandoc
pandoc-linear-table
pandoc-logic-proof
pandoc-columns
];
}
</pre></div></td></tr></table></div></code></pre>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_access_to_a_haskell_package_on_your_local_computer_with_inter_dependencies">10.7. Access to a Haskell package on your local computer, with inter-dependencies</h3>
<div class="paragraph">
<p>Ex: Access four Haskell packages
(<code>pandoc-linear-table</code>, <code>pandoc-logic-proof</code>, <code>pandoc-columns</code> and <code>pandoc-maths-web</code>)
that are on my hard drive.
The fourth package depends on the first three to build.</p>
</div>
<div class="sect3">
<h4 id="_in_shell_nix_2">10.7.1. In <code>shell.nix</code></h4>
<div class="listingblock">
<div class="title">shell.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></pre></div></td><td class="code"><div><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">with</span> (<span style="color: #008000">import</span> &lt;nixpkgs&gt; {});
<span style="color: #008000; font-weight: bold">let</span>
<span style="color: #19177C">pandoc-linear-table</span> <span style="color: #666666">=</span> haskellPackages<span style="color: #666666">.</span>callCabal2nix <span style="color: #BA2121">&quot;pandoc-linear-table&quot;</span> /home/amy/github/pandoc-linear-table {};
<span style="color: #19177C">pandoc-logic-proof</span> <span style="color: #666666">=</span> haskellPackages<span style="color: #666666">.</span>callCabal2nix <span style="color: #BA2121">&quot;pandoc-logic-proof&quot;</span> /home/amy/github/pandoc-logic-proof {};
<span style="color: #19177C">pandoc-columns</span> <span style="color: #666666">=</span> haskellPackages<span style="color: #666666">.</span>callCabal2nix <span style="color: #BA2121">&quot;pandoc-columns&quot;</span> /home/amy/github/pandoc-columns {};
<span style="color: #19177C">pandoc-maths-web</span> <span style="color: #666666">=</span> haskellPackages<span style="color: #666666">.</span>callCabal2nix <span style="color: #BA2121">&quot;pandoc-maths-web&quot;</span> /home/amy/github/pandoc-maths-web
{
<span style="color: #008000; font-weight: bold">inherit</span> pandoc-linear-table pandoc-logic-proof pandoc-columns;
};
<span style="color: #008000; font-weight: bold">in</span>
mkShell {
<span style="color: #19177C">buildInputs</span> <span style="color: #666666">=</span> [
pandoc
pandoc-linear-table
pandoc-logic-proof
pandoc-columns
pandoc-maths-web
];
}
</pre></div></td></tr></table></div></code></pre>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_set_an_environment_variable">10.8. Set an environment variable</h3>
<div class="paragraph">
<p>Ex: Set the value of the environment variable FOO to &#8220;bar&#8221;</p>
</div>
<div class="sect3">
<h4 id="_in_shell_nix_3">10.8.1. In <code>shell.nix</code></h4>
<div class="listingblock">
<div class="title">shell.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></pre></div></td><td class="code"><div><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">with</span> (<span style="color: #008000">import</span> &lt;nixpkgs&gt; {});
mkShell {
<span style="color: #19177C">shellHook</span> <span style="color: #666666">=</span> <span style="color: #BA2121">&#39;&#39;</span>
<span style="color: #BA2121"> export FOO=&quot;bar&quot;</span>
<span style="color: #BA2121"> &#39;&#39;</span>;
}
</pre></div></td></tr></table></div></code></pre>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
@ -4787,7 +4779,7 @@ mkShell {
</div>
<div id="footer">
<div id="footer-text">
Last updated 2025-09-05 20:39:24 IST
Last updated 2025-09-06 17:58:13 IST
</div>
</div>
</body>

View file

@ -0,0 +1,33 @@
= Set an environment variable
////
$ mkdir tempwork
$ cd tempwork
$ cp ../flake.nix flake.nix
$ git add flake.nix
$ nix develop
$ git add flake.lock
$ git commit -a -m temp
////
Set the value of the environment variable FOO to “bar”.
[source,nix,linenums]
.flake.nix
....
$# cat flake.nix
....
Here's a demonstration using the shell.
....
$ echo "FOO=$FOO"
$# ../../../../../start-shell nix develop <<EOL
$ echo "FOO=$FOO"
$# EOL
....
////
Good adoc0 scripts clean up after themselves.
$ cd .. ; rm -rf tempwork # clean up
////

View file

@ -20,11 +20,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1757172738,
"narHash": "sha256-wt4izkhUOlFBMt6Zc4TRG8U769Iq79l5rAU1W5aevVg=",
"lastModified": 1757177463,
"narHash": "sha256-+0iaqsEjfaIZMuRNGO+wC0uVazT5b+W38wB7Uv0kA5Y=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "3ef96d876cd8cb511b809a942dc5e1072636b85b",
"rev": "9aaf71a4a74d835ec05ac3ddf5fc1b859e005c41",
"type": "github"
},
"original": {

View file

@ -8,12 +8,13 @@
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
customGhc = pkgs.haskellPackages.ghcWithPackages (p: with p; [ containers ]);
in
{
devShells = rec {
default = pkgs.mkShell {
buildInputs = [ customGhc ];
shellHook = ''
export FOO="bar"
'';
};
};
}

View file

@ -4,4 +4,10 @@ Ex: Access three Haskell packages
(`pandoc-linear-table`, `pandoc-logic-proof`, and `pandoc-columns`)
that are on my hard drive.
include::shell/main-generated.adoc[leveloffset=+1]
[source,nix,linenums]
.flake.nix
....
include::flake.nix[]
....
// TODO Add demo

View file

@ -6,5 +6,9 @@ include::flake/main-generated.adoc[leveloffset=+1]
include::haskell-pkg/main-generated.adoc[leveloffset=+1]
include::haskell-flake/main-generated.adoc[leveloffset=+1]
include::env-var/main-generated.adoc[leveloffset=+1]
/// SKIP include::non-flake/main-generated.adoc[leveloffset=+1]

View file

@ -1,5 +0,0 @@
= Set an environment variable
Ex: Set the value of the environment variable FOO to "`bar`"
include::shell/main-generated.adoc[leveloffset=+1]

View file

@ -1,21 +0,0 @@
= In `shell.nix`
[source,nix,linenums]
.shell.nix
....
include::shell.nix[]
....
////
TODO FIX
Here's a demonstration using the shell.
....
$# echo '$ nix-shell'
$# nix-shell --run bash <<EOL
$ echo "FOO=$FOO"
$# EOL
....
////

View file

@ -1,8 +0,0 @@
= Access to a Haskell package on your local computer, with inter-dependencies
Ex: Access four Haskell packages
(`pandoc-linear-table`, `pandoc-logic-proof`, `pandoc-columns` and `pandoc-maths-web`)
that are on my hard drive.
The fourth package depends on the first three to build.
include::shell/main-generated.adoc[leveloffset=+1]

View file

@ -1,9 +0,0 @@
= In `shell.nix`
[source,nix,linenums]
.shell.nix
....
include::shell.nix[]
....
// TODO add demo

View file

@ -1,19 +0,0 @@
with (import <nixpkgs> {});
let
pandoc-linear-table = haskellPackages.callCabal2nix "pandoc-linear-table" /home/amy/github/pandoc-linear-table {};
pandoc-logic-proof = haskellPackages.callCabal2nix "pandoc-logic-proof" /home/amy/github/pandoc-logic-proof {};
pandoc-columns = haskellPackages.callCabal2nix "pandoc-columns" /home/amy/github/pandoc-columns {};
pandoc-maths-web = haskellPackages.callCabal2nix "pandoc-maths-web" /home/amy/github/pandoc-maths-web
{
inherit pandoc-linear-table pandoc-logic-proof pandoc-columns;
};
in
mkShell {
buildInputs = [
pandoc
pandoc-linear-table
pandoc-logic-proof
pandoc-columns
pandoc-maths-web
];
}

View file

@ -1,9 +0,0 @@
= In `shell.nix`
[source,nix,linenums]
.shell.nix
....
include::shell.nix[]
....
// TODO Add demo

View file

@ -1,14 +0,0 @@
with (import <nixpkgs> {});
let
pandoc-linear-table = haskellPackages.callCabal2nix "pandoc-linear-table" /home/amy/github/pandoc-linear-table {};
pandoc-logic-proof = haskellPackages.callCabal2nix "pandoc-logic-proof" /home/amy/github/pandoc-logic-proof {};
pandoc-columns = haskellPackages.callCabal2nix "pandoc-columns" /home/amy/github/pandoc-columns {};
in
mkShell {
buildInputs = [
pandoc
pandoc-linear-table
pandoc-logic-proof
pandoc-columns
];
}

View file

@ -21,9 +21,3 @@ include::shebang/main.adoc[leveloffset=+1]
include::devshell/main.adoc[leveloffset=+1]
include::nix-shell/main-generated.adoc[leveloffset=+1]
include::haskell-local/main.adoc[leveloffset=+1]
include::haskell-local-deps/main.adoc[leveloffset=+1]
include::env-var/main.adoc[leveloffset=+1]

View file

@ -1,6 +1,6 @@
= Running programs directly (without installing them)
== A top level package from the Nixpkgs/NixOS repo
== Run a top level package from the Nixpkgs/NixOS repo
....
$ nix run nixpkgs#cowsay "Moo!"
@ -9,13 +9,13 @@ $ nix run nixpkgs#cowsay "Moo!"
[#flakeref]
== Flakes
=== A flake defined in a local file
=== Run a flake defined in a local file
....
$ nix run ~/codeberg/hello-flake
....
=== A flake defined in a remote git repo
=== Run a flake defined in a remote git repo
....
$ nix run git+https://codeberg.org/mhwombat/hello-flake
@ -35,18 +35,18 @@ To run a specific branch and revision, use the command below.
nix run git+https://codeberg.org/mhwombat/hello-flake?ref=main&rev=d44728bce88a6f9d1d37dbf4720ece455e997606
....
=== A flake defined in a zip archive
=== Run a flake defined in a zip archive
....
$ nix run https://codeberg.org/mhwombat/hello-flake/archive/main.zip
....
=== A flake defined in a compressed tar archive
=== Run a flake defined in a compressed tar archive
....
$ nix run https://codeberg.org/mhwombat/hello-flake/archive/main.tar.gz
....
=== Other types of flake references
=== Run other types of flake references
See https://nix.dev/manual/nix/stable/command-ref/new-cli/nix3-flake#flake-reference-attributes.