<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sasha Devol</title>
    <description>The latest articles on DEV Community by Sasha Devol (@tastycode).</description>
    <link>https://dev.to/tastycode</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F26725%2Fc801106e-0a5e-461d-9844-47c4fa658f4e.jpeg</url>
      <title>DEV Community: Sasha Devol</title>
      <link>https://dev.to/tastycode</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tastycode"/>
    <language>en</language>
    <item>
      <title>Circles of Truth: Overcomplicating simple commands</title>
      <dc:creator>Sasha Devol</dc:creator>
      <pubDate>Fri, 16 Aug 2024 17:48:41 +0000</pubDate>
      <link>https://dev.to/tastycode/circles-of-truth-overcomplicating-simple-commands-2lp2</link>
      <guid>https://dev.to/tastycode/circles-of-truth-overcomplicating-simple-commands-2lp2</guid>
      <description>&lt;p&gt;While fixing my air conditioner, I needed to frequently debug what HTTP requests my ESP32 was sending to my hue bridge's API when it activates or deactivates my 3d printed dremel-based pump to prevent excess condensate from flooding my flat and jeopardizing my housing situation. If you use nix/home-manager, then my approach could be of perverse interest to you. If not, then feel free to gawk at how complicated I can implement a single alias command.&lt;/p&gt;

&lt;p&gt;When my ESP32 detects a pulled-down voltage at &lt;code&gt;GPIO4&lt;/code&gt;, this means that the water level has reached the upper limit in my condensation collection container. This is because i have &lt;code&gt;GND&lt;/code&gt; ran out to the bottom of the bin, and &lt;code&gt;GPIO4&lt;/code&gt; is set to &lt;code&gt;INPUT_PULLUP&lt;/code&gt;. &lt;code&gt;GPIO3&lt;/code&gt; is set to the same but I do not turn on the pump for this pin. Instead, i use that pin to know when to turn off the pump once the pump has been turned on at the upper limit.&lt;/p&gt;

&lt;p&gt;When the &lt;code&gt;ESP32&lt;/code&gt; sends a request to my local hue bridge to activate the smartplug where I have my dremel pump plugged in, and nothing happens, I need to figure out what HTTP request is actually going out. I use &lt;a href="https://pipedream.com/requestbin" rel="noopener noreferrer"&gt;requestbin&lt;/a&gt; for this. The publicly available service became sporadically available many years back, but you can still run it via docker. Once its running, it gives me a URL i can substitute for the Hue bridge API endpoint, I ca inspect&lt;/p&gt;

&lt;p&gt;The command for this is&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run --rm -it -p 8000:8000 weshigbee/requestbin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's just a little too unwieldy to remember, so I'd like to make a permanent utility to run it. While writing this, i realize i could have just aliased it and added it to my zsh config inside my home-manager config under &lt;code&gt;programs.zsh.shellAliases&lt;/code&gt; However, in my early-morning sleepy haze, I opted to create a solution as arguably over-engineered as it may be forgivingly considered succinctly practical. I have &lt;code&gt;~/.local/bin&lt;/code&gt; in my &lt;code&gt;home.sessionPath&lt;/code&gt;. I have slowly been evolving how I manage these utilities for the last few months. The primary difference between files in &lt;code&gt;~/.local/bin&lt;/code&gt; and a shell alias is that files in that directory can be shell scripts. For example &lt;code&gt;~/.local/bin/update&lt;/code&gt; used to be a shell alias bound to &lt;code&gt;NIXPKGS\_ALLOW\_INSECURE=1 darwin-rebuild switch --flake "$HOME/.nixpkgs#$(hostname)" --impure&lt;/code&gt; Today, it's a shell script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; ~/.nixpkgs
&lt;span class="c"&gt;# capture local binary utilities&lt;/span&gt;
&lt;span class="k"&gt;for &lt;/span&gt;file &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="sb"&gt;`&lt;/span&gt;find ~/.local/bin/ &lt;span class="nt"&gt;-maxdepth&lt;/span&gt; 1 &lt;span class="nt"&gt;-type&lt;/span&gt; f&lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do 
    &lt;/span&gt;&lt;span class="nb"&gt;mv&lt;/span&gt; &lt;span class="nv"&gt;$file&lt;/span&gt; ~/.nixpkgs/user-specific/sdevol/.local/bin/
&lt;span class="k"&gt;done
&lt;/span&gt;git add user-specific/sdevol/.local/bin

&lt;span class="c"&gt;# capture the espanso configuration&lt;/span&gt;
&lt;span class="nb"&gt;cp&lt;/span&gt; &lt;span class="nt"&gt;-R&lt;/span&gt; ~/.config/espanso/&lt;span class="k"&gt;*&lt;/span&gt; ~/.nixpkgs/user-specific/sdevol/.config/espanso/
git add ~/.nixpkgs/user-specific/sdevol/.config/espanso

&lt;span class="c"&gt;# do the thing&lt;/span&gt;
&lt;span class="nv"&gt;NIXPKGS_ALLOW_INSECURE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1 darwin-rebuild switch &lt;span class="nt"&gt;--flake&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$HOME&lt;/span&gt;&lt;span class="s2"&gt;/.nixpkgs#&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;hostname&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="nt"&gt;--impure&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;My nix configuration lives in &lt;code&gt;~/.nixpkgs&lt;/code&gt;. Notice that we are moving files from &lt;code&gt;~/.local/bin&lt;/code&gt; into the nix repo under &lt;code&gt;~/.nixpkgs/user-specific/sdevol/.local/bin&lt;/code&gt;. As you might have began to suspect, there's some plumbing inside &lt;code&gt;~/.nixpkgs/user-specific/sdevol/home.nix&lt;/code&gt; that connects some more dots.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight nix"&gt;&lt;code&gt;&lt;span class="c"&gt;# let &lt;/span&gt;
  &lt;span class="nv"&gt;localBinDir&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sx"&gt;./.local/bin&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;# this is relative to the current file, so this is ~/.nixpkgs/user-specific/sdevol/.local/bin&lt;/span&gt;
  &lt;span class="nv"&gt;localBinFiles&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kr"&gt;builtins&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;attrNames&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kr"&gt;builtins&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;readDir&lt;/span&gt; &lt;span class="nv"&gt;localBinDir&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nv"&gt;mkLocalBin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;source&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sx"&gt;./.local/bin&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="nv"&gt;recursive&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="kn"&gt;in&lt;/span&gt; &lt;span class="kr"&gt;rec&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nv"&gt;manual&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;manpages&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;enable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nv"&gt;home&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;username&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"tastycode"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nv"&gt;file&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
      &lt;span class="kr"&gt;builtins&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;listToAttrs&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kr"&gt;map&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="nv"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;".local/bin/&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
          &lt;span class="nv"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;mkLocalBin&lt;/span&gt; &lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;})&lt;/span&gt;
        &lt;span class="nv"&gt;localBinFiles&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s2"&gt;".config/zed/settings.json"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="nv"&gt;source&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sx"&gt;./zed.settings.json&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
          &lt;span class="nv"&gt;recursive&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;};&lt;/span&gt;
        &lt;span class="s2"&gt;".config/espanso"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="nv"&gt;source&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;config&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;lib&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;file&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nv"&gt;mkOutOfStoreSymlink&lt;/span&gt; &lt;span class="sx"&gt;.config/espanso&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
          &lt;span class="nv"&gt;recursive&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, when I type &lt;code&gt;update&lt;/code&gt;. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Any non-symlinks are moved into the nix configuration &lt;/li&gt;
&lt;li&gt;My nix configuration is rebuilt, within which the nix configuration iterates through all files in its local directory &lt;code&gt;user-specific/sdevol/.local/bin&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;A &lt;code&gt;home.file.\*&lt;/code&gt; reference is generated with a symlink configuration for each. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This sequence thus replaces non-symlinked files in &lt;code&gt;~/.local/bin&lt;/code&gt; with symlinks to version-controlled references to the same. Therefore, once i have decided i want to make a permanent command for &lt;code&gt;docker run --rm -it -p 8000:8000 weshigbee/requestbin&lt;/code&gt;. All I need to do is , press up on my keyboard so that the docker command is at the prompt and modify the command to read. &lt;code&gt;echo docker run --rm -it -p 8000:8000 weshigbee/requestbin &amp;gt; ~/.local/bin/requestbin&lt;/code&gt; then &lt;code&gt;ls ~/.local/bin&lt;/code&gt; reads&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ls -l ~/.local/bin                          ✔  26ms   18.1.0   10:24:11 
lrwxr-xr-x  - tastycode 16 Aug 09:49 readlinks -&amp;gt; /nix/store/m2aiz6gszyk3i4hbqn93dpwpsi6f805p-home-manager-files/.local/bin/readlinks
.rw-r--r-- 54 tastycode 16 Aug 10:24 requestbin
lrwxr-xr-x  - tastycode 16 Aug 09:49 screensnap -&amp;gt; /nix/store/m2aiz6gszyk3i4hbqn93dpwpsi6f805p-home-manager-files/.local/bin/screensnap
lrwxr-xr-x  - tastycode 16 Aug 09:49 tastyspace -&amp;gt; /nix/store/m2aiz6gszyk3i4hbqn93dpwpsi6f805p-home-manager-files/.local/bin/tastyspace
lrwxr-xr-x  - tastycode 16 Aug 09:49 update -&amp;gt; /nix/store/m2aiz6gszyk3i4hbqn93dpwpsi6f805p-home-manager-files/.local/bin/update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, i just run &lt;code&gt;update&lt;/code&gt; Now, &lt;code&gt;requestbin&lt;/code&gt; is in &lt;code&gt;~/.local/bin/requestbin&lt;/code&gt; but it has been swapped out with a symlink to my nix config's manifested version of the script.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lrwxr-xr-x - tastycode 16 Aug 10:26 requestbin -&amp;gt; /nix/store/vgrdrcnjyhykkx1xq29kg6g2jhbqg0hx-home-manager-files/.local/bin/requestbin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Honestly, that's less keystrokes than adding a shellAlias. If you aren't sold on using nix to manage your system's configuration, this seems overcomplicated. If you use nix, then you are already probably frustrated at keeping your nix configuration in sync with quick little optimizations you do on a regular basis. With nix, everything is source controlled. If you are a dotfiler, then you would still have to commit your changes. I guess that's true in my solution as well. The &lt;code&gt;git add&lt;/code&gt; in my &lt;code&gt;update&lt;/code&gt; is probably the most dubious element of this entire schrade.  That is unless, you are using &lt;a href="https://github.com/martinvonz/jj" rel="noopener noreferrer"&gt;jj&lt;/a&gt;. &lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
