XGQT's blog: Posts tagged 'powershell'urn:https-xgqt-gitlab-io:-blog-tags-powershell-html2023-12-17T22:59:12Z.NET in Gentoo in 2023urn:https-xgqt-gitlab-io:-blog-posts-2023-12-17-net-in-gentoo-in-20232023-12-17T22:59:12Z2023-12-17T22:59:12ZMaciej Barć
<h2 id="net-ecosystem-in-gentoo-in-year-2023">.NET ecosystem in Gentoo in year 2023</h2>
<p>The Gentoo Dotnet project introduced better support for building .NET-based software using the <code>nuget</code>, <code>dotnet-pkg-base</code> and <code>dotnet-pkg</code> eclasses. This opened new opportunities of bringing new packages depending on .NET ecosystem to the official Gentoo ebuild repository and helping developers that use <code>dotnet-sdk</code> on Gentoo.</p>
<p>New software requiring .NET is constantly being added to the main Gentoo tree, among others that is:</p>
<ul>
<li><a href="https://packages.gentoo.org/packages/app-shells/pwsh">PowerShell</a> for Linux,</li>
<li><a href="https://packages.gentoo.org/packages/app-office/denaro">Denaro</a> — finance application,</li>
<li><a href="https://packages.gentoo.org/packages/games-emulation/ryujinx">Ryujinx</a> — NS emulator,</li>
<li><a href="https://packages.gentoo.org/packages/games-strategy/openra">OpenRA</a> — RTS engine for Command & Conquer, Red Alert and Dune2k,</li>
<li><a href="https://packages.gentoo.org/packages/media-gfx/pinta">Pinta</a> — graphics program,</li>
<li><a href="https://packages.gentoo.org/packages/media-gfx/pablodraw">Pablodraw</a> — Ansi, Ascii and RIPscrip art editor,</li>
<li><a href="https://packages.gentoo.org/packages/dev-lang/dafny">Dafny</a> — verification-aware programming language</li>
<li>many <a href="https://packages.gentoo.org/maintainer/dotnet@gentoo.org#dev-dotnet">packages</a> aimed straight at developing .NET projects.</li></ul>
<p>Dotnet project is also looking for new maintainers and users who are willing to help out here and there. Current state of .NET in Gentoo is very good but we can still do a lot better.</p>
<h2 id="special-thanks-to-people-who-helped-out">Special thanks to people who helped out</h2>
<ul>
<li><a href="https://github.com/navi-desu/">Anna Figueiredo Gomes</a></li>
<li><a href="https://github.com/mid-kid/">Esteve Varela Colominas</a></li>
<li><a href="https://github.com/Tatsh/">Andrew Udvare</a></li></ul>
<h2 id="links-to-bugs-and-announcements">Links to bugs and announcements</h2>
<ul>
<li>Bugs
<ul>
<li><a href="https://gitlab.gentoo.org/dotnet/gentoo-dotnet-2023/-/issues/1">gentoo-dotnet–2023/1</a></li>
<li><a href="https://bugs.gentoo.org/900597">900597</a></li></ul></li>
<li>Github PRs
<ul>
<li><a href="https://github.com/gentoo/gentoo/pull/21112/">21112</a></li>
<li><a href="https://github.com/gentoo/gentoo/pull/21451/">21451</a></li>
<li><a href="https://github.com/gentoo/gentoo/pull/29309/">29309</a></li>
<li><a href="https://github.com/gentoo/gentoo/pull/32109/">32109</a></li>
<li><a href="https://github.com/gentoo/gentoo/pull/33940/">33940</a></li></ul></li>
<li>Active Gentoo .NET projects
<ul>
<li><a href="https://gitlab.gentoo.org/dotnet/gentoo-dotnet-guide/">gentoo-dotnet-guide</a></li>
<li><a href="https://gitlab.gentoo.org/dotnet/gentoo-dotnet-maintainer-tools/">gentoo-dotnet-maintainer-tools</a></li>
<li><a href="https://gitlab.gentoo.org/dotnet/csharp-gentoodotnetinfo/">csharp-gentoodotnetinfo</a></li>
<li><a href="https://gitlab.gentoo.org/dotnet/eselect-dotnet/">eselect-dotnet</a></li>
<li><a href="https://gitlab.gentoo.org/dotnet/eselect-pwsh/">eselect-pwsh</a></li></ul></li></ul>Installing PowerShell modules via Portageurn:https-xgqt-gitlab-io:-blog-posts-2023-04-07-installing-powershell-modules-via-portage2023-04-07T02:26:43Z2023-04-07T02:26:43ZMaciej Barć
<h1 id="building-powershell">Building PowerShell</h1>
<p>As a part of my work of modernizing the way .NET SDK packages are distributed in Gentoo I delved into packaging a from-source build of PowerShell for Gentoo using the <a href="https://gitlab.com/xgqt/gentoo-dotnet-2023/-/blob/master/eclass/dotnet-pkg.eclass">dotnet-pkg eclass</a>.</p>
<p>Packaging <code>pwsh</code> was a little tricky but I got a lot of help from reading the Alpine Linux’s <a href="https://git.alpinelinux.org/aports/tree/community/powershell/APKBUILD?id=26cea8a350cfadb92820b471d11e9d00d4e020a6">APKBUILD</a>. I had to generate special C# code bindings with <code>ResGen</code> and repackage the PowerShell tarball. Other than this trick, restoring and building PowerShell was pretty straight forward with the NuGet package management support from the <code>dotnet-pkg.eclass</code>.</p>
<p>Alternatively if you do not want to build PowerShell you can install the binary package, I have in plans to keep that package around even after we get the non-binary <a href="https://gitlab.com/xgqt/gentoo-dotnet-2023/-/tree/master/app-shells/pwsh">app-shells/pwsh</a> into the official Gentoo ebuild repository.</p>
<h1 id="why-install-modules-via-portage">Why install modules via Portage?</h1>
<p>But why stop on PowerShell when we can also package multiple PS modules?</p>
<p>Installing modules via Portage has many benefits:</p>
<ul>
<li>better version control,</li>
<li>more control over global install,</li>
<li>no need to enable PS Gallery,</li>
<li>sandboxed builds,</li>
<li>using system .NET runtime.</li></ul>
<h1 id="merging-the-modules">Merging the modules</h1>
<p>PowerShell’s method of finding modules is at follows: check paths from the <code>PSModulePath</code> environment variable for directories containing valid <code>.psd1</code> files which define the PS modules.</p>
<p>By default <code>pwsh</code> tries to find modules in paths:</p>
<ul>
<li>user’s modules directory — <code>~/.local/share/powershell/Modules</code></li>
<li>system modules directory in <code>/usr/local</code> — <code>/usr/local/share/powershell/Modules</code></li>
<li><code>Modules</code> directory inside the <code>pwsh</code> home — for example <code>/usr/share/pwsh-7.3/Modules</code></li></ul>
<p>Because we do not want to touch either <code>/usr/local</code> nor <code>pwsh</code> home, we embed a special environment variable inside the <code>pwsh</code> launcher script to extend the path where <code>pwsh</code> looks for PS modules. The new module directory is located at <code>/usr/share/GentooPowerShell/Modules</code>.</p>
<div class="brush: shell">
<div class="source">
<table class="sourcetable">
<tbody>
<tr>
<td class="linenos">
<div class="linenodiv">
<pre><span class="normal">1</span>
<span class="normal">2</span></pre></div></td>
<td class="code">
<div>
<pre><span></span>dotnet-pkg-utils_append_launchervar<span class="w"> </span><span class="se">\</span>
<span class="w"> </span><span class="s1">'PSModulePath="${PSModulePath}:/usr/share/GentooPowerShell/Modules:"'</span>
</pre></div></td></tr></tbody></table></div>
</div>
<p>So every PowerShell module will install it’s files inside <code>/usr/share/GentooPowerShell/Modules</code>.</p>
<p>To follow PS module location convention we add to that path a segment for the real module name and a segment for module version. This also enables us to have proper multi-slotting because most of the time the modules will not block installing other versions.</p>
<p>Take a look at this example from the <a href="https://gitlab.com/xgqt/gentoo-dotnet-2023/-/blob/cfcb425e097a3782d067d4abaca2ec06be3f4fde/app-pwsh/posh-dotnet/posh-dotnet-1.2.3.ebuild">app-pwsh/posh-dotnet–1.2.3</a> ebuild:</p>
<div class="brush: shell">
<div class="source">
<table class="sourcetable">
<tbody>
<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></pre></div></td>
<td class="code">
<div>
<pre><span></span>src_install<span class="o">()</span><span class="w"> </span><span class="o">{</span>
<span class="w"> </span>insinto<span class="w"> </span>/usr/share/GentooPowerShell/Modules/<span class="si">${</span><span class="nv">PN</span><span class="si">}</span>/<span class="si">${</span><span class="nv">PV</span><span class="si">}</span>
<span class="w"> </span>doins<span class="w"> </span><span class="si">${</span><span class="nv">PN</span><span class="si">}</span>.psd1<span class="w"> </span><span class="si">${</span><span class="nv">PN</span><span class="si">}</span>.psm1
<span class="w"> </span>einstalldocs
<span class="o">}</span>
</pre></div></td></tr></tbody></table></div>
</div>
<p>And that is it. Some packages do not even need to be compiled, they just need files placed into specific location. But when compilation of C# code is needed we have <code>dotnet-pkg</code> to help.</p>