Jekyll2023-10-22T15:46:06+00:00https://matthewrhone.dev/feed.xmlMatthew Rhone dot DevOne IT Professional's journey back to his programming roots. Matthew RhoneNixOS Package (Install/Uninstall) Guide2023-10-22T00:00:00+00:002023-10-22T00:00:00+00:00https://matthewrhone.dev/nixos-package-guide<h2 id="searching-for-a-package">Searching for a Package</h2>
<p>There are several ways to search for packages in NixOS (each way may return more results or information):</p>
<p><code class="language-plaintext highlighter-rouge">nix search <package-name></code>, <code class="language-plaintext highlighter-rouge">nix-env --query <package-name></code>, or <code class="language-plaintext highlighter-rouge">nix-env -qa '<package-name></code></p>
<p>You can also visit a web-based interface on NixOS’ site to <a href="https://nixos.org/nixos/packages.html">search</a> for the a package.</p>
<h2 id="installing-a-package">Installing a Package</h2>
<h3 id="installing-a-package-via-nix-env-user-wide">Installing a Package via nix-env (user-wide)</h3>
<p>To install a package just in your regular user environment, you can use <code class="language-plaintext highlighter-rouge">nix-env -i <packange-name></code>.</p>
<p>You can also pretend to install adding the <code class="language-plaintext highlighter-rouge">--dry-run</code> parameter at the end of any operation of <code class="language-plaintext highlighter-rouge">nix-env</code>.</p>
<p>To see a list of installed packages that were installed via <code class="language-plaintext highlighter-rouge">nix-env</code> run:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>nix-env --query --installed
</code></pre></div></div>
<h3 id="installing-a-package-via-configurationnix-system-wide">Installing a Package via Configuration.nix (system-wide)</h3>
<p>To add additional package to be install system-wide (this can also be done at install time), look for the following lines and add additional packages separated each by a space:</p>
<figure class="highlight"><pre><code class="language-nix" data-lang="nix"><span class="nv">environment</span><span class="o">.</span><span class="nv">systemPackages</span> <span class="o">=</span> <span class="kn">with</span> <span class="nv">pkgs</span><span class="p">;</span> <span class="p">[</span>
<span class="nv">wget</span> <span class="nv">vim</span> <span class="nv">nano</span> <span class="nv">zsh</span> <span class="nv">file</span>
<span class="p">];</span></code></pre></figure>
<p>Now you have to rebuild the environment. You can either run <code class="language-plaintext highlighter-rouge">sudo nixos-rebuild</code> to have it rebuild and not switch your current operating environment to the changes or <code class="language-plaintext highlighter-rouge">sudo nixos-rebuild switch</code> to have it switch automatically. When you reboot your PC, you will be able to pick previous builds, so if it broke something, you can go back in time.</p>
<h3 id="installing-a-package-via-confignix-user-wide">Installing a Package via config.nix (user-wide)</h3>
<p>Create the following folder and file: <code class="language-plaintext highlighter-rouge">~/.nixpkgs/config.nix</code>. We can define multiple groups of packages that can be installed all at once with just one command. Put the following in to this new file:</p>
<figure class="highlight"><pre><code class="language-nix" data-lang="nix"><span class="p">{</span> <span class="nv">pkgs</span> <span class="p">}:</span>
<span class="kd">let</span>
<span class="kn">inherit</span> <span class="p">(</span><span class="nv">pkgs</span><span class="p">)</span> <span class="nv">lib</span> <span class="nv">buildEnv</span><span class="p">;</span>
<span class="kn">in</span> <span class="p">{</span>
<span class="nv">allowUnfree</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span> <span class="c"># allow non-free, non-open source packages to install</span>
<span class="c"># if you are using Chromium, this is likely something you want to enable an option for</span>
<span class="nv">chromium</span> <span class="o">=</span> <span class="p">{</span>
<span class="nv">enableWideVine</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span> <span class="c"># enable the DRM to allow things like Netflix to work</span>
<span class="p">};</span>
<span class="nv">packageOverrides</span> <span class="o">=</span> <span class="nv">pkgs</span><span class="p">:</span> <span class="p">{</span>
<span class="nv">desktopDev</span> <span class="o">=</span> <span class="nv">lib</span><span class="o">.</span><span class="nv">lowPrio</span> <span class="p">(</span><span class="nv">buildEnv</span> <span class="p">{</span>
<span class="nv">name</span> <span class="o">=</span> <span class="s2">"devEnvApps"</span><span class="p">;</span>
<span class="nv">paths</span> <span class="o">=</span> <span class="kn">with</span> <span class="nv">pkgs</span><span class="p">;</span> <span class="p">[</span>
<span class="nv">vscode</span>
<span class="nv">elixir</span>
<span class="nv">nodejs</span>
<span class="nv">git</span>
<span class="nv">file</span>
<span class="nv">unzip</span>
<span class="p">];</span>
<span class="p">});</span>
<span class="nv">kdeApplications</span> <span class="o">=</span> <span class="nv">lib</span><span class="o">.</span><span class="nv">lowPrio</span> <span class="p">(</span><span class="nv">buildEnv</span> <span class="p">{</span>
<span class="nv">name</span> <span class="o">=</span> <span class="s2">"kdeApps"</span><span class="p">;</span>
<span class="nv">paths</span> <span class="o">=</span> <span class="kn">with</span> <span class="nv">pkgs</span><span class="p">;</span> <span class="p">[</span>
<span class="nv">latte-dock</span>
<span class="nv">yakuake</span>
<span class="nv">kate</span>
<span class="nv">kdeconnect</span>
<span class="nv">okular</span>
<span class="nv">ark</span>
<span class="p">];</span>
<span class="p">});</span>
<span class="p">};</span>
<span class="p">}</span></code></pre></figure>
<p>In order to install one of these groups of applications, you just need to install using the <code class="language-plaintext highlighter-rouge">name = ""</code> one, for example, to install the KDE group, <code class="language-plaintext highlighter-rouge">nix-env -i kdeApps</code>. The other part that is unique like the <code class="language-plaintext highlighter-rouge">kdeApplications</code> doesn’t matter as much, just has to be unique in this instance.</p>
<h2 id="uninstalling-a-package">Uninstalling a Package</h2>
<h3 id="uninstalling-system-wide">Uninstalling System-Wide</h3>
<p>To uninstall a package, remove it from the pkg list in the <code class="language-plaintext highlighter-rouge">configuration.nix</code> file:</p>
<figure class="highlight"><pre><code class="language-nix" data-lang="nix"><span class="nv">environment</span><span class="o">.</span><span class="nv">systemPackages</span> <span class="o">=</span> <span class="kn">with</span> <span class="nv">pkgs</span><span class="p">;</span> <span class="p">[</span>
<span class="nv">wget</span> <span class="nv">vim</span> <span class="nv">nano</span> <span class="nv">zsh</span> <span class="nv">file</span>
<span class="p">];</span></code></pre></figure>
<p>Just like when you add a new pacakge, you will now you have to rebuild the environment. You can either run <code class="language-plaintext highlighter-rouge">sudo nixos-rebuild</code> to have it rebuild and not switch your current operating environment to the changes or <code class="language-plaintext highlighter-rouge">sudo nixos-rebuild switch</code> to have it switch automatically.</p>
<h3 id="uninstalling-user-wide">Uninstalling User-Wide</h3>
<p>To uninstall a package, run:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>nix-env --uninstall <package-name>
</code></pre></div></div>
<h2 id="enabling-flatpak">Enabling Flatpak</h2>
<p>To enable flatpak add the following to your <code class="language-plaintext highlighter-rouge">configuration.nix</code> file (first line needed if not doing Gnome):</p>
<figure class="highlight"><pre><code class="language-nix" data-lang="nix"><span class="nv">xdg</span><span class="o">.</span><span class="nv">portal</span><span class="o">.</span><span class="nv">enable</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span> <span class="c"># only needed if you are not doing Gnome</span>
<span class="nv">services</span><span class="o">.</span><span class="nv">flatpak</span><span class="o">.</span><span class="nv">enable</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span></code></pre></figure>
<p>After adding anything into the <code class="language-plaintext highlighter-rouge">configuration.nix</code> file like more packages, you need to rebuild NixOS:</p>
<p>You can either run <code class="language-plaintext highlighter-rouge">sudo nixos-rebuild</code> to have it rebuild and not switch your current operating environment to the changes or <code class="language-plaintext highlighter-rouge">sudo nixos-rebuild switch</code> to have it switch automatically.</p>
<p>Once flatpak is installed, you need to add the usual flathub repo:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
</code></pre></div></div>
<h2 id="updating-nixos">Updating NixOS</h2>
<h3 id="updating-system-wide">Updating System-Wide</h3>
<p>To update NixOS, you need to update the channel (<code class="language-plaintext highlighter-rouge">nix-channel --update</code>), to force a rebuild of the packages defined in your <code class="language-plaintext highlighter-rouge">configuration.nix</code>, you would have to do use the <code class="language-plaintext highlighter-rouge">nixos-rebuild</code> command. You can update both the channel and rebuild things in one command, <code class="language-plaintext highlighter-rouge">nixos-rebuild --upgrade switch</code>. If your update broke things, you can roll back with <code class="language-plaintext highlighter-rouge">nix-channel --rollback</code> and rebuild again.</p>
<h3 id="updating-user-wide">Updating User-Wide</h3>
<p>To update your packages, run the same <code class="language-plaintext highlighter-rouge">nix-channel --update</code> as in a system-wide update and then run the following command: <code class="language-plaintext highlighter-rouge">nix-env -u</code>.</p>
<h2 id="switching-to-the-unstable-nixpkgs-repository">Switching to the Unstable NixPkgs Repository</h2>
<h3 id="switching-system-wide">Switching System-Wide</h3>
<p>Do this under root or as sudo:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>nix-channel --add https://nixos.org/channels/nixos-unstable nixos
</code></pre></div></div>
<p>As with making changes to <code class="language-plaintext highlighter-rouge">configuration.nix</code>, you will want to do your <code class="language-plaintext highlighter-rouge">nixos-rebuild</code> commands to get it current.</p>
<h3 id="switching-user-wide">Switching User-Wide</h3>
<p>Do this under your normal account and not as root or sudo:</p>
<p>Remove nixos channel (stable):</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>nix-channel --remove stable
</code></pre></div></div>
<p>Now any applications you install will be done from the unstable repo. Do a <code class="language-plaintext highlighter-rouge">nix-env -u</code> to get current. If you get a warning about a name conflict, you may have to remove the old channel:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>nix-channel --add https://nixos.org/channels/nixos-unstable nixos
</code></pre></div></div>
<p>Then you need to re-add it as above. Only one channel can be named <code class="language-plaintext highlighter-rouge">nixos</code> at a time.</p>
<h3 id="install-specific-packages-from-unstable">Install Specific Packages from Unstable</h3>
<p>You can manually clone the github <a href="https://github.com/NixOS/nixpkgs">repo</a> that contains nixos-unstable. This will allow you to install some applications that are from unstable without having to install all of your packages from unstable. To clone it:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git clone https://github.com/NixOS/nixpkgs.git ~/nixpkgs-unstable
</code></pre></div></div>
<p>To install a package from the cloned Unstable NixPkgs repo where <code class="language-plaintext highlighter-rouge">~/nixpkgs-unstable/</code> is the location of the cloned repo:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>nix-env -iA <packagename> -f ~/nixpkgs-unstable/
</code></pre></div></div>
<p>Also, be sure to do a <code class="language-plaintext highlighter-rouge">git pull</code> on the cloned repo before doing operations so it is current.</p>
<h2 id="cleanup-old-versions-of-packages">Cleanup Old Versions of Packages</h2>
<h3 id="cleanup-old-packages-user-wide">Cleanup Old Packages (user-wide)</h3>
<p>To remove all old packages but the current one, run this:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>nix-env --delete-generations old
</code></pre></div></div>
<p>You can delete based on different generations (like generation 10, 11, 14):</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>nix-env --delete-generations 10 11 14
</code></pre></div></div>
<p>Or you can delete generations based on how old they are (14 days in this example):</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>nix-env --delete-generations 14d
</code></pre></div></div>
<p>Then run the garbage collector to delete them:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>nix-store --gc
</code></pre></div></div>
<p>To see what will be deleted:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>nix-store --gc --print-dead
</code></pre></div></div>
<h3 id="cleanup-old-packages-all-users">Cleanup Old Packages (all users)</h3>
<p>To cleanup the garbage collection on all users (you may have to add sudo to have it clean everything):</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>nix-collect-garbage -d
</code></pre></div></div>
<h3 id="useful-references">Useful References</h3>
<ul>
<li><a href="https://nixos.org/nix/manual/">NixOS Manual</a></li>
</ul>Matthew RhoneAn Everyday Guide to Regular Package Management Tasks in NixOS.Installing Microsoft Edge Browser in NixOS2021-01-17T00:00:00+00:002021-01-17T00:00:00+00:00https://matthewrhone.dev/nixos-edge-browser<h1 id="download-overlay-files-from-gitlab-repo">Download Overlay Files from GitLab Repo</h1>
<p>Clone the git repo from GitLab (original repo):</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git clone https://gitlab.com/zanc/overlays.git
</code></pre></div></div>
<p>If the edge version is out of date, you may try cloning from my fork if I have updated it:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git clone https://gitlab.com/kritoke/overlays.git
</code></pre></div></div>
<h1 id="install-microsoft-edge-browser-dev">Install Microsoft Edge Browser (dev)</h1>
<p>Go into the newly cloned folder and run the installation process to have it install in your local user environment:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>cd overlays
nix-env -i -E 'f: with import <nixpkgs> { overlays = import ./overlays.nix; config = { allowUnfree = true; }; }; microsoft-edge-dev'
</code></pre></div></div>
<p>Doing a pull on the GitLab folder after it’s been updated and re-running the same install process should update it to the newer version.</p>
<h1 id="manually-updating-to-newer-versions">Manually Updating to Newer Versions</h1>
<p>If neither repos are updated, you can try to update the default.nix file in the microsoft-edge-dev folder yourself.</p>
<p>Browse out to the <code class="language-plaintext highlighter-rouge">https://packages.microsoft.com/repos/edge/pool/main/m/microsoft-edge-dev/</code> address and find the latest version and update that in the version area of the <code class="language-plaintext highlighter-rouge">.nix</code> file.</p>
<p>Now we need to generate a sri hash for the new version of the file, download it and run the following to get the new hash to put in the <code class="language-plaintext highlighter-rouge">.nix</code> file:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>nix hash-file --sri microsoft-edge-dev_xx.xx.xx.xx-1_amd64.deb
</code></pre></div></div>
<p>Go back into the overlays folder and run the same install command as before.</p>
<p>In some instances when you try to run Edge, it may give an error related to missing a library. You will have to research to find the package name that needs to be added.</p>
<p>For example, after one update, I had to add <code class="language-plaintext highlighter-rouge">xorg.libxshmfence</code> to the <code class="language-plaintext highlighter-rouge">lib.makeLibraryPath</code> area of the <code class="language-plaintext highlighter-rouge">.nix</code> file due to it asking about a file related to that library. When you add the new library to that, re-run the install command as before to see if it resolves the issue.</p>
<h1 id="troubleshooting-run-issues">Troubleshooting Run Issues</h1>
<p>If you have issues running edge, you may have to append the following:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>LD_LIBRARY_PATH=/run/current-system/sw/lib microsoft-edge-dev
</code></pre></div></div>
<p>In some cases, after updating from an older version, you may have to restart your machine even after killing any existing <code class="language-plaintext highlighter-rouge">msedge</code> processes.</p>
<h1 id="useful-references">Useful References</h1>
<p><a href="https://github.com/NixOS/nixpkgs/issues/101223">Microsoft Edge Dev #101223 Github Issue with Run Fix</a></p>
<p><a href="https://gitlab.com/zanc/overlays/">Original GitLab Repo with Microsoft Edge .Nix File</a></p>Matthew RhoneA simple guide to get the dev version of Microsoft Edge Browser installed in NixOS.Setting Up nix-shell and Visual Studio Code to Interact2021-01-17T00:00:00+00:002021-01-17T00:00:00+00:00https://matthewrhone.dev/nixos-vscode-environment<h1 id="why-use-a-shellnix-file">Why use a shell.nix File?</h1>
<p>Using a <code class="language-plaintext highlighter-rouge">shell.nix</code> file will allow you to setup a development environment that is self-contained and does not pollute your regular environment. When you run <code class="language-plaintext highlighter-rouge">nix-shell</code> and you have the <code class="language-plaintext highlighter-rouge">shell.nix</code> file in the same folder, it will automatically get your development tools installed for you. You can also interact with this same environment via an extension in VS Code, without needing to install the development tools in your regular environment.</p>
<h1 id="create-a-shellnix-file">Create a shell.nix File</h1>
<p>Depending on what languages you are working on will impact what your <code class="language-plaintext highlighter-rouge">shell.nix</code> file looks like. It could be something as simple as this if you just need ruby:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
nativeBuildInputs = [ pkgs.buildPackages.ruby_2_7 ];
}
</code></pre></div></div>
<p>For Elixir or Erlang development, it may look like this:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
# nativeBuildInputs is usually what you want -- tools you need to run
nativeBuildInputs = [
pkgs.buildPackages.elixir
pkgs.buildPackages.nodejs
pkgs.buildPackages.erlang
pkgs.buildPackages.rebar3
];
}
</code></pre></div></div>
<h1 id="install-the-extension-in-visual-studio-code">Install the Extension in Visual Studio Code</h1>
<p>Install the <a href="https://marketplace.visualstudio.com/items?itemName=arrterian.nix-env-selector">Nix Environment Selector</a> extension in Visual Studio Code and select <code class="language-plaintext highlighter-rouge">shell.nix</code> when you open your workspace/folder. If you need access to the same files in the integrated terminal, you just have to run nix-shell in the terminal in the folder that has the <code class="language-plaintext highlighter-rouge">shell.nix</code> file.</p>
<h2 id="other-things-to-note">Other Things to Note</h2>
<p>You could also launch <code class="language-plaintext highlighter-rouge">nix-shell</code> in command line and then run <code class="language-plaintext highlighter-rouge">code .</code> to launch it in the same environment without needing to install the extension at all.</p>
<h2 id="useful-references">Useful References</h2>
<p><a href="https://marketplace.visualstudio.com/items?itemName=arrterian.nix-env-selector">Nix Environment Selector Visual Studio Code Extension</a></p>
<p><a href="https://cah6.github.io/technology/nix-haskell-2/">Exploring Nix & Haskell Part 2: Dev Tools & IDE Integration</a>, has some advanced discussion of targetting older channels in NixOS.</p>Matthew RhoneA simple guide to get Visual Studio Code to operate with nix-shell, allowing you to keep your development environments self-contained to their own projects.Installing Extensions in Visual Studio Code on NixOS2021-01-17T00:00:00+00:002021-01-17T00:00:00+00:00https://matthewrhone.dev/nixos-vscode<h1 id="getting-vs-code-with-extensions-installed-unstable-repo">Getting VS Code with Extensions Installed (Unstable Repo)</h1>
<p>Some extensions may or may not work right on NixOS unless they are done via the NixOS way. The following is kind of a <a href="https://discourse.nixos.org/t/vscode-extensions-setup/1801">hack</a> to keep the main NixOS running regular channel, but Visual Studio Code from the unstable branch:</p>
<p>Create a <code class="language-plaintext highlighter-rouge">vscode.nix</code> in your <code class="language-plaintext highlighter-rouge">/etc/nixos/</code> folder with the following:</p>
<figure class="highlight"><pre><code class="language-nix" data-lang="nix"><span class="p">{</span> <span class="nv">config</span><span class="p">,</span> <span class="nv">pkgs</span><span class="p">,</span> <span class="nv">lib</span><span class="p">,</span> <span class="o">...</span> <span class="p">}:</span> <span class="p">{</span>
<span class="nv">options</span> <span class="o">=</span> <span class="p">{</span>
<span class="nv">vscode</span><span class="o">.</span><span class="nv">extensions</span> <span class="o">=</span> <span class="nv">lib</span><span class="o">.</span><span class="nv">mkOption</span> <span class="p">{</span> <span class="nv">default</span> <span class="o">=</span> <span class="p">[];</span> <span class="p">};</span>
<span class="nv">vscode</span><span class="o">.</span><span class="nv">user</span> <span class="o">=</span> <span class="nv">lib</span><span class="o">.</span><span class="nv">mkOption</span> <span class="p">{</span> <span class="p">};</span> <span class="c"># <- Must be supplied</span>
<span class="nv">vscode</span><span class="o">.</span><span class="nv">homeDir</span> <span class="o">=</span> <span class="nv">lib</span><span class="o">.</span><span class="nv">mkOption</span> <span class="p">{</span> <span class="p">};</span> <span class="c"># <- Must be supplied</span>
<span class="nv">nixpkgs</span><span class="o">.</span><span class="nv">latestPackages</span> <span class="o">=</span> <span class="nv">lib</span><span class="o">.</span><span class="nv">mkOption</span> <span class="p">{</span> <span class="nv">default</span> <span class="o">=</span> <span class="p">[];</span> <span class="p">};</span>
<span class="p">};</span>
<span class="nv">config</span> <span class="o">=</span> <span class="p">{</span>
<span class="c">###</span>
<span class="c"># DIRTY HACK</span>
<span class="c"># This will fetch latest packages on each rebuild, whatever channel you are at</span>
<span class="nv">nixpkgs</span><span class="o">.</span><span class="nv">overlays</span> <span class="o">=</span> <span class="p">[</span>
<span class="p">(</span><span class="nv">self</span><span class="p">:</span> <span class="nv">super</span><span class="p">:</span>
<span class="kd">let</span> <span class="nv">latestPkgs</span> <span class="o">=</span> <span class="kr">import</span> <span class="p">(</span><span class="kr">fetchTarball</span> <span class="sx">https://github.com/nixos/nixpkgs-channels/archive/nixpkgs-unstable.tar.gz</span><span class="p">)</span> <span class="p">{</span>
<span class="nv">config</span><span class="o">.</span><span class="nv">allowUnfree</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
<span class="p">};</span>
<span class="kn">in</span> <span class="nv">lib</span><span class="o">.</span><span class="nv">genAttrs</span> <span class="nv">config</span><span class="o">.</span><span class="nv">nixpkgs</span><span class="o">.</span><span class="nv">latestPackages</span> <span class="p">(</span><span class="nv">pkg</span><span class="p">:</span> <span class="nv">latestPkgs</span><span class="o">.</span><span class="s2">"</span><span class="si">${</span><span class="nv">pkg</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span>
<span class="p">)</span>
<span class="p">];</span>
<span class="c"># END DIRTY HACK</span>
<span class="c">###</span>
<span class="nv">environment</span><span class="o">.</span><span class="nv">systemPackages</span> <span class="o">=</span> <span class="p">[</span> <span class="nv">pkgs</span><span class="o">.</span><span class="nv">vscode</span> <span class="p">];</span>
<span class="nv">system</span><span class="o">.</span><span class="nv">activationScripts</span><span class="o">.</span><span class="nv">fix-vscode-extensions</span> <span class="o">=</span> <span class="p">{</span>
<span class="nv">text</span> <span class="o">=</span> <span class="s2">''</span><span class="err">
</span><span class="s2"> EXT_DIR=</span><span class="si">${</span><span class="nv">config</span><span class="o">.</span><span class="nv">vscode</span><span class="o">.</span><span class="nv">homeDir</span><span class="si">}</span><span class="s2">/.vscode/extensions</span><span class="err">
</span><span class="s2"> mkdir -p $EXT_DIR</span><span class="err">
</span><span class="s2"> chown </span><span class="si">${</span><span class="nv">config</span><span class="o">.</span><span class="nv">vscode</span><span class="o">.</span><span class="nv">user</span><span class="si">}</span><span class="s2">:users $EXT_DIR</span><span class="err">
</span><span class="s2"> for x in </span><span class="si">${</span><span class="nv">lib</span><span class="o">.</span><span class="nv">concatMapStringsSep</span> <span class="s2">" "</span> <span class="kr">toString</span> <span class="nv">config</span><span class="o">.</span><span class="nv">vscode</span><span class="o">.</span><span class="nv">extensions</span><span class="si">}</span><span class="s2">; do</span><span class="err">
</span><span class="s2"> ln -sf $x/share/vscode/extensions/* $EXT_DIR/</span><span class="err">
</span><span class="s2"> done</span><span class="err">
</span><span class="s2"> chown -R </span><span class="si">${</span><span class="nv">config</span><span class="o">.</span><span class="nv">vscode</span><span class="o">.</span><span class="nv">user</span><span class="si">}</span><span class="s2">:users $EXT_DIR</span><span class="err">
</span><span class="s2"> ''</span><span class="p">;</span>
<span class="nv">deps</span> <span class="o">=</span> <span class="p">[];</span>
<span class="p">};</span>
<span class="p">};</span>
<span class="p">}</span></code></pre></figure>
<p>In your <code class="language-plaintext highlighter-rouge">imports</code> area of the main <code class="language-plaintext highlighter-rouge">/etc/nixos/configuration.nix</code>, add <code class="language-plaintext highlighter-rouge">./vscode.nix</code>.</p>
<p>Add the following to your <code class="language-plaintext highlighter-rouge">configuration.nix</code> file (changing <code class="language-plaintext highlighter-rouge"><username></code> to your username), this will install your extensions in the local vscode extensions folder (also note that I have the Nix extension and wakatime extensions installing using built-in extensions from Nix, remove if you do not want them):</p>
<figure class="highlight"><pre><code class="language-nix" data-lang="nix"> <span class="nv">vscode</span><span class="o">.</span><span class="nv">user</span> <span class="o">=</span> <span class="s2">"<username>"</span><span class="p">;</span>
<span class="nv">vscode</span><span class="o">.</span><span class="nv">homeDir</span> <span class="o">=</span> <span class="s2">"/home/<username>"</span><span class="p">;</span>
<span class="nv">vscode</span><span class="o">.</span><span class="nv">extensions</span> <span class="o">=</span> <span class="kn">with</span> <span class="nv">pkgs</span><span class="o">.</span><span class="nv">vscode-extensions</span><span class="p">;</span> <span class="p">[</span>
<span class="nv">bbenoist</span><span class="o">.</span><span class="nv">Nix</span>
<span class="nv">WakaTime</span><span class="o">.</span><span class="nv">vscode-wakatime</span>
<span class="p">];</span> </code></pre></figure>
<p>In a lot of cases, NixOS may give you problems with some lesser known extensions (will get undefined variable errors). A couple extensions have their own .nix files that help to get more problematic extensions installed like <code class="language-plaintext highlighter-rouge">Wakatime</code> or the <code class="language-plaintext highlighter-rouge">cpptools</code> extension. You can check <a href="https://github.com/NixOS/nixpkgs/tree/master/pkgs/misc/vscode-extensions">here</a> to see a list of ones you may want to specify as I did in the above example.</p>
<p>To have other extensions that are not already being installed from my previous example, we need to give it four pieces of information for each extension. The best way to do this is to install your extensions the normal way in <code class="language-plaintext highlighter-rouge">vscode</code> and then execute this command from their <a href="https://github.com/NixOS/nixpkgs/raw/master/pkgs/misc/vscode-extensions/update_installed_exts.sh">github</a>. This will give us a list of the extensions and the related information it needs in the format it needs. So now we can adapt the previous code block by giving it more information, in this case we added some <code class="language-plaintext highlighter-rouge">eslint</code> and an <code class="language-plaintext highlighter-rouge">elixir language server</code> extensions to illustrate adding new extensions:</p>
<figure class="highlight"><pre><code class="language-nix" data-lang="nix"> <span class="nv">vscode</span><span class="o">.</span><span class="nv">user</span> <span class="o">=</span> <span class="s2">"<username>"</span><span class="p">;</span>
<span class="nv">vscode</span><span class="o">.</span><span class="nv">homeDir</span> <span class="o">=</span> <span class="s2">"/home/<username>"</span><span class="p">;</span>
<span class="nv">vscode</span><span class="o">.</span><span class="nv">extensions</span> <span class="o">=</span> <span class="kn">with</span> <span class="nv">pkgs</span><span class="o">.</span><span class="nv">vscode-extensions</span><span class="p">;</span> <span class="p">[</span>
<span class="nv">bbenoist</span><span class="o">.</span><span class="nv">Nix</span>
<span class="nv">WakaTime</span><span class="o">.</span><span class="nv">vscode-wakatime</span>
<span class="p">]</span> <span class="o">++</span> <span class="nv">pkgs</span><span class="o">.</span><span class="nv">vscode-utils</span><span class="o">.</span><span class="nv">extensionsFromVscodeMarketplace</span> <span class="p">[</span>
<span class="p">{</span>
<span class="nv">name</span> <span class="o">=</span> <span class="s2">"vscode-eslint"</span><span class="p">;</span>
<span class="nv">publisher</span> <span class="o">=</span> <span class="s2">"dbaeumer"</span><span class="p">;</span>
<span class="nv">version</span> <span class="o">=</span> <span class="s2">"2.1.14"</span><span class="p">;</span>
<span class="nv">sha256</span> <span class="o">=</span> <span class="s2">"113w2iis4zi4z3sqc3vd2apyrh52hbh2gvmxjr5yvjpmrsksclbd"</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">{</span>
<span class="nv">name</span> <span class="o">=</span> <span class="s2">"elixir-ls"</span><span class="p">;</span>
<span class="nv">publisher</span> <span class="o">=</span> <span class="s2">"JakeBecker"</span><span class="p">;</span>
<span class="nv">version</span> <span class="o">=</span> <span class="s2">"0.6.2"</span><span class="p">;</span>
<span class="nv">sha256</span> <span class="o">=</span> <span class="s2">"1vmfvjh916cqjva874a751zyjx77zyj0x8ia9hw3f09mvbvdbzqh"</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">{</span>
<span class="nv">name</span> <span class="o">=</span> <span class="s2">"vs-code-prettier-eslint"</span><span class="p">;</span>
<span class="nv">publisher</span> <span class="o">=</span> <span class="s2">"rvest"</span><span class="p">;</span>
<span class="nv">version</span> <span class="o">=</span> <span class="s2">"0.4.1"</span><span class="p">;</span>
<span class="nv">sha256</span> <span class="o">=</span> <span class="s2">"0inqkn574zjzg52qcnmpfhsbzbi6vxnr2lrqqff9mh5vvvqsm6v0"</span><span class="p">;</span>
<span class="p">}</span>
<span class="p">];</span> </code></pre></figure>
<p>To get updated versions and sha256 keys, you will need to run the same script from <a href="https://github.com/NixOS/nixpkgs/raw/master/pkgs/misc/vscode-extensions/update_installed_exts.sh">github</a> as before. Replace the changed/update extensions. As you would with doing any other changes to the <code class="language-plaintext highlighter-rouge">configuration.nix</code> file, you will need to run the <code class="language-plaintext highlighter-rouge">nixos-rebuild</code> command to have to install <code class="language-plaintext highlighter-rouge">vscode</code> and the extensions you defined.</p>
<h3 id="useful-references">Useful References</h3>
<p><a href="https://discourse.nixos.org/t/vscode-extensions-setup/1801">NixOS Discoure - VSCode extensions setup post</a></p>
<p><a href="https://nixos.wiki/wiki/Vscode">NixOS Wiki - Vscode</a></p>Matthew RhoneA simple guide to get Visual Studio Code and its extensions installed on NixOS.Getting Jekyll to Work in NixOS2021-01-16T00:00:00+00:002021-01-16T00:00:00+00:00https://matthewrhone.dev/jekyll-in-nixos<h2 id="prep-work-before-install">Prep Work Before Install</h2>
<p>In NixOS, due to how it organizes files/packages, it cannot run Ruby Gems in the typical way, so you will run into issues with the gems installing right via <strong>Bundler</strong>.</p>
<p>Go into the folder that you want to run/install <strong>Jekyll</strong> in and type the following:</p>
<p><code class="language-plaintext highlighter-rouge">nix-shell -p bundler</code></p>
<p>This will get you in an environment that provides bundler for use of getting a <code class="language-plaintext highlighter-rouge">Gemfile</code> and associated <code class="language-plaintext highlighter-rouge">Gemfile.lock</code> built.</p>
<p>If it is a new installation for <strong>Jekyll</strong> (without a Gemfile), we need to create a Gemfile and make it writeable:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>bundle init
chmod +w Gemfile
</code></pre></div></div>
<p>Add jekyll to the Gemfile:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>bundler add jekyll
</code></pre></div></div>
<p>We need to make sure it doesn’t try to install the Gems when adding gems:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>bundler package --no-install --path vendor
</code></pre></div></div>
<p>Now we need to generate a <em>gemset.nix</em> that will allow installations of gems:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>bundix
</code></pre></div></div>
<p>We should then delete the unneeded vendor folder since it would have put the files in the nix store anyway:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>rm -rf vendor
</code></pre></div></div>
<p>There is a much easier way to automate this whole task (if you have a Gemfile already). We can put everything in one line of code that will allow bundler to update and updating of the <em>gemset.nix</em> file as well:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>nix-shell -p bundler -p bundix --run 'bundler update; bundler lock; bundler package --no-install --path vendor; bundix; rm -rf vendor'
</code></pre></div></div>
<h2 id="install-of-jekyll-and-nix-shell-setup">Install of Jekyll and Nix-Shell Setup</h2>
<p>Now we need to create a file that will allow us to then compile the <strong>Jekyll</strong> and its dependencies when launching <code class="language-plaintext highlighter-rouge">nix-shell</code>. Now create a <strong><em>default.nix</em></strong> file in the folder of the <strong>Jekyll</strong> site (make up a name for the <code class="language-plaintext highlighter-rouge">your-package</code>, doesn’t have to exist anywhere):</p>
<figure class="highlight"><pre><code class="language-nix" data-lang="nix"><span class="kn">with</span> <span class="p">(</span><span class="kr">import</span> <span class="o"><</span><span class="nv">nixpkgs</span><span class="o">></span> <span class="p">{});</span>
<span class="kd">let</span> <span class="nv">env</span> <span class="o">=</span> <span class="nv">bundlerEnv</span> <span class="p">{</span>
<span class="nv">name</span> <span class="o">=</span> <span class="s2">"your-package"</span><span class="p">;</span>
<span class="kn">inherit</span> <span class="nv">ruby</span><span class="p">;</span>
<span class="nv">gemfile</span> <span class="o">=</span> <span class="sx">./Gemfile</span><span class="p">;</span>
<span class="nv">lockfile</span> <span class="o">=</span> <span class="sx">./Gemfile.lock</span><span class="p">;</span>
<span class="nv">gemset</span> <span class="o">=</span> <span class="sx">./gemset.nix</span><span class="p">;</span>
<span class="p">};</span>
<span class="kn">in</span> <span class="nv">stdenv</span><span class="o">.</span><span class="nv">mkDerivation</span> <span class="p">{</span>
<span class="nv">name</span> <span class="o">=</span> <span class="s2">"your-package"</span><span class="p">;</span>
<span class="nv">buildInputs</span> <span class="o">=</span> <span class="p">[</span><span class="nv">env</span> <span class="nv">bundler</span> <span class="nv">ruby</span><span class="p">];</span>
<span class="p">}</span></code></pre></figure>
<p>Now we need to run <code class="language-plaintext highlighter-rouge">nix-shell</code> (it should by default use <strong><em>default.nix</em></strong>, if it doesn’t, run <code class="language-plaintext highlighter-rouge">nix-shell default.nix</code>). Run the following to get into the environment:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>nix-shell
</code></pre></div></div>
<p>If we are trying to start fresh without any config, we need to run a special command to generate the default config and files without bundler:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>jekyll new --force --skip-bundle .
</code></pre></div></div>
<p>After running that, when trying to run <strong>Jekyll</strong>, you may get an error about it not having packages like <code class="language-plaintext highlighter-rouge">minima</code>. We need to get out of <code class="language-plaintext highlighter-rouge">nix-shell</code> (run <code class="language-plaintext highlighter-rouge">exit</code>). The easiest thing to update everything would just be to run that one liner (should take care of updating everything):</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>nix-shell -p bundler -p bundix --run 'bundler update; bundler lock; bundler package --no-install --path vendor; bundix; rm -rf vendor'
</code></pre></div></div>
<p>If you changed the default theme from the default theme in the config, you may need to add it to the Gemfile your self or do a <code class="language-plaintext highlighter-rouge">nix-shell -p bundler --run 'bundle add <package-name>'</code>. This same line would be the easiest way to add new gems to the Gemfile. You would then need to rerun the one liner.</p>
<p>Even creating a small bash script could be handy to run:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>#!/usr/bin/env bash
nix-shell -p bundler -p bundix --run 'bundler update; bundler lock; bundler package --no-install --path vendor; bundix; rm -rf vendor'
echo "Ready for nix-shell"
</code></pre></div></div>
<h2 id="autorunning-jekyll-tasks-in-nix-shell">Autorunning Jekyll Tasks in Nix-Shell</h2>
<p>If you want <strong>Jekyll</strong> to automatically run the web server each time you go into <code class="language-plaintext highlighter-rouge">nix-shell</code>, change your <strong><em>default.nix</em></strong> to resemble this:</p>
<figure class="highlight"><pre><code class="language-nix" data-lang="nix"><span class="kn">with</span> <span class="p">(</span><span class="kr">import</span> <span class="o"><</span><span class="nv">nixpkgs</span><span class="o">></span> <span class="p">{});</span>
<span class="kd">let</span>
<span class="nv">env</span> <span class="o">=</span> <span class="nv">bundlerEnv</span> <span class="p">{</span>
<span class="nv">name</span> <span class="o">=</span> <span class="s2">"your-package"</span><span class="p">;</span>
<span class="kn">inherit</span> <span class="nv">ruby</span><span class="p">;</span>
<span class="nv">gemfile</span> <span class="o">=</span> <span class="sx">./Gemfile</span><span class="p">;</span>
<span class="nv">lockfile</span> <span class="o">=</span> <span class="sx">./Gemfile.lock</span><span class="p">;</span>
<span class="nv">gemset</span> <span class="o">=</span> <span class="sx">./gemset.nix</span><span class="p">;</span>
<span class="p">};</span>
<span class="kn">in</span> <span class="nv">stdenv</span><span class="o">.</span><span class="nv">mkDerivation</span> <span class="p">{</span>
<span class="nv">name</span> <span class="o">=</span> <span class="s2">"your-package"</span><span class="p">;</span>
<span class="nv">buildInputs</span> <span class="o">=</span> <span class="p">[</span><span class="nv">env</span> <span class="nv">ruby</span><span class="p">];</span>
<span class="nv">shellHook</span> <span class="o">=</span> <span class="s2">''</span><span class="err">
</span><span class="s2"> exec </span><span class="si">${</span><span class="nv">env</span><span class="si">}</span><span class="s2">/bin/jekyll serve --watch</span><span class="err">
</span><span class="s2"> ''</span><span class="p">;</span>
<span class="p">}</span></code></pre></figure>
<p>You can make other <code class="language-plaintext highlighter-rouge">.nix</code> files that could automate different tasks. One good example would be if you are using algolia for searching. You can change the <code class="language-plaintext highlighter-rouge">exec ${env}/bin/jekyll serve --watch</code> to <code class="language-plaintext highlighter-rouge">exec ${env}/bin/jekyll algolia</code> to have it index your posts and name it a different file like <code class="language-plaintext highlighter-rouge">algolia.nix</code>. To run it, you would type <code class="language-plaintext highlighter-rouge">nix-shell algolia.nix</code>.</p>
<h2 id="other-things-to-note">Other Things to Note</h2>
<p>As of writing this blog, Nokogiri 1.11 and up has an issue with trying to compile within the nix-shell environment. Changing the Gemfile to require 1.10.10, <code class="language-plaintext highlighter-rouge">gem "nokogiri", "~> 1.10.10"</code> and then clearing out the Gemfile.lock and rerunning <code class="language-plaintext highlighter-rouge">bundler</code> and <code class="language-plaintext highlighter-rouge">bundix</code> should fix it.</p>
<p>If you use <code class="language-plaintext highlighter-rouge">shell.nix</code> in your development workflow, you will need to run <code class="language-plaintext highlighter-rouge">nix-shell default.nix</code> instead of just running <code class="language-plaintext highlighter-rouge">nix-shell</code>.</p>
<h3 id="useful-references">Useful References</h3>
<ul>
<li><a href="https://savo.rocks/programming/2017/01/30/jekyll-setup-in-nixos.html">Jekyll setup in NixOS</a></li>
<li><a href="https://jekyllrb.com/tutorials/using-jekyll-with-bundler/">Using Jekyll with Bundler</a></li>
<li><a href="https://stesie.github.io/2016/08/nixos-github-pages-env">Building a Jekyll Environment with NixOS</a></li>
<li><a href="https://nathan.gs/2019/04/19/using-jekyll-and-nix-to-blog/">Using Jekyll and Nix to blog</a></li>
</ul>Matthew RhoneA Simple Guide on How to Get Jekyll Working (Using Bundler) in NixOSGuide to Getting Raw Image Previews in Gnome’s File Manager2020-11-22T00:00:00+00:002020-11-22T00:00:00+00:00https://matthewrhone.dev/raw-image-previews-gnome<p>Install <code class="language-plaintext highlighter-rouge">ufraw</code> in your distribution.</p>
<p>For Ubuntu:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sudo apt-get install ufraw
</code></pre></div></div>
<p>For Fedora:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>sudo dnf install ufraw
</code></pre></div></div>
<p>Create a thumbnailer file (<code class="language-plaintext highlighter-rouge">/usr/share/thumbnailers/ufraw.thumbnailer</code>) if you do not already have one after installing:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>[Thumbnailer Entry]
Exec=/usr/bin/ufraw-batch --embedded-image --out-type=png --size=%s %u --overwrite --silent --output=%o
MimeType=image/x-3fr;image/x-adobe-dng;image/x-arw;image/x-bay;image/x-canon-cr2;image/x-canon-crw;image/x-cap;image/x-cr2;image/x-crw;image/x-dcr;image/x-dcraw;image/x-dcs;image/x-dng;image/x-drf;image/x-eip;image/x-erf;image/x-fff;image/x-fuji-raf;image/x-iiq;image/x-k25;image/x-kdc;image/x-mef;image/x-minolta-mrw;image/x-mos;image/x-mrw;image/x-nef;image/x-nikon-nef;image/x-nrw;image/x-olympus-orf;image/x-orf;image/x-panasonic-raw;image/x-pef;image/x-pentax-pef;image/x-ptx;image/x-pxn;image/x-r3d;image/x-raf;image/x-raw;image/x-rw2;image/x-rwl;image/x-rwz;image/x-sigma-x3f;image/x-sony-arw;image/x-sony-sr2;image/x-sony-srf;image/x-sr2;image/x-srf;image/x-x3f;
</code></pre></div></div>Matthew RhoneHow to get previews of RAW images in your file manager.Installing NPM Packages Globally in NixOS2020-07-11T00:00:00+00:002020-07-11T00:00:00+00:00https://matthewrhone.dev/nixos-npm-globally<p>Since the nix store is immutable and cannot be modified, you need to define a writable location for NPM packages to be installed globally.</p>
<p>Install NodeJS if you haven’t already.</p>
<p>Add the following to your <code class="language-plaintext highlighter-rouge">~/.npmrc</code> to have it put the packages in the <code class="language-plaintext highlighter-rouge">~/.npm-packages</code> folder:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>prefix = ${HOME}/.npm-packages
</code></pre></div></div>
<p>You need to add the npm bin folder to your <code class="language-plaintext highlighter-rouge">PATH</code> in your shell’s rc file (i.e. <code class="language-plaintext highlighter-rouge">.bashrc</code> or <code class="language-plaintext highlighter-rouge">.zshrc</code> for example, so you can access the executables:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>export PATH=~/.npm-packages/bin:$PATH
</code></pre></div></div>
<p>You also need to add the <code class="language-plaintext highlighter-rouge">NODE_PATH</code> to the same file:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>export NODE_PATH=~/.npm-packages/lib/node_modules
</code></pre></div></div>
<p>Doing a <code class="language-plaintext highlighter-rouge">source ./zshrc</code> will allow you to not have to reload your terminal session (assuming you are using <code class="language-plaintext highlighter-rouge">zsh</code> for your shell, change to whatever you are using).</p>Matthew RhoneA simple guide to get NPM Packages to install globally on NixOS.Troubleshooting Wakatime in VS Code on NixOS2020-07-11T00:00:00+00:002020-07-11T00:00:00+00:00https://matthewrhone.dev/nixos-wakatime-vscode<p>When the <strong>Wakatime Extension</strong> gets installed in <strong>Visual Studio Code</strong>, it does not extract the <strong>Wakatime CLI</strong>. This guide is how to have it use the <strong>Wakatime</strong> that is installed in <strong>NixOS</strong>.</p>
<p><em>Note: This explains how to get it working without using the official NixOS method of installing extensions for VS Code.</em></p>
<h2 id="install-wakatime-in-nixos">Install Wakatime in NixOS</h2>
<p>First, install <strong>Wakatime</strong> in <strong>NixOS</strong>:</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>nix-env -i wakatime
</code></pre></div></div>
<p>Make a note of the /nix/store location for the <code class="language-plaintext highlighter-rouge">bin/wakatime</code> file, as we will use it later on.</p>
<h2 id="find-wakatime-extension-location">Find Wakatime Extension Location</h2>
<p>Now you must find the location of run the <code class="language-plaintext highlighter-rouge">wakatime-cli</code> executable for the extension. Ctrl + Shift + I (Help -> Toggle Developer Tools). It will have errors that have <code class="language-plaintext highlighter-rouge">EONET</code> in it and spawn errors. Look for the path where it’s trying to launch from, in my instance, it’s <code class="language-plaintext highlighter-rouge">~/.vscode/extensions/wakatime.vscode-wakatime-4.0.0/wakatime-cli</code>.</p>
<h2 id="create-a-symbolic-link-to-wakatime">Create a Symbolic Link to Wakatime</h2>
<p>I had to create the <code class="language-plaintext highlighter-rouge">wakatime-cli</code> directory in <code class="language-plaintext highlighter-rouge">wakatime.vscode-wakatime-4.0.0</code> and then do a symbolic link to where <code class="language-plaintext highlighter-rouge">nix-env</code> command installed it.</p>
<p>This is an example of the command I used (be sure to change the nix store and <strong>Wakatime Extension</strong> location if different):</p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>ln -s /nix/store/zjzh8fh8gcdlkvaj6i5wpcbd9jki2fj9-wakatime-13.0.7/bin/wakatime ~/.vscode/extensions/wakatime.vscode-wakatime-4.0.0/wakatime-cli/wakatime-cli
</code></pre></div></div>
<p>If you forgot to grab the <code class="language-plaintext highlighter-rouge">/nix/store</code> location for <strong>Wakatime</strong>, you will need to go into the <code class="language-plaintext highlighter-rouge">nix repl</code> and do a search query for it:</p>
<figure class="highlight"><pre><code class="language-nix" data-lang="nix"><span class="nv">nix</span> <span class="nv">repl</span>
<span class="p">:</span><span class="nv">l</span> <span class="o"><</span><span class="nv">nixpkgs</span><span class="o">></span>
<span class="s2">"</span><span class="si">${</span><span class="nv">wakatime</span><span class="si">}</span><span class="s2">"</span></code></pre></figure>
<h2 id="notes">Notes</h2>
<p>Each time the <strong>Wakatime Extension</strong> upgrades to a new version, you may have to repeat the same process.</p>Matthew RhoneA troubleshooting guide to get Wakatime to work in Visual Studio Code on NixOS.