This commit is contained in:
Amy de Buitléir 2025-09-03 20:35:34 +01:00
parent 03904e210f
commit 7de7ca8532
5 changed files with 393 additions and 46 deletions

View file

@ -241,50 +241,83 @@ pre.pygments .tok-il { color: #666666 } /* Literal.Number.Integer.Long */
</li>
<li><a href="#_recipes">10. Recipes</a>
<ul class="sectlevel2">
<li><a href="#_access_to_a_top_level_package_from_the_nixpkgsnixos_repo">10.1. Access to a top-level package from the Nixpkgs/NixOS repo</a>
<li><a href="#_running_programs_directly_without_installing_them">10.1. Running programs directly (without installing them)</a>
<ul class="sectlevel3">
<li><a href="#_from_the_command_line_flake_style">10.1.1. From the command line (flake style)</a></li>
<li><a href="#_from_the_command_line_non_flake_style">10.1.2. From the command line (non-flake style)</a></li>
<li><a href="#_in_flake_nix">10.1.3. In <code>flake.nix</code></a></li>
<li><a href="#_in_shell_nix">10.1.4. In <code>shell.nix</code></a></li>
<li><a href="#_in_a_bash_script_flake_style">10.1.5. In a Bash script (flake style)</a></li>
<li><a href="#_in_a_bash_script_non_flake_style">10.1.6. In a Bash script (non-flake style)</a></li>
<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="#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>
</ul>
</li>
<li><a href="#_access_to_a_package_defined_in_a_remote_git_repo">10.2. Access to a package defined in a remote git repo</a>
<ul class="sectlevel3">
<li><a href="#_in_shell_nix_2">10.2.1. In <code>shell.nix</code></a></li>
</ul>
</li>
<li><a href="#_access_to_a_flake_defined_in_a_remote_git_repo">10.3. Access to a flake defined in a remote git repo</a>
<li><a href="#_ad_hoc_environments_with_access_to">10.2. Ad hoc environments with access to&#8230;&#8203;</a>
<ul class="sectlevel3">
<li><a href="#_in_shell_nix_3">10.3.1. In <code>shell.nix</code></a></li>
<li><a href="#_a_top_level_package_from_the_nixpkgsnixos_repo_2">10.2.1. A top level package from the Nixpkgs/NixOS repo</a></li>
<li><a href="#_a_flake">10.2.2. A flake</a></li>
</ul>
</li>
<li><a href="#_access_to_a_haskell_library_package_in_the_nixpkgs_repo_without_a_cabal_file">10.4. Access to a Haskell library package in the nixpkgs repo (without a <code>.cabal</code> file)</a>
<li><a href="#_scripts_with_access_to">10.3. Scripts with access to&#8230;&#8203;</a>
<ul class="sectlevel3">
<li><a href="#_in_shell_nix_4">10.4.1. In <code>shell.nix</code></a></li>
<li><a href="#_in_a_haskell_script">10.4.2. In a Haskell script</a></li>
<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>
</ul>
</li>
<li><a href="#_access_to_a_haskell_package_on_your_local_computer">10.5. Access to a Haskell package on your local computer</a>
<li><a href="#_development_shells_with_access_to">10.4. Development shells with access to&#8230;&#8203;</a>
<ul class="sectlevel3">
<li><a href="#_in_shell_nix_5">10.5.1. In <code>shell.nix</code></a></li>
<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>
</ul>
</li>
<li><a href="#_access_to_a_haskell_package_on_your_local_computer_with_inter_dependencies">10.6. Access to a Haskell package on your local computer, with inter-dependencies</a>
<li><a href="#_access_to_a_top_level_package_from_the_nixpkgsnixos_repo">10.5. Access to a top-level package from the Nixpkgs/NixOS repo</a>
<ul class="sectlevel3">
<li><a href="#_in_shell_nix_6">10.6.1. In <code>shell.nix</code></a></li>
<li><a href="#_from_the_command_line_flake_style">10.5.1. From the command line (flake style)</a></li>
<li><a href="#_from_the_command_line_non_flake_style">10.5.2. From the command line (non-flake style)</a></li>
<li><a href="#_in_flake_nix">10.5.3. In <code>flake.nix</code></a></li>
<li><a href="#_in_shell_nix">10.5.4. In <code>shell.nix</code></a></li>
<li><a href="#_in_a_bash_script_flake_style">10.5.5. In a Bash script (flake style)</a></li>
<li><a href="#_in_a_bash_script_non_flake_style">10.5.6. In a Bash script (non-flake style)</a></li>
</ul>
</li>
<li><a href="#_access_to_a_python_library_package_in_the_nixpkgs_repo_without_using_a_python_builder">10.7. Access to a Python library package in the nixpkgs repo (without using a Python builder)</a>
<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>
<ul class="sectlevel3">
<li><a href="#_in_a_python_script">10.7.1. In a Python script</a></li>
<li><a href="#_in_shell_nix_2">10.6.1. In <code>shell.nix</code></a></li>
</ul>
</li>
<li><a href="#_set_an_environment_variable">10.8. Set an environment variable</a>
<li><a href="#_access_to_a_flake_defined_in_a_remote_git_repo">10.7. Access to a flake defined in a remote git repo</a>
<ul class="sectlevel3">
<li><a href="#_in_shell_nix_7">10.8.1. In <code>shell.nix</code></a></li>
<li><a href="#_from_the_command_line">10.7.1. From the command line</a></li>
<li><a href="#_in_shell_nix_3">10.7.2. In <code>shell.nix</code></a></li>
</ul>
</li>
<li><a href="#_access_to_a_haskell_library_package_in_the_nixpkgs_repo_without_a_cabal_file">10.8. Access to a Haskell library package in the nixpkgs repo (without a <code>.cabal</code> file)</a>
<ul class="sectlevel3">
<li><a href="#_in_shell_nix_4">10.8.1. In <code>shell.nix</code></a></li>
<li><a href="#_in_a_haskell_script">10.8.2. In a Haskell script</a></li>
</ul>
</li>
<li><a href="#_access_to_a_haskell_package_on_your_local_computer">10.9. Access to a Haskell package on your local computer</a>
<ul class="sectlevel3">
<li><a href="#_in_shell_nix_5">10.9.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.10. Access to a Haskell package on your local computer, with inter-dependencies</a>
<ul class="sectlevel3">
<li><a href="#_in_shell_nix_6">10.10.1. In <code>shell.nix</code></a></li>
</ul>
</li>
<li><a href="#_access_to_a_python_library_package_in_the_nixpkgs_repo_without_using_a_python_builder">10.11. Access to a Python library package in the nixpkgs repo (without using a Python builder)</a>
<ul class="sectlevel3">
<li><a href="#_in_a_python_script">10.11.1. In a Python script</a></li>
</ul>
</li>
<li><a href="#_set_an_environment_variable">10.12. Set an environment variable</a>
<ul class="sectlevel3">
<li><a href="#_in_shell_nix_7">10.12.1. In <code>shell.nix</code></a></li>
</ul>
</li>
</ul>
@ -4097,13 +4130,286 @@ interpreter and any dependencies.</p>
</ul>
</div>
<div class="sect2">
<h3 id="_access_to_a_top_level_package_from_the_nixpkgsnixos_repo">10.1. Access to a top-level package from the Nixpkgs/NixOS repo</h3>
<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>
<div class="literalblock">
<div class="content">
<pre class="nowrap">$ nix run nixpkgs#cowsay "Moo!"
______
&lt; Moo! &gt;
------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||</pre>
</div>
</div>
</div>
<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>
<div class="literalblock">
<div class="content">
<pre class="nowrap">$ nix run ~/codeberg/hello-flake
Hello from your flake!</pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="_a_flake_defined_in_a_remote_git_repo">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
Hello from your flake!</pre>
</div>
</div>
<div class="paragraph">
<p>To run a specific branch, use the command below.</p>
</div>
<div class="literalblock">
<div class="content">
<pre class="nowrap">nix run git+https://codeberg.org/mhwombat/hello-flake?ref=main</pre>
</div>
</div>
<div class="paragraph">
<p>To run a specific branch and revision, use the command below.</p>
</div>
<div class="literalblock">
<div class="content">
<pre class="nowrap">nix run git+https://codeberg.org/mhwombat/hello-flake?ref=main&amp;rev=d44728bce88a6f9d1d37dbf4720ece455e997606</pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="_a_flake_defined_in_a_zip_archive">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
Hello from your flake!</pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="_a_flake_defined_in_a_compressed_tar_archive">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
Hello from your flake!</pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="_other_types_of_flake_references">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>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_ad_hoc_environments_with_access_to">10.2. Ad hoc environments with access to&#8230;&#8203;</h3>
<div class="sect3">
<h4 id="_a_top_level_package_from_the_nixpkgsnixos_repo_2">10.2.1. A top level package from the Nixpkgs/NixOS repo</h4>
<div class="literalblock">
<div class="content">
<pre class="nowrap">$ nix shell nixpkgs#cowsay
$ cowsay "moo"
_____
&lt; moo &gt;
-----
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||</pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_a_flake">10.2.2. A flake</h4>
<div class="literalblock">
<div class="content">
<pre class="nowrap">$ nix shell git+https://codeberg.org/mhwombat/hello-flake
$ hello-flake
Hello from your flake!</pre>
</div>
</div>
<div class="paragraph">
<p>You can use all of the flake reference styles defined in <a href="#flakeref">Section 10.1.2, &#8220;Flakes&#8221;</a>.</p>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_scripts_with_access_to">10.3. Scripts with access to&#8230;&#8203;</h3>
<div class="sect3">
<h4 id="_a_top_level_package_from_the_nixpkgsnixos_repo_3">10.3.1. A top level package from the Nixpkgs/NixOS repo</h4>
<div class="listingblock">
<div class="title">Script</div>
<div class="content">
<pre class="pygments highlight nowrap"><code data-lang="bash"><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></pre></div></td><td class="code"><div><pre><span></span><span class="tok-ch">#! /usr/bin/env nix</span>
<span class="tok-c1">#! nix shell nixpkgs#hello nixpkgs#cowsay --command bash</span>
hello
cowsay<span class="tok-w"> </span><span class="tok-s2">&quot;Pretty cool, huh?&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">Hello, world!
___________________
&lt; Pretty cool, huh? &gt;
-------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||</pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_a_flake_2">10.3.2. A flake</h4>
<div class="listingblock">
<div class="title">Script</div>
<div class="content">
<pre class="pygments highlight nowrap"><code data-lang="bash"><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></pre></div></td><td class="code"><div><pre><span></span><span class="tok-ch">#! /usr/bin/env nix</span>
<span class="tok-c1">#! nix shell git+https://codeberg.org/mhwombat/hello-flake --command bash</span>
hello-flake
</pre></div></td></tr></table></div></code></pre>
</div>
</div>
<div class="literalblock">
<div class="title">Output</div>
<div class="content">
<pre class="nowrap">Hello from your flake!</pre>
</div>
</div>
<div class="paragraph">
<p>You can use all of the flake reference styles defined in <a href="#flakeref">Section 10.1.2, &#8220;Flakes&#8221;</a>.</p>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_development_shells_with_access_to">10.4. Development shells with access to&#8230;&#8203;</h3>
<div class="sect3">
<h4 id="_a_top_level_package_from_the_nixpkgsnixos_repo_4">10.4.1. A top level package from the Nixpkgs/NixOS repo</h4>
<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></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>
<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>
flake-utils<span class="tok-o">.</span>lib<span class="tok-o">.</span>eachDefaultSystem <span class="tok-p">(</span>system<span class="tok-p">:</span>
<span class="tok-k">let</span>
<span class="tok-ss">pkgs</span> <span class="tok-o">=</span> <span class="tok-nb">import</span> nixpkgs <span class="tok-p">{</span> <span class="tok-k">inherit</span> system<span class="tok-p">;</span> <span class="tok-p">};</span>
<span class="tok-k">in</span>
<span class="tok-p">{</span>
<span class="tok-ss">devShells</span> <span class="tok-o">=</span> <span class="tok-k">rec</span> <span class="tok-p">{</span>
<span class="tok-ss">default</span> <span class="tok-o">=</span> pkgs<span class="tok-o">.</span>mkShell <span class="tok-p">{</span>
<span class="tok-ss">packages</span> <span class="tok-o">=</span> <span class="tok-p">[</span> pkgs<span class="tok-o">.</span>cowsay <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>
<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">$ cowsay "Moo!"
bash: line 35: cowsay: command not found
$ pwd
/home/amy/codeberg/nix-book/source/recipes/devshell/tempwork
$ realpath ../../../..
/home/amy/codeberg/nix-book
$ nix develop
warning: Git tree '/home/amy/codeberg/nix-book' is dirty
warning: creating lock file '"/home/amy/codeberg/nix-book/source/recipes/devshell/tempwork/flake.lock"':
• Added input 'flake-utils':
'github:numtide/flake-utils/11707dc2f618dd54ca8739b309ec4fc024de578b?narHash=sha256-l0KFg5HjrsfsO/JpG%2Br7fRrqm12kzFHyUHqHCVpMMbI%3D' (2024-11-13)
• Added input 'flake-utils/systems':
'github:nix-systems/default/da67096a3b9bf56a91d16901293e51ba5b49a27e?narHash=sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768%3D' (2023-04-09)
• Added input 'nixpkgs':
'github:NixOS/nixpkgs/6ce002c32a5e3470505a44fbcfb9e51cbaec71a6?narHash=sha256-uOBDwpkJZMb8gjkOA89fx%2Bcq9qT0abLETCINC/cb%2Bz0%3D' (2025-09-03)
warning: Git tree '/home/amy/codeberg/nix-book' is dirty
$ cowsay "Moo!"
______
&lt; Moo! &gt;
------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||</pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_a_flake_3">10.4.2. A flake</h4>
<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>You can use all of the flake reference styles defined in <a href="#flakeref">Section 10.1.2, &#8220;Flakes&#8221;</a>.</p>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_access_to_a_top_level_package_from_the_nixpkgsnixos_repo">10.5. Access to a top-level package from the Nixpkgs/NixOS repo</h3>
<div class="paragraph">
<p>Ex: Access two packages from nixpkgs:
hello and cowsay.</p>
</div>
<div class="sect3">
<h4 id="_from_the_command_line_flake_style">10.1.1. From the command line (flake style)</h4>
<h4 id="_from_the_command_line_flake_style">10.5.1. From the command line (flake style)</h4>
<div class="literalblock">
<div class="content">
<pre class="nowrap">$ nix shell nixpkgs#hello nixpkgs#cowsay --command bash
@ -4122,7 +4428,7 @@ $ cowsay "moo"
</div>
</div>
<div class="sect3">
<h4 id="_from_the_command_line_non_flake_style">10.1.2. From the command line (non-flake style)</h4>
<h4 id="_from_the_command_line_non_flake_style">10.5.2. From the command line (non-flake style)</h4>
<div class="literalblock">
<div class="content">
<pre class="nowrap">$ nix-shell -p "[hello cowsay]"
@ -4141,7 +4447,7 @@ $ cowsay "moo"
</div>
</div>
<div class="sect3">
<h4 id="_in_flake_nix">10.1.3. In <code>flake.nix</code></h4>
<h4 id="_in_flake_nix">10.5.3. In <code>flake.nix</code></h4>
<div class="paragraph">
<p>See the example in <a href="#_introducing_a_dependency">Section 8.2, &#8220;Introducing a dependency&#8221;</a>
where defined a development shell in <a href="#hello-flake-dependency">flake.nix</a>
@ -4150,7 +4456,7 @@ and tested the shell.</p>
</div>
</div>
<div class="sect3">
<h4 id="_in_shell_nix">10.1.4. In <code>shell.nix</code></h4>
<h4 id="_in_shell_nix">10.5.4. In <code>shell.nix</code></h4>
<div class="listingblock">
<div class="title">shell.nix</div>
<div class="content">
@ -4191,7 +4497,7 @@ $ cowsay "moo"
</div>
</div>
<div class="sect3">
<h4 id="_in_a_bash_script_flake_style">10.1.5. In a Bash script (flake style)</h4>
<h4 id="_in_a_bash_script_flake_style">10.5.5. In a Bash script (flake style)</h4>
<div class="listingblock">
<div class="title">Script</div>
<div class="content">
@ -4221,7 +4527,7 @@ cowsay<span class="tok-w"> </span><span class="tok-s2">&quot;Pretty cool, huh?&q
</div>
</div>
<div class="sect3">
<h4 id="_in_a_bash_script_non_flake_style">10.1.6. In a Bash script (non-flake style)</h4>
<h4 id="_in_a_bash_script_non_flake_style">10.5.6. In a Bash script (non-flake style)</h4>
<div class="listingblock">
<div class="title">Script</div>
<div class="content">
@ -4252,7 +4558,7 @@ cowsay<span class="tok-w"> </span><span class="tok-s2">&quot;Pretty cool, huh?&q
</div>
</div>
<div class="sect2">
<h3 id="_access_to_a_package_defined_in_a_remote_git_repo">10.2. Access to a package defined in a remote git repo</h3>
<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.
@ -4260,7 +4566,7 @@ To use a package from GitHub, GitLab, or any other public platform,
modify the URL.</p>
</div>
<div class="sect3">
<h4 id="_in_shell_nix_2">10.2.1. In <code>shell.nix</code></h4>
<h4 id="_in_shell_nix_2">10.6.1. In <code>shell.nix</code></h4>
<div class="listingblock">
<div class="title">shell.nix</div>
<div class="content">
@ -4299,7 +4605,7 @@ Hello from your nix package!</pre>
</div>
</div>
<div class="sect2">
<h3 id="_access_to_a_flake_defined_in_a_remote_git_repo">10.3. Access to a flake defined in a remote git repo</h3>
<h3 id="_access_to_a_flake_defined_in_a_remote_git_repo">10.7. Access to a flake defined in a remote git repo</h3>
<div class="paragraph">
<p>Ex: Access a flake called <code>hello-flake</code>,
which is defined in a remote git repo on codeberg.
@ -4307,7 +4613,17 @@ To use a package from GitHub, GitLab, or any other public platform,
modify the URL.</p>
</div>
<div class="sect3">
<h4 id="_in_shell_nix_3">10.3.1. In <code>shell.nix</code></h4>
<h4 id="_from_the_command_line">10.7.1. From the command line</h4>
<div class="literalblock">
<div class="content">
<pre class="nowrap">$ nix shell git+https://codeberg.org/mhwombat/hello-flake
$ hello-flake
Hello from your flake!</pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_in_shell_nix_3">10.7.2. In <code>shell.nix</code></h4>
<div class="listingblock">
<div class="title">shell.nix</div>
<div class="content">
@ -4348,7 +4664,7 @@ Hello from your flake!</pre>
</div>
</div>
<div class="sect2">
<h3 id="_access_to_a_haskell_library_package_in_the_nixpkgs_repo_without_a_cabal_file">10.4. Access to a Haskell library package in the nixpkgs repo (without a <code>.cabal</code> file)</h3>
<h3 id="_access_to_a_haskell_library_package_in_the_nixpkgs_repo_without_a_cabal_file">10.8. 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>
@ -4357,7 +4673,7 @@ but you don&#8217;t want to bother writing a cabal file.</p>
<p>Example: Access the <code>containers</code> package from the <code>haskellPackages</code> set in the nixpkgs repo.</p>
</div>
<div class="sect3">
<h4 id="_in_shell_nix_4">10.4.1. In <code>shell.nix</code></h4>
<h4 id="_in_shell_nix_4">10.8.1. In <code>shell.nix</code></h4>
<div class="listingblock">
<div class="title">shell.nix</div>
<div class="content">
@ -4423,7 +4739,7 @@ $ runghc Main.hs
</div>
</div>
<div class="sect3">
<h4 id="_in_a_haskell_script">10.4.2. In a Haskell script</h4>
<h4 id="_in_a_haskell_script">10.8.2. In a Haskell script</h4>
<div class="listingblock">
<div class="title">Script</div>
<div class="content">
@ -4468,14 +4784,14 @@ $ runghc Main.hs
</div>
</div>
<div class="sect2">
<h3 id="_access_to_a_haskell_package_on_your_local_computer">10.5. Access to a Haskell package on your local computer</h3>
<h3 id="_access_to_a_haskell_package_on_your_local_computer">10.9. 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_5">10.5.1. In <code>shell.nix</code></h4>
<h4 id="_in_shell_nix_5">10.9.1. In <code>shell.nix</code></h4>
<div class="listingblock">
<div class="title">shell.nix</div>
<div class="content">
@ -4512,7 +4828,7 @@ mkShell <span class="tok-p">{</span>
</div>
</div>
<div class="sect2">
<h3 id="_access_to_a_haskell_package_on_your_local_computer_with_inter_dependencies">10.6. 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.10. 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>)
@ -4520,7 +4836,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_6">10.6.1. In <code>shell.nix</code></h4>
<h4 id="_in_shell_nix_6">10.10.1. In <code>shell.nix</code></h4>
<div class="listingblock">
<div class="title">shell.nix</div>
<div class="content">
@ -4567,7 +4883,7 @@ mkShell <span class="tok-p">{</span>
</div>
</div>
<div class="sect2">
<h3 id="_access_to_a_python_library_package_in_the_nixpkgs_repo_without_using_a_python_builder">10.7. 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.11. 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>
@ -4576,7 +4892,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.7.1. In a Python script</h4>
<h4 id="_in_a_python_script">10.11.1. In a Python script</h4>
<div class="listingblock">
<div class="title">Script</div>
<div class="content">
@ -4614,12 +4930,12 @@ sanitized: &lt;strong&gt;some text&lt;/strong&gt;</pre>
</div>
</div>
<div class="sect2">
<h3 id="_set_an_environment_variable">10.8. Set an environment variable</h3>
<h3 id="_set_an_environment_variable">10.12. 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_7">10.8.1. In <code>shell.nix</code></h4>
<h4 id="_in_shell_nix_7">10.12.1. In <code>shell.nix</code></h4>
<div class="listingblock">
<div class="title">shell.nix</div>
<div class="content">
@ -4653,7 +4969,7 @@ mkShell <span class="tok-p">{</span>
</div>
<div id="footer">
<div id="footer-text">
Last updated 2025-09-02 16:56:43 IST
Last updated 2025-09-03 20:34:24 IST
</div>
</div>
</body>

View file

@ -11,4 +11,5 @@ mkShell {
# rubyPackages.coderay
# rubyPackages.rouge
];
# outputs = [ "start-shell" ];
}

View file

@ -0,0 +1,20 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
in
{
devShells = rec {
default = pkgs.mkShell {
packages = [ pkgs.cowsay ];
};
};
}
);
}

View file

@ -24,6 +24,14 @@ should invoke `nix-shell`. The second should declares the script
interpreter and any dependencies.
include::run/main-generated.adoc[leveloffset=+1]
include::ad-hoc/main-generated.adoc[leveloffset=+1]
include::shebang/main-generated.adoc[leveloffset=+1]
include::devshell/main-generated.adoc[leveloffset=+1]
include::nixpkgs-pkg/main.adoc[leveloffset=+1]
include::remote-git/main.adoc[leveloffset=+1]

View file

@ -5,4 +5,6 @@ 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.
include::cli/main-generated.adoc[leveloffset=+1]
include::shell/main-generated.adoc[leveloffset=+1]