<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>nixos &amp;mdash; Jerry of the Week</title>
    <link>https://write.in0rdr.ch/tag:nixos</link>
    <description>ˈdʒɛri - Individual who sends life against the grain no matter the consequences</description>
    <pubDate>Thu, 23 Apr 2026 23:13:48 +0000</pubDate>
    <item>
      <title>How-To Test Nixpkg Perl Module Additions</title>
      <link>https://write.in0rdr.ch/h1how-to-test-nixpkg-perl-module-addition-h1</link>
      <description>&lt;![CDATA[I recently installed NixOS on my laptop.&#xA;&#xA;So far, I&#39;m very happy with how things work and can do most of my tasks as on any other Linux distribution. Some tasks, however, require some more reading and thinking.&#xA;&#xA;Today I wanted to jot down a quick how-to on testing an addition to the Perl packages in the Nix Packages collection (Nixpkgs).&#xA;&#xA;#coding #perl #nixos&#xA;&#xA;!--more--&#xA;&#xA;This how-to is based on:&#xA;&#xA;https://nixos.wiki/wiki/Perl#AddingsomethingfromCPANtonixpkgs&#xA;https://dataswamp.org/~solene/2021-09-18-nix-cpan-pip.html#Perl&#xA;https://nixos.org/manual/nixpkgs/stable/#how-to-develop&#xA;https://nixos.org/manual/nixpkgs/stable/#submitting-changes-making-patches&#xA;&#xA;First, download nix-generate-from-cpan by adding it to /etc/nixos/configuration.nix and running sudo nixos-rebuild switch.&#xA;&#xA;I won&#39;t go into the details on the first step here, because this is a task you should already be familiar with after having spent the first few hours a href=&#34;https://nixos.org/manual/nixos/stable/#sec-changing-config&#34;configuring your NixOS installation/a.&#xA;&#xA;The next steps involve patching the a href=&#34;https://nixos.org/manual/nixpkgs&#34;nixpkgs/a &#34;collection&#34; (which is part of the default nixpkgs &#34;channel&#34;) .&#xA;&#xA;git clone --depth=1 https://github.com/NixOS/nixpkgs nixpkgs.git&#xA;cd nixpkgs.git&#xA;&#xA;Then you create the patch for the a href=&#34;https://nixos.org/manual/nixpkgs/stable/#sec-language-perl&#34;pkgs/top-level/perl-packages.nix/a file as follows:&#xA;&#xA;nix-generate-from-cpan Cal::DAV&#xA;attribute name: CalDAV&#xA;module: Cal::DAV&#xA;version: 0.6&#xA;package: Cal-DAV-0.6.tar.gz (Cal-DAV-0.6, CalDAV)&#xA;path: authors/id/S/SI/SIMONW&#xA;downloaded to: /home/andi/.cpanplus/authors/id/S/SI/SIMONW/Cal-DAV-0.6.tar.gz&#xA;sha-256: e436ecb61db9a2fa3ba4b2111149dfd31bdf7aa6acbc12cc49584e50db63e79b&#xA;unpacked to: /home/andi/.cpanplus/5.36.0/build/CM40IbZK/Cal-DAV-0.6&#xA;runtime deps: DataICal HTTPDAV LWP&#xA;build deps: &#xA;description: A CalDAV client&#xA;license: perl5&#xA;RSS feed: https://metacpan.org/feed/distribution/Cal-DAV&#xA;&#xA;  CalDAV = buildPerlPackage {&#xA;    pname = &#34;Cal-DAV&#34;;&#xA;    version = &#34;0.6&#34;;&#xA;    src = fetchurl {&#xA;      url = &#34;mirror://cpan/authors/id/S/SI/SIMONW/Cal-DAV-0.6.tar.gz&#34;;&#xA;      sha256 = &#34;e436ecb61db9a2fa3ba4b2111149dfd31bdf7aa6acbc12cc49584e50db63e79b&#34;;&#xA;    };&#xA;    propagatedBuildInputs = [ DataICal HTTPDAV LWP ];&#xA;    meta = {&#xA;      description = &#34;A CalDAV client&#34;;&#xA;      license = with lib.licenses; [ artistic1 gpl1Plus ];&#xA;    };&#xA;  };&#xA;&#xA;Add the expression in alphabetical order to a href=&#34;https://github.com/NixOS/nixpkgs/blob/master/pkgs/top-level/perl-packages.nix&#34;pkgs/top-level/perl-packages.nix/a. Only copy/paste the &#34;Nix expression&#34; after the === characters into the file.&#xA;&#xA;To test the patch, spin-up a nix-shell which includes the new Perl module. Create the default.nix expression file in any working directory:&#xA;&#xA;cat &lt;EOF  default.nix &#xA;with (import nixpkgs {});&#xA;let&#xA;  CalDAV = perlPackages.buildPerlPackage {&#xA;    pname = &#34;Cal-DAV&#34;;&#xA;    version = &#34;0.6&#34;;&#xA;    src = fetchurl {&#xA;      url = &#34;mirror://cpan/authors/id/S/SI/SIMONW/Cal-DAV-0.6.tar.gz&#34;;&#xA;      sha256 = &#34;e436ecb61db9a2fa3ba4b2111149dfd31bdf7aa6acbc12cc49584e50db63e79b&#34;;&#xA;    };&#xA;    propagatedBuildInputs = [ perlPackages.DataICal perlPackages.HTTPDAV perlPackages.LWP ];&#xA;    meta = {&#xA;      description = &#34;A CalDAV client&#34;;&#xA;      license = with lib.licenses; [ artistic1 gpl1Plus ];&#xA;    };&#xA;  };&#xA;&#xA;in&#xA;mkShell {&#xA;  buildInputs = [ CalDAV perl ];&#xA;  # putting perl here is only required when not using NixOS, this tell you want Nix perl binary&#xA;}&#xA;EOF&#xA;&#xA;The expression includes the result of the previous nix-generate-from-cpan Cal::DAV with slight modifications.&#xA;&#xA;Notice that propagatedBuildInputs needs to refer to already installed packages prefixed by perlPackages.&#xA;&#xA;More information on a href=&#34;https://nixos.org/manual/nixpkgs/stable/#how-to-develop&#34;how to develop with nix-shell/a.&#xA;&#xA;a href=&#34;https://dataswamp.org/~solene/2021-09-18-nix-cpan-pip.html#Perl&#34;Solènes article/a nicely shows how the a href=&#34;https://nixos.org/guides/nix-pills/basics-of-language&#34;let expression/a can also include an entirely new block of code to define a variable. In this example, the let expression uses the a href=&#34;https://nixos.org/manual/nixpkgs/stable/#ssec-perl-packaging&#34;buildPerlPackage function/a, which is a a href=&#34;https://nixos.org/guides/nix-pills/generic-builders&#34;&#34;builder&#34;/a for building Perl packages (as the name indicates).&#xA;&#xA;With that said, you can launch the development shell to test any Perl script with the newly added Perl library as follows:&#xA;&#xA;nix-shell&#xA;&#xA;If you don&#39;t want to create a &#34;descriptive&#34; shell expression, you can also launch the shell more in an ad-hoc fashion using the following command:&#xA;&#xA;nix-shell -p perlPackages.CalDAV perl -I nixpkgs=~/Downloads/nixpkgs.git&#xA;&#xA;See also the example for Perl in the a href=&#34;https://nixos.org/manual/nix/stable/command-ref/nix-shell#examples&#34;nix-shell Manual/a.&#xA;&#xA;If you are happy with how the module works in the nix-shell, you can a href=&#34;https://nixos.org/manual/nixpkgs/stable/#submitting-changes-making-patches&#34;add it to your system/profile/a (using nix-env or nixos-rebuild) and even a href=&#34;https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md&#34;contribute it to the upstream nixpkgs repository/a.&#xA;&#xA;This post mostly reminds myself of all the new terminology I learned the past few days.&#xA;&#xA;div style=&#34;text-align:center; font-size: 0.8em&#34;&#xD;&#xA;a href=&#34;https://write.in0rdr.ch/feed&#34;&amp;#128732; RSS/a | a href=&#34;https://m.in0rdr.ch/in0rdr&#34;&amp;#128024; Fediverse/a | a href=&#34;https://chat.in0rdr.ch/#/guest?join=p0c@conference.in0rdr.ch&#34;&amp;#128172; XMPP/a&#xD;&#xA;/div]]&gt;</description>
      <content:encoded><![CDATA[<p>I recently installed NixOS on my laptop.</p>

<p>So far, I&#39;m very happy with how things work and can do most of my tasks as on any other Linux distribution. Some tasks, however, require some more reading and thinking.</p>

<p>Today I wanted to jot down a quick how-to on testing an addition to the Perl packages in the Nix Packages collection (Nixpkgs).</p>

<p><a href="https://write.in0rdr.ch/tag:coding" class="hashtag"><span>#</span><span class="p-category">coding</span></a> <a href="https://write.in0rdr.ch/tag:perl" class="hashtag"><span>#</span><span class="p-category">perl</span></a> <a href="https://write.in0rdr.ch/tag:nixos" class="hashtag"><span>#</span><span class="p-category">nixos</span></a></p>



<p>This how-to is based on:</p>
<ul><li><a href="https://nixos.wiki/wiki/Perl#Adding_something_from_CPAN_to_nixpkgs">https://nixos.wiki/wiki/Perl#Adding_something_from_CPAN_to_nixpkgs</a></li>
<li><a href="https://dataswamp.org/~solene/2021-09-18-nix-cpan-pip.html#_Perl">https://dataswamp.org/~solene/2021-09-18-nix-cpan-pip.html#_Perl</a></li>
<li><a href="https://nixos.org/manual/nixpkgs/stable/#how-to-develop">https://nixos.org/manual/nixpkgs/stable/#how-to-develop</a></li>
<li><a href="https://nixos.org/manual/nixpkgs/stable/#submitting-changes-making-patches">https://nixos.org/manual/nixpkgs/stable/#submitting-changes-making-patches</a></li></ul>

<p>First, download <code>nix-generate-from-cpan</code> by adding it to <code>/etc/nixos/configuration.nix</code> and running <code>sudo nixos-rebuild switch</code>.</p>

<p>I won&#39;t go into the details on the first step here, because this is a task you should already be familiar with after having spent the first few hours <a href="https://nixos.org/manual/nixos/stable/#sec-changing-config">configuring your NixOS installation</a>.</p>

<p>The next steps involve patching the <a href="https://nixos.org/manual/nixpkgs"><code>&lt;nixpkgs&gt;</code></a> “collection” (which is part of the default <code>nixpkgs</code> “channel”) .</p>

<pre><code class="language-bash">git clone --depth=1 https://github.com/NixOS/nixpkgs nixpkgs.git
cd nixpkgs.git
</code></pre>

<p>Then you create the patch for the <a href="https://nixos.org/manual/nixpkgs/stable/#sec-language-perl"><code>pkgs/top-level/perl-packages.nix</code></a> file as follows:</p>

<pre><code class="language-bash">nix-generate-from-cpan Cal::DAV
attribute name: CalDAV
module: Cal::DAV
version: 0.6
package: Cal-DAV-0.6.tar.gz (Cal-DAV-0.6, CalDAV)
path: authors/id/S/SI/SIMONW
downloaded to: /home/andi/.cpanplus/authors/id/S/SI/SIMONW/Cal-DAV-0.6.tar.gz
sha-256: e436ecb61db9a2fa3ba4b2111149dfd31bdf7aa6acbc12cc49584e50db63e79b
unpacked to: /home/andi/.cpanplus/5.36.0/build/CM_4_0IbZK/Cal-DAV-0.6
runtime deps: DataICal HTTPDAV LWP
build deps: 
description: A CalDAV client
license: perl_5
RSS feed: https://metacpan.org/feed/distribution/Cal-DAV
===
  CalDAV = buildPerlPackage {
    pname = &#34;Cal-DAV&#34;;
    version = &#34;0.6&#34;;
    src = fetchurl {
      url = &#34;mirror://cpan/authors/id/S/SI/SIMONW/Cal-DAV-0.6.tar.gz&#34;;
      sha256 = &#34;e436ecb61db9a2fa3ba4b2111149dfd31bdf7aa6acbc12cc49584e50db63e79b&#34;;
    };
    propagatedBuildInputs = [ DataICal HTTPDAV LWP ];
    meta = {
      description = &#34;A CalDAV client&#34;;
      license = with lib.licenses; [ artistic1 gpl1Plus ];
    };
  };
</code></pre>

<p>Add the expression in alphabetical order to <a href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/top-level/perl-packages.nix">pkgs/top-level/perl-packages.nix</a>. Only copy/paste the “Nix expression” after the <code>===</code> characters into the file.</p>

<p>To test the patch, spin-up a <code>nix-shell</code> which includes the new Perl module. Create the <code>default.nix</code> expression file in any working directory:</p>

<pre><code class="language-bash">cat &lt;&lt;EOF &gt; default.nix 
with (import &lt;nixpkgs&gt; {});
let
  CalDAV = perlPackages.buildPerlPackage {
    pname = &#34;Cal-DAV&#34;;
    version = &#34;0.6&#34;;
    src = fetchurl {
      url = &#34;mirror://cpan/authors/id/S/SI/SIMONW/Cal-DAV-0.6.tar.gz&#34;;
      sha256 = &#34;e436ecb61db9a2fa3ba4b2111149dfd31bdf7aa6acbc12cc49584e50db63e79b&#34;;
    };
    propagatedBuildInputs = [ perlPackages.DataICal perlPackages.HTTPDAV perlPackages.LWP ];
    meta = {
      description = &#34;A CalDAV client&#34;;
      license = with lib.licenses; [ artistic1 gpl1Plus ];
    };
  };

in
mkShell {
  buildInputs = [ CalDAV perl ];
  # putting perl here is only required when not using NixOS, this tell you want Nix perl binary
}
EOF
</code></pre>

<p>The expression includes the result of the previous <code>nix-generate-from-cpan Cal::DAV</code> with slight modifications.</p>

<p>Notice that <code>propagatedBuildInputs</code> needs to refer to already installed packages prefixed by <code>perlPackages</code>.</p>

<p>More information on <a href="https://nixos.org/manual/nixpkgs/stable/#how-to-develop">how to develop with nix-shell</a>.</p>

<p><a href="https://dataswamp.org/~solene/2021-09-18-nix-cpan-pip.html#_Perl">Solènes article</a> nicely shows how the <a href="https://nixos.org/guides/nix-pills/basics-of-language"><code>let</code> expression</a> can also include an entirely new block of code to define a variable. In this example, the let expression uses the <a href="https://nixos.org/manual/nixpkgs/stable/#ssec-perl-packaging"><code>buildPerlPackage</code> function</a>, which is a <a href="https://nixos.org/guides/nix-pills/generic-builders">“builder”</a> for building Perl packages (as the name indicates).</p>

<p>With that said, you can launch the development shell to test any Perl script with the newly added Perl library as follows:</p>

<pre><code class="language-bash">nix-shell
</code></pre>

<p>If you don&#39;t want to create a “descriptive” shell expression, you can also launch the shell more in an ad-hoc fashion using the following command:</p>

<pre><code class="language-bash">nix-shell -p perlPackages.CalDAV perl -I nixpkgs=~/Downloads/nixpkgs.git
</code></pre>

<p>See also the example for Perl in the <a href="https://nixos.org/manual/nix/stable/command-ref/nix-shell#examples"><code>nix-shell</code> Manual</a>.</p>

<p>If you are happy with how the module works in the <code>nix-shell</code>, you can <a href="https://nixos.org/manual/nixpkgs/stable/#submitting-changes-making-patches">add it to your system/profile</a> (using <code>nix-env</code> or <code>nixos-rebuild</code>) and even <a href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md">contribute it to the upstream <code>&lt;nixpkgs&gt;</code> repository</a>.</p>

<p>This post mostly reminds myself of all the new terminology I learned the past few days.</p>

<div style="text-align:center; font-size: 0.8em">
<a href="https://write.in0rdr.ch/feed">🛜 RSS</a> | <a href="https://m.in0rdr.ch/in0rdr">🐘 Fediverse</a> | <a href="https://chat.in0rdr.ch/#/guest?join=p0c@conference.in0rdr.ch">💬 XMPP</a>
</div>
]]></content:encoded>
      <guid>https://write.in0rdr.ch/h1how-to-test-nixpkg-perl-module-addition-h1</guid>
      <pubDate>Sun, 10 Sep 2023 18:18:10 +0000</pubDate>
    </item>
  </channel>
</rss>