This commit is contained in:
Amy de Buitléir 2025-09-05 19:59:37 +01:00
parent 3aaa7a299b
commit 54f4db6d26
9 changed files with 98 additions and 311 deletions

View file

@ -194,6 +194,8 @@
<ul class="sectlevel3">
<li><a href="#_a_top_level_package_from_the_nixpkgsnixos_repo_3">10.3.1. A top level package from the Nixpkgs/NixOS repo</a></li>
<li><a href="#_a_flake_2">10.3.2. A flake</a></li>
<li><a href="#_access_to_a_haskell_library_package_in_the_nixpkgs_repo_without_a_cabal_file">10.3.3. Access to a Haskell library package in the nixpkgs repo (without a <code>.cabal</code> file)</a></li>
<li><a href="#_in_a_haskell_script">10.3.4. In a Haskell script</a></li>
</ul>
</li>
<li><a href="#_development_shells_with_access_to">10.4. Development shells with access to&#8230;&#8203;</a>
@ -201,34 +203,27 @@
<li><a href="#_a_top_level_package_from_the_nixpkgsnixos_repo_4">10.4.1. A top level package from the Nixpkgs/NixOS repo</a></li>
<li><a href="#_a_flake_3">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="#_a_non_flake_package_not_in_nixpkgs">10.4.4. 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.5. An (old-style) Nix shell with access to a flake</a></li>
<li><a href="#_access_to_a_package_defined_in_a_remote_git_repo">10.6. Access to a package defined in a remote git repo</a></li>
<li><a href="#_access_to_a_haskell_library_package_in_the_nixpkgs_repo_without_a_cabal_file">10.7. Access to a Haskell library package in the nixpkgs repo (without a <code>.cabal</code> file)</a>
<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_a_haskell_script">10.7.1. In a Haskell script</a></li>
<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">10.8. Access to a Haskell package on your local computer</a>
<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">10.8.1. In <code>shell.nix</code></a></li>
<li><a href="#_in_shell_nix_2">10.7.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.9. Access to a Haskell package on your local computer, with inter-dependencies</a>
<li><a href="#_access_to_a_python_library_package_in_the_nixpkgs_repo_without_using_a_python_builder">10.8. Access to a Python library package in the nixpkgs repo (without using a Python builder)</a>
<ul class="sectlevel3">
<li><a href="#_in_shell_nix_2">10.9.1. In <code>shell.nix</code></a></li>
<li><a href="#_in_a_python_script">10.8.1. In a Python script</a></li>
</ul>
</li>
<li><a href="#_access_to_a_python_library_package_in_the_nixpkgs_repo_without_using_a_python_builder">10.10. Access to a Python library package in the nixpkgs repo (without using a Python builder)</a>
<li><a href="#_set_an_environment_variable">10.9. Set an environment variable</a>
<ul class="sectlevel3">
<li><a href="#_in_a_python_script">10.10.1. In a Python script</a></li>
</ul>
</li>
<li><a href="#_set_an_environment_variable">10.11. Set an environment variable</a>
<ul class="sectlevel3">
<li><a href="#_in_shell_nix_3">10.11.1. In <code>shell.nix</code></a></li>
<li><a href="#_in_shell_nix_3">10.9.1. In <code>shell.nix</code></a></li>
</ul>
</li>
</ul>
@ -4222,6 +4217,66 @@ However, you can use any of the flake reference styles defined in <a href="#flak
</div>
</div>
</div>
<div class="sect3">
<h4 id="_access_to_a_haskell_library_package_in_the_nixpkgs_repo_without_a_cabal_file">10.3.3. Access to 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>
</div>
<div class="paragraph">
<p>Example: Access the <code>containers</code> package from the <code>haskellPackages</code> set in the nixpkgs repo.</p>
</div>
<div class="paragraph">
<p>Unresolved directive in recipes/shebang/haskell-nixpkg/main-generated.adoc - include::shell/main-generated.adoc[leveloffset=+1]</p>
</div>
<div class="paragraph">
<p>Unresolved directive in recipes/shebang/haskell-nixpkg/main-generated.adoc - include::shebang/main-generated.adoc[leveloffset=+1]</p>
</div>
</div>
<div class="sect3">
<h4 id="_in_a_haskell_script">10.3.4. In a Haskell script</h4>
<div class="listingblock">
<div class="title">Script</div>
<div class="content">
<pre class="pygments highlight nowrap" style="background: #f8f8f8;"><code data-lang="haskell"><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></pre></div></td><td class="code"><div><pre style="line-height: 125%;"><span></span><span style="color: #666666">#!</span><span style="color: #bbbbbb"> </span><span style="color: #666666">/</span>usr<span style="color: #666666">/</span>bin<span style="color: #666666">/</span>env<span style="color: #bbbbbb"> </span>nix<span style="color: #666666">-</span>shell
<span style="color: #666666">#!</span><span style="color: #bbbbbb"> </span>nix<span style="color: #666666">-</span>shell<span style="color: #bbbbbb"> </span><span style="color: #666666">-</span>p<span style="color: #bbbbbb"> </span><span style="color: #BA2121">&quot;haskellPackages.ghcWithPackages (p: [p.containers])&quot;</span>
<span style="color: #666666">#!</span><span style="color: #bbbbbb"> </span>nix<span style="color: #666666">-</span>shell<span style="color: #bbbbbb"> </span><span style="color: #666666">-</span>i<span style="color: #bbbbbb"> </span>runghc
<span style="color: #008000; font-weight: bold">import</span><span style="color: #bbbbbb"> </span><span style="color: #0000FF; font-weight: bold">Data.Map</span>
<span style="color: #0000FF">m</span><span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">::</span><span style="color: #bbbbbb"> </span><span style="color: #B00040">Map</span><span style="color: #bbbbbb"> </span><span style="color: #B00040">String</span><span style="color: #bbbbbb"> </span><span style="color: #B00040">Int</span>
<span style="color: #0000FF">m</span><span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">=</span><span style="color: #bbbbbb"> </span>fromList<span style="color: #bbbbbb"> </span>[(<span style="color: #BA2121">&quot;cats&quot;</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">3</span>),<span style="color: #bbbbbb"> </span>(<span style="color: #BA2121">&quot;dogs&quot;</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">2</span>)]
<span style="color: #0000FF">main</span><span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">::</span><span style="color: #bbbbbb"> </span><span style="color: #B00040">IO</span><span style="color: #bbbbbb"> </span><span style="color: #008000">()</span>
<span style="color: #0000FF">main</span><span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">do</span>
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">let</span><span style="color: #bbbbbb"> </span>cats<span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">=</span><span style="color: #bbbbbb"> </span>findWithDefault<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">&quot;cats&quot;</span><span style="color: #bbbbbb"> </span>m
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">let</span><span style="color: #bbbbbb"> </span>dogs<span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">=</span><span style="color: #bbbbbb"> </span>findWithDefault<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">&quot;dogs&quot;</span><span style="color: #bbbbbb"> </span>m
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">let</span><span style="color: #bbbbbb"> </span>zebras<span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">=</span><span style="color: #bbbbbb"> </span>findWithDefault<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">&quot;zebras&quot;</span><span style="color: #bbbbbb"> </span>m
<span style="color: #bbbbbb"> </span>print<span style="color: #bbbbbb"> </span><span style="color: #666666">$</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">&quot;I have &quot;</span><span style="color: #bbbbbb"> </span><span style="color: #666666">++</span><span style="color: #bbbbbb"> </span>show<span style="color: #bbbbbb"> </span>cats<span style="color: #bbbbbb"> </span><span style="color: #666666">++</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">&quot; cats, &quot;</span><span style="color: #bbbbbb"> </span><span style="color: #666666">++</span><span style="color: #bbbbbb"> </span>show<span style="color: #bbbbbb"> </span>dogs<span style="color: #bbbbbb"> </span><span style="color: #666666">++</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">&quot; dogs, and &quot;</span><span style="color: #bbbbbb"> </span><span style="color: #666666">++</span><span style="color: #bbbbbb"> </span>show<span style="color: #bbbbbb"> </span>zebras<span style="color: #bbbbbb"> </span><span style="color: #666666">++</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">&quot; zebras.&quot;</span>
</pre></div></td></tr></table></div></code></pre>
</div>
</div>
<div class="literalblock">
<div class="title">Output</div>
<div class="content">
<pre class="nowrap">"I have 3 cats, 2 dogs, and 0 zebras."</pre>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_development_shells_with_access_to">10.4. Development shells with access to&#8230;&#8203;</h3>
@ -4506,83 +4561,8 @@ $ runghc Main.hs
"I have 3 cats, 2 dogs, and 0 zebras."</pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_a_non_flake_package_not_in_nixpkgs">10.4.4. A non-flake package (not in nixpkgs)</h4>
<div class="paragraph">
<p>In this example, we will use a nix package 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>
</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></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="background-color: #ffffcc"> <span style="color: #19177C">hello-nix</span> <span style="color: #666666">=</span> {
</span><span style="background-color: #ffffcc"> <span style="color: #19177C">url</span> <span style="color: #666666">=</span> <span style="color: #BA2121">&quot;git+https://codeberg.org/mhwombat/hello-nix&quot;</span>;
</span><span style="background-color: #ffffcc"> <span style="color: #19177C">flake</span> <span style="color: #666666">=</span> <span style="color: #880000">false</span>;
</span> };
};
<span style="color: #19177C">outputs</span> <span style="color: #666666">=</span> { self, nixpkgs, flake-utils, hello-nix }:
flake-utils<span style="color: #666666">.</span>lib<span style="color: #666666">.</span>eachDefaultSystem (system:
<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="background-color: #ffffcc"> <span style="color: #19177C">devShells</span> <span style="color: #666666">=</span> <span style="color: #008000; font-weight: bold">rec</span> {
</span><span style="background-color: #ffffcc"> <span style="color: #19177C">default</span> <span style="color: #666666">=</span> pkgs<span style="color: #666666">.</span>mkShell {
</span><span style="background-color: #ffffcc"> <span style="color: #19177C">shellHook</span> <span style="color: #666666">=</span>
</span><span style="background-color: #ffffcc"> <span style="color: #BA2121">&#39;&#39;</span>
</span><span style="color: #BA2121"> PATH=</span><span style="color: #A45A77; font-weight: bold">${</span>hello-nix<span style="color: #A45A77; font-weight: bold">}</span><span style="color: #BA2121">:$PATH</span>
<span style="color: #BA2121"> &#39;&#39;</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">$ hello-nix # this will fail
bash: line 20: hello-nix: command not found
$ nix develop
$ hello-nix
Hello from your nix package!</pre>
</div>
<p>/// SKIP include::non-flake/main-generated.adoc[leveloffset=+1]</p>
</div>
</div>
</div>
@ -4630,97 +4610,22 @@ $ hello-flake
Hello from your flake!</pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_access_to_a_package_defined_in_a_remote_git_repo">10.6. Access to a package defined in a remote git repo</h3>
<div class="paragraph">
<p>Ex: Access a package (not a flake) called <code>hello-nix</code>,
which is defined in a remote git repo on codeberg.
To use a package from GitHub, GitLab, or any other public platform,
modify the URL.</p>
<p>Unresolved directive in recipes/main.adoc - include::remote-git/main.adoc[leveloffset=+1]</p>
</div>
<div class="paragraph">
<p>REMOVE ME</p>
</div>
<div class="paragraph">
<p>REMOVE ME</p>
</div>
<div class="paragraph">
<p>REMOVE ME</p>
</div>
<div class="paragraph">
<p>REMOVE ME</p>
</div>
<div class="paragraph">
<p>Unresolved directive in recipes/remote-git/main.adoc - include::flake/main-generated.adoc[leveloffset=+1]</p>
<p>Unresolved directive in recipes/main.adoc - include::haskell-nixpkg/main.adoc[leveloffset=+1]</p>
</div>
</div>
<div class="sect2">
<h3 id="_access_to_a_haskell_library_package_in_the_nixpkgs_repo_without_a_cabal_file">10.7. Access to a Haskell library package in the nixpkgs repo (without a <code>.cabal</code> file)</h3>
<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>
</div>
<div class="paragraph">
<p>Example: Access the <code>containers</code> package from the <code>haskellPackages</code> set in the nixpkgs repo.</p>
</div>
<div class="paragraph">
<p>Unresolved directive in recipes/haskell-nixpkg/main.adoc - include::shell/main-generated.adoc[leveloffset=+1]</p>
</div>
<div class="sect3">
<h4 id="_in_a_haskell_script">10.7.1. In a Haskell script</h4>
<div class="listingblock">
<div class="title">Script</div>
<div class="content">
<pre class="pygments highlight nowrap" style="background: #f8f8f8;"><code data-lang="haskell"><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></pre></div></td><td class="code"><div><pre style="line-height: 125%;"><span></span><span style="color: #666666">#!</span><span style="color: #bbbbbb"> </span><span style="color: #666666">/</span>usr<span style="color: #666666">/</span>bin<span style="color: #666666">/</span>env<span style="color: #bbbbbb"> </span>nix<span style="color: #666666">-</span>shell
<span style="color: #666666">#!</span><span style="color: #bbbbbb"> </span>nix<span style="color: #666666">-</span>shell<span style="color: #bbbbbb"> </span><span style="color: #666666">-</span>p<span style="color: #bbbbbb"> </span><span style="color: #BA2121">&quot;haskellPackages.ghcWithPackages (p: [p.containers])&quot;</span>
<span style="color: #666666">#!</span><span style="color: #bbbbbb"> </span>nix<span style="color: #666666">-</span>shell<span style="color: #bbbbbb"> </span><span style="color: #666666">-</span>i<span style="color: #bbbbbb"> </span>runghc
<span style="color: #008000; font-weight: bold">import</span><span style="color: #bbbbbb"> </span><span style="color: #0000FF; font-weight: bold">Data.Map</span>
<span style="color: #0000FF">m</span><span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">::</span><span style="color: #bbbbbb"> </span><span style="color: #B00040">Map</span><span style="color: #bbbbbb"> </span><span style="color: #B00040">String</span><span style="color: #bbbbbb"> </span><span style="color: #B00040">Int</span>
<span style="color: #0000FF">m</span><span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">=</span><span style="color: #bbbbbb"> </span>fromList<span style="color: #bbbbbb"> </span>[(<span style="color: #BA2121">&quot;cats&quot;</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">3</span>),<span style="color: #bbbbbb"> </span>(<span style="color: #BA2121">&quot;dogs&quot;</span>,<span style="color: #bbbbbb"> </span><span style="color: #666666">2</span>)]
<span style="color: #0000FF">main</span><span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">::</span><span style="color: #bbbbbb"> </span><span style="color: #B00040">IO</span><span style="color: #bbbbbb"> </span><span style="color: #008000">()</span>
<span style="color: #0000FF">main</span><span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">do</span>
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">let</span><span style="color: #bbbbbb"> </span>cats<span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">=</span><span style="color: #bbbbbb"> </span>findWithDefault<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">&quot;cats&quot;</span><span style="color: #bbbbbb"> </span>m
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">let</span><span style="color: #bbbbbb"> </span>dogs<span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">=</span><span style="color: #bbbbbb"> </span>findWithDefault<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">&quot;dogs&quot;</span><span style="color: #bbbbbb"> </span>m
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">let</span><span style="color: #bbbbbb"> </span>zebras<span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">=</span><span style="color: #bbbbbb"> </span>findWithDefault<span style="color: #bbbbbb"> </span><span style="color: #666666">0</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">&quot;zebras&quot;</span><span style="color: #bbbbbb"> </span>m
<span style="color: #bbbbbb"> </span>print<span style="color: #bbbbbb"> </span><span style="color: #666666">$</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">&quot;I have &quot;</span><span style="color: #bbbbbb"> </span><span style="color: #666666">++</span><span style="color: #bbbbbb"> </span>show<span style="color: #bbbbbb"> </span>cats<span style="color: #bbbbbb"> </span><span style="color: #666666">++</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">&quot; cats, &quot;</span><span style="color: #bbbbbb"> </span><span style="color: #666666">++</span><span style="color: #bbbbbb"> </span>show<span style="color: #bbbbbb"> </span>dogs<span style="color: #bbbbbb"> </span><span style="color: #666666">++</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">&quot; dogs, and &quot;</span><span style="color: #bbbbbb"> </span><span style="color: #666666">++</span><span style="color: #bbbbbb"> </span>show<span style="color: #bbbbbb"> </span>zebras<span style="color: #bbbbbb"> </span><span style="color: #666666">++</span><span style="color: #bbbbbb"> </span><span style="color: #BA2121">&quot; zebras.&quot;</span>
</pre></div></td></tr></table></div></code></pre>
</div>
</div>
<div class="literalblock">
<div class="title">Output</div>
<div class="content">
<pre class="nowrap">"I have 3 cats, 2 dogs, and 0 zebras."</pre>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_access_to_a_haskell_package_on_your_local_computer">10.8. Access to a Haskell package on your local computer</h3>
<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.8.1. In <code>shell.nix</code></h4>
<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">
@ -4757,7 +4662,7 @@ mkShell {
</div>
</div>
<div class="sect2">
<h3 id="_access_to_a_haskell_package_on_your_local_computer_with_inter_dependencies">10.9. Access to a Haskell package on your local computer, with inter-dependencies</h3>
<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>)
@ -4765,7 +4670,7 @@ 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.9.1. In <code>shell.nix</code></h4>
<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">
@ -4812,7 +4717,7 @@ mkShell {
</div>
</div>
<div class="sect2">
<h3 id="_access_to_a_python_library_package_in_the_nixpkgs_repo_without_using_a_python_builder">10.10. Access to a Python library package in the nixpkgs repo (without using a Python builder)</h3>
<h3 id="_access_to_a_python_library_package_in_the_nixpkgs_repo_without_using_a_python_builder">10.8. Access to a Python library package in the nixpkgs repo (without using a Python builder)</h3>
<div class="paragraph">
<p>Occasionally you might want to run a short Python program that depends on a Python library,
but you don&#8217;t want to bother configuring a builder.</p>
@ -4821,7 +4726,7 @@ but you don&#8217;t want to bother configuring a builder.</p>
<p>Example: Access the <code>html_sanitizer</code> package from the <code>python3nnPackages</code> set in the nixpkgs repo.</p>
</div>
<div class="sect3">
<h4 id="_in_a_python_script">10.10.1. In a Python script</h4>
<h4 id="_in_a_python_script">10.8.1. In a Python script</h4>
<div class="listingblock">
<div class="title">Script</div>
<div class="content">
@ -4859,12 +4764,12 @@ sanitized: &lt;strong&gt;some text&lt;/strong&gt;</pre>
</div>
</div>
<div class="sect2">
<h3 id="_set_an_environment_variable">10.11. Set an environment variable</h3>
<h3 id="_set_an_environment_variable">10.9. 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.11.1. In <code>shell.nix</code></h4>
<h4 id="_in_shell_nix_3">10.9.1. In <code>shell.nix</code></h4>
<div class="listingblock">
<div class="title">shell.nix</div>
<div class="content">
@ -4898,7 +4803,7 @@ mkShell {
</div>
<div id="footer">
<div id="footer-text">
Last updated 2025-09-05 19:36:04 IST
Last updated 2025-09-05 19:56:06 IST
</div>
</div>
</body>

View file

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

View file

@ -1,77 +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"
}
},
"hello-nix": {
"flake": false,
"locked": {
"lastModified": 1676213208,
"narHash": "sha256-Zds5C+f5sA3w+j85EsAQjte0zeHqubMVPGYn5lGwATo=",
"ref": "refs/heads/main",
"rev": "aa2c87f8b89578b069b09fdb2be30a0c9d8a77d8",
"revCount": 4,
"type": "git",
"url": "https://codeberg.org/mhwombat/hello-nix"
},
"original": {
"type": "git",
"url": "https://codeberg.org/mhwombat/hello-nix"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1757096966,
"narHash": "sha256-nJpPWCFbc5/u0VIoSHT350FEwPS5pwiRfyZBbZA3Kgg=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "6eb784fb955ab56952e6eeb01f3e64a79933e2b5",
"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
}

View file

@ -1,27 +0,0 @@
{
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; };
in
{
devShells = rec {
default = pkgs.mkShell {
shellHook =
''
PATH=${hello-nix}:$PATH
'';
};
};
}
);
}

View file

@ -1,13 +0,0 @@
= In a Haskell script
[source,haskell,linenums]
.Script
....
include::my-script.sh[]
....
.Output
....
$# ./my-script.sh
....

View file

@ -1,16 +0,0 @@
= Access to a package defined in a remote git repo
Ex: Access a package (not a flake) called `hello-nix`,
which is defined in a remote git repo on codeberg.
To use a package from GitHub, GitLab, or any other public platform,
modify the URL.
REMOVE ME
REMOVE ME
REMOVE ME
REMOVE ME
include::flake/main-generated.adoc[leveloffset=+1]

View file

@ -9,3 +9,16 @@ include::shell/main-generated.adoc[leveloffset=+1]
include::shebang/main-generated.adoc[leveloffset=+1]
= In a Haskell script
[source,haskell,linenums]
.Script
....
include::my-script.sh[]
....
.Output
....
$# ./my-script.sh
....

View file

@ -37,3 +37,5 @@ $# cat run-flake.sh
....
$# ./run-flake.sh
....
include::haskell-nixpkg/main-generated.adoc[leveloffset=+1]