Tech News
← Back to articles

I let LLMs write an Elixir NIF in C; it mostly worked

read original related products more articles

This post documents how I built a cross-platform Elixir NIF in C to get on-demand up-to-date disk-usage stats without relying on os_mon and its disksup service. I had Grok 3 generate the initial C code and Makefile, then iterated through multiple code reviews by Gemini 2.5 Flash and GPT-5 to make it work on Linux, macOS, Windows, and the BSDs (except DragonFlyBSD). Along the way, I ran into typical LLM hiccups that speak volumes about the breathless hyperbole often peddled by LLM vendors, compute providers, and over-enthusiastic consultants, middle managers and executives on LinkedIn. Nevertheless, the result is a working, cross-platform Elixir package on Hex.pm, plus a real-world case study in where LLMs shine, where they fail, and what “human-in-the-loop” can mean in practice. Spoiler alert: the hype is exactly that; even so, we ended up with working code that is, at the very least, a solid starting point for further improvements by actual general intelligence.

What set this off?

I was working on my new book, Elixir File Browsing (readers of Northwind Elixir Traders : it’s not published yet), which is about developing an Elixir client for the undocumented REST API of File Browser . I had reached the point of developing the enough_space_to_download?/3 function that “gates” file downloads from the File Browser server based on whether there is enough space to actually store the file on a local path.

Using Erlang’s os_mon

After looking online for an Elixir function that does this, I found the Check disk space inside elixir thread on ElixirForum. The guidance therein is to use the disksup service of Erlang’s os_mon OS monitor application.

It’s possible to use :disksup.get_disk_info/1 to get the total space, the available space, and the percentage of disk space used, but there are a few caveats:

You have to add :os_mon to the :extra_application in mix.exs , so that you have access to :disksup.get_disk_info/1 .

to the in , so that you have access to . The default configuration of disksup is to check disk space every 30 minutes. It’s configurable, so that’s good.

is to check disk space every 30 minutes. It’s configurable, so that’s good. On Windows, disksup checks the space of “all logical drives of type FIXED_DISK”, which I’m assuming doesn’t include UNCs (e.g., Samba shares), except if you perhaps use the Map Network Drive feature of Windows’ Explorer.

Of those caveats I didn’t particularly care for the third one, though some of my readers or eventual users of the ExFileBrowser library (not yet open-sourced) might be using Windows and might want to download files from a File Browser server to e.g. \\server\share\path .

... continue reading