<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>bodby — notes and code, shared as I go</title>
  <link href="https://bodby.me/atom.xml" rel="self"/>
  <link href="https://bodby.me/"/>
  <id>https://bodby.me/</id>
  <updated>2026-10-25T00:00:00Z</updated>
  <author><name>bodby</name></author>
  <entry>
    <title>Nix shell for Factor</title>
    <link href="https://bodby.me/notes/factor-nix-shell/"/>
    <id>https://bodby.me/notes/factor-nix-shell/</id>
    <updated>2026-10-25T00:00:00Z</updated>
    <summary>Setting FACTOR_ROOTS in a Nix dev shell</summary>
    <content type="html">&lt;p&gt;Both snippets below assume you either only have &lt;code&gt;extra/&lt;/code&gt; or have all your vocabs in your project root (i.e. next to &lt;code&gt;shell.nix&lt;/code&gt; or &lt;code&gt;flake.nix&lt;/code&gt;). If you have multiple directories, each with vocabs inside, then list them all in &lt;code&gt;FACTOR_ROOTS&lt;/code&gt; separated by a colon (semicolons on Windows, but gross blauegh and Nix doesn’t work there as of writing this anwyays).&lt;/p&gt;
&lt;h2&gt;Classic Nix&lt;/h2&gt;
&lt;p&gt;If you don’t use flakes:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-nix&quot;&gt;mkShellNoCC {
  packages = [ factor-lang ];
  env.FACTOR_ROOTS = toString ./.;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Flakes&lt;/h2&gt;
&lt;p&gt;Since &lt;code&gt;toString ./.&lt;/code&gt; properly evaluates to a store path when using Flakes, &lt;code&gt;FACTOR_ROOTS&lt;/code&gt; won’t be set to the right directory and so changes made in your worktree won’t take effect if you try to &lt;code&gt;factor -run=x&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Instead, write a &lt;code&gt;shellHook&lt;/code&gt; that sets &lt;code&gt;FACTOR_ROOTS&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-nix&quot;&gt;mkShellNoCC {
  packages = [ factor-lang ];

  shellHook = &#x27;&#x27;
    CWD=&amp;quot;$PWD&amp;quot;
    ROOT=&amp;quot;&amp;quot;

    while [ &amp;quot;$CWD&amp;quot; != &#x27;/&#x27; ] &amp;amp;&amp;amp; [ -z &amp;quot;$ROOT&amp;quot; ]; do
      if [ -e &amp;quot;$CWD/flake.nix&amp;quot; ]; then
        ROOT=&amp;quot;$CWD&amp;quot;
      fi
      CWD=&amp;quot;$(dirname &amp;quot;$CWD&amp;quot;)&amp;quot;
    done

    if [ -n &amp;quot;$ROOT&amp;quot; ]; then
      export FACTOR_ROOTS=&amp;quot;$ROOT&amp;quot;
    fi
  &#x27;&#x27;;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Using &lt;code&gt;$PWD&lt;/code&gt; directly won’t set it to the right value if you &lt;code&gt;nix develop&lt;/code&gt; in a subdirectory.&lt;/p&gt;</content>
  </entry>
</feed>
