I apologize for my absence in the blogging world as of late - as my last post showed, I have been going down the Nix/NixOS rabbit hole and working on some personal business projects that will be out in the coming months. There has been extensive learning, deep diving, and exciting revelation that I am all too stoked to share.
But, one thing I figured I would share that has me excited recently is how Nix has made publishing tooling that I need extremely easy, so much so that any git repo becomes callable via a nix-run
command. This has permitted me to start putting out some small tools and working on others that I want to get out into the world. It will also be my go-to method for deploying projects in the future.
Nix flakes transform every Git repo into a reproducible, hermetically-sealed build environment. Unlike traditional package managers that rely on system state, this creates a mathematical guarantee: same inputs & same outputs, forever. You become your own package manager, allowing the tools and programs you build to be easily shared with anyone.
Here’s how I have been doing it.
Step One: create a public git repo.#
Do this however you so choose, I have been making all my repos via the gh cil like so:
gh repo create --public repo-name
Step Two: Add a flake.nix#
You can do this with nix flake init
or just steal one of mine and repurpose it for the sake of doing this quickly:
curl -O https://raw.githubusercontent.com/jblais493/go-api-key/master/flake.nix
Step Three: Build out your tool.#
I have been writing most of my tooling in Go as it is a very nice compilation. You will see in my flake that I specify the build directory and name of the binary here:
# Rename binary from go-secrets to secretspostInstall = '' mv $out/bin/go-api-key $out/bin/keygen'';
When I told Claude about this, it responded with:
Go’s static compilation + Nix’s hermetic builds = deployment nirvana.
Indeed.
Step Four: nix build#
Run nix build
in your shell, and the tool will then be compiled and ready for pushing to your git repo.
Step Five: Push to your repo you made in step one, and pull down the program:#
You can now pull the program down from your git repo (and everyone else in the world running nix can, too!):
nix run github:githubUSERNAME/tool-name
There you have it. Portable tooling without packaging or gatekeeping. Not only does this permit your CLI tools and scripts to be accessed on any machine running nix (the package manager, not OS) - but you can deploy web projects, desktop apps, whatever you want - just like so.
I will discuss how nix has made my development environments insanely enjoyable with devenv + direnv in the coming days. I have been sleeping on nix for far too long it seems!
As always, God bless, and until next time.
If you enjoyed this post, consider supporting my work by Buying me a Coffee, Checking out my book, or sending me an email to tell me what you think.