waseigo
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.
Trending in Blog Posts
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
krasenyp
It mostly worked means it didn’t work. Good job getting it there though.
waseigo
It was an experiment that I could have avoided, had I looked more closely at
:disksup.get_disk_info/1, which immediately returns the disk-usage info (regardless of the update interval).Some comments on HackerNews were adamantly against letting LLMs write C, and after running
splinton the C file, I don’t blame them… An excerpt:Summary
Version 1.0.0 with the NIF in Rust coming soon.
Also, I really hate the entire “vibe-coding” process; it turns me into a stupid part of a slow loop. I feel the need to understand what I’m doing, but also know that I have no time to dig into Rust or OS internals. Nevertheless, I feel compelled to finish the “re-vibe-coding” in Rust, to at least release something that isn’t as broken as the prior versions.
dimitarvp
Should have asked me in a DM, would have told you to use Rust from the get go.
Now if I can only fix the strange out-of-memory in the GitHub CI runners, I’d be able to finally release my library… (It’s not because of Rust though, my tests so far have put it somewhere in the native building stack in a previous stage of the entire process, or a compile-time switch.)
If you have questions how to best work with Rustler, just ask.
waseigo
Thanks @dimitarvp! I looked at what
mix rustler.newcreated and saw that it different from what many older articles online were talking about.From then on, it was pretty smooth sailing (if you exclude how much I hate vibe-coding lol).
Here it is: disk_space | Hex v1.0.0
It now works on Linux, macOS, Windows and Elixir 1.14 to 1.18 (probably also 1.18.4) and Erlang/OTP 25 to 27 (probably also 28) and the 4 BSDs with their Elixir and Erlang/OTP versions from their respective package repositories.
And geez, HackerNews really dislikes C…
dimitarvp
As they should. Are you surprised?
waseigo
Are you kidding me? After seeing the output of
I’m not surprised. I’m very positively surprised by Rust though.
splint, I’m in awe at Linux, if anythingBut I’ll stick with Elixir!
dimitarvp
Why not actively use both, like me?
Making stuff work with C is nearly the same as making stuff work with Python: it is working despite the language. Not because of it.
waseigo
I’d have to learn Rust, and since 2023 I’ve decided to spend at least 5 years non-stop on Elixir. It brings me joy to write Elixir code. I know it sounds corny, but it’s true.
Edit: And I really enjoy writing Elixir-related books. I learn, I figure things out, I document my learning for others. Triple win. Brings me back to my development-engineer days at ABB when I was doing the same for every design/development project (develop the thing, document the results, the process and the pitfalls)–that company had an incredible documentation culture at the time.
dimitarvp
I love Elixir and so far to me it is irreplaceable (9.5 years after discovering it). It covers aspects that so many other languages / runtimes don’t even dare begin tackling (Rust and Go are exceptions but they just don’t take the problem seriously enough and as such kind of accidentally try to invent their own BEAM, badly).
I am saying that my attention can be on multiple things. Focus is hugely important and it’s been a lackluster part of my methods (one that I am actively fixing lately) but I also find it extremely important to have more tools in my bag so I can practice the “right tool for the job” confidently.
waseigo
I hear you. I dabbled in Go for a while, and I generally like it, but most of all the generation of a single binary that can bundle frontend code, too.
If I had the time, I’d learn Go and Rust next to Elixir. Zig would be the next one on my list.
Knowing many programming languages and their ecosystem also helps with cross-polination of ideas.
For example, on a plain-PHP backend I’ve been maintaining, I got tired of the same query-params and request-body validations in every route handler, so I wrote two classes that make it possible to do this:
That’s thanks to my continued exposure to Ecto, which makes the use of schemas and changesets seem like a very good way of doing things.
It doesn’t yet track the state of changes to avoid updating unchanged fields, but has already helped cut down massively on code repetition. Plus, I enjoyed bringing a bit of Elixir flavor into a PHP codebase.