I published my first #Nix / #NixOS library!
Niccup: Hiccup-like HTML Generation in ~120 Lines of Pure Nix.
Transforms Nix expressions into HTML.
The website has some cool examples, I'm especially proud of the quine one that was slightly tricky to get right: https://embedding-shapes.github.io/niccup/examples/quine/
Website: https://embedding-shapes.github.io/niccup/
And a softer introduction blog post with motivation and more background: https://embedding-shapes.github.io/introducing-niccup/
![Examples
let h = inputs.niccup.lib; in
h.render [
"div#main.container"
{ lang = "en"; class = [ "app" "dark" ]; }
[ "h1" "Hello from Nix" ]
[ "p" "Hiccup-style HTML in Nix." ]
(h.comment "List example")
[ "ul" (map (x: [ "li.item" x ]) [ "one" "two" "three" ]) ]
]
Write to file (use nixpkgs writeText):
{ pkgs, inputs, ... }:
pkgs.writeText "index.html" (inputs.niccup.lib.render [ "p" "Hello" ])
Some more involved examples:
art - Generative SVG (Sierpinski triangle)
blog - Multi-page blog with navigation
docs - NixOS module documentation generator
quine - Self-rendering page
The website for niccup is generated dynamically with niccup too, the whole source is ~120 lines of Nix as well](https://files.mastodon.social/media_attachments/files/115/657/616/829/494/790/original/fb96c8dd5d0a0a70.png)