First post

Posted on || 4 minute read

Table of Contents

First, there was pages.srht.site

SourceHut is awesome!

Who wouldn't like a completely Open Sourced Software (OSS), self-hostable, free to use, Software Development platform?

The SourceHut software suite contains offerings like:

  1. Git hosting
  2. Static page hosting
  3. And much more (check them out if your curiosity is piqued)!

So, static page hosting? And git hosting of said website source??

Yes.

Following their guide for statically hosting websites, I finally got what I wanted; a not-quite self-hosted blog on a domain(read: FQDN) of my choosing!

Unfortunately...

My big issue, that I struggled with for months, if not a year or more - mainly due to (lack of) interest, was figuring out how to make my domain (read: blog.x10an14.dev) "DNS forward in the background to the correct pages.srht.site".

This was DNS magic I'd never been exposed to before.

Solution!

Before (read: almost a year ago), I'm certain that I was unable to simply set a "simple" CNAME record (pointing to pages.srht.site.). Maybe it was because I previously had other <something else>.x10an14.dev DNS records.

For some reason(tm) it worked fine now (as of this writing).

At some point in the future, I will want to add more subdomains, so maybe I'll have to figure out how to use something like ANAME record.

Results of DNS lookup (now that it works):

-> $ dig blog.x10an14.dev

; <<>> DiG 9.18.12 <<>> blog.x10an14.dev
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 54422
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
;; QUESTION SECTION:
;blog.x10an14.dev.              IN      A

;; ANSWER SECTION:
blog.x10an14.dev.       42134   IN      CNAME   pages.sr.ht.
pages.sr.ht.            603734  IN      A       173.195.146.139

;; Query time: 3 msec
;; SERVER: 100.100.100.100#53(100.100.100.100) (UDP)
;; WHEN: Fri Jun 02 00:38:10 CEST 2023
;; MSG SIZE  rcvd: 86


Then, there was a Nix-powered blog!

So, now I could (manually) use the hut to manually publish (tarballed) static content to x10an14.srht.site/!

So, how would I make this development environment reproducible with Nix?

Well, first we need to make a derivation which tarballs the static content:

# Inside flake.nix:

outputs = {...}@inputs: let
	pkgs = import inputs.nixpkgs {inherit system;};
	# The build of the tarball
	tarball = pkgs.stdenv.mkDerivation {
		buildPhase = ''
			mkdir -p $out/share
			tar -cvz index.html > $out/share/${name}-${self.shortRev or "dirty"}.tar.gz
		'';
		name = "blog-tarball";
		src = ./.;
	};
in {
	packages = rec {
		build = tarball;
		default = build;
	};
}

Afterwards, it'd be nice to automate the deployment as much as possible. An issue with Nix, is that no derivation can produce side-effects. So performing things like HTTP requests to send data are by their nature, illegal.

A compromise, could be that we write a script that automates the whole process for us, as if we performed the steps manually:

# Also in the flake.nix:

	# Convenience script for upload
	uploadBlogScript = pkgs.writeShellApplication {
		name = "upload-blog";
		runtimeInputs = with pkgs; [hut];
		text = ''
			declare -a PAGES=(
				"blog.x10an14.dev"
				"x10an14.srht.site"
			)
			for site in "''${PAGES[@]}"; do
				hut pages publish --domain "''${site}" "${tarball}/${tarballPath}"
			done
		'';
	};
in {
	packages = rec {
		build = tarball;
		default = build;
		upload = uploadBlogScript;
	};
}

Full and complete flake.nix can be found over at sourcehut!


Afterwards Zola saved the day

Finally, a theme/framework is of course required to find the blog readable. Currently, the index.html is very simple, and leaves much to be desired:

<!doctype html>
<html lang="en">
<meta charset="utf-8" />
<title>x10an14's blog</title>
<h1>x10an14's blog</h1>
<p>Testy.

After dipping a toe into testing out MkDocs blogging, I started searching for other Static Site Generators (SSGs). I didn't particularly like MkDocs blogging framework for their navigation layout, and I wanted search functionality.

Luckily, some searching of the web helped me come across Jamstack's list/overview of SSGs.

After some perusing, I noticed a Rust-powered SSG that piqued my curiosity Zola.

Considering the below tag lines - found on their landing page - I got even more sold on the idea of investing in learning Zola:

  • "Easy to use"
  • "Everything you need in one binary"
  • "No dependencies"
  • "Augmented MarkDown"