I didn’t really decide to start up a blog.
About a year ago I bought a domain and put up some static pages and never touched it again. The whole idea of sharing what I’m thinking and doing made me nervous, so I just stopped.
But recently I stumbled on the Quartz static site generator. I’ve always been kind of enamored with fun knowledge webs and so this seemed perfect. I looked at the installation instructions and thought “fork to install? Retro.”
So I started playing around; I made a theme, changed the layout in minor ways, and then decided it might finally be time to put this up. But there was a problem.
Forks of public repos on GitHub have to be public. There are ways around this, and honestly I could have just kept the drafts local until I was happy with them and then included them in my fork, or even just set the original as another remote, but now the gears were turning. This feels like a job for a build system!
I’ve been playing around with nix a bunch over the last few months, and when all you have is a hammer, everything looks like a flake.
Nixifying
Using nix, I could create a derivation that would
- Grab my fork of quartz that lives in a public repo on Github
- Grab the content I want to publish from a private repo on github
- Point the quartz build command toward my private content
- Return the resulting static files as the result of derivation
That took a little doing. First, it took a while to figure out why using npx
in the derivation builder was throwing errors. I was using buildNpmPackage, a
function inside of nixpkgs to build quartz, and I was overriding the
buildPhase. But calling npx
was trying to mutate the npx
library in the
nix store, and since that’s immutable it was throwing an error.
What I figured out was that I wanted to use the installPhase
instead, and let
buildNpmPackage handle the build phase entirely. From here, I could bring in
the content from the private repo, and then build
the site using the quartz package that was built in the previous phase. Then
all that’s left is to move the built public folder into the $out
dir, which
is how a derivation communicates with the outside world.
From here we have a directory of built static assets, which is perfect for…
Github Actions
Since we’re just publishing a static site, we can just use GitHub Pages to publish. The Action is super simple, check it out here.