quine - niccup exampleflake.nix<br>description = "Self-rendering quine example using niccup";
inputs = {<br>niccup.url = "github:embedding-shapes/niccup";<br>nixpkgs.follows = "niccup/nixpkgs";<br>};
outputs = { nixpkgs, niccup, ... }:<br>let<br>systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];<br>in {<br>packages = nixpkgs.lib.genAttrs systems (system: {<br>default = import ./build.nix {<br>pkgs = import nixpkgs { inherit system; };<br>h = niccup.lib;<br>};<br>});<br>};
build.nix<br>{ pkgs, h }:
let<br>flakeSrc = builtins.readFile ./flake.nix;<br>buildSrc = builtins.readFile ./build.nix;
css = ''<br>body { max-width: 800px; margin: 2rem auto; padding: 0 1rem; font-family: system-ui; background: #fafafa; color: #333; }<br>@media (prefers-color-scheme: dark) { body { background: #1a1a2e; color: #eee; } }<br>h1 { border-bottom: 2px solid #0066cc; padding-bottom: 0.5rem; }<br>h2 { color: #666; margin-top: 1.5rem; font-size: 1rem; font-family: ui-monospace, monospace; }<br>@media (prefers-color-scheme: dark) { h2 { color: #999; } }<br>pre { background: #1a1a2e; color: #eee; padding: 1rem; border-radius: 8px; overflow-x: auto; font-size: 0.85rem; line-height: 1.4; }<br>code { font-family: ui-monospace, monospace; }<br>.meta { color: #666; font-style: italic; margin-top: 2rem; }<br>@media (prefers-color-scheme: dark) { .meta { color: #888; } }<br>'';
page = h.render [<br>"html" { lang = "en"; }<br>[ "head"<br>[ "meta" { charset = "utf-8"; } ]<br>[ "meta" { name = "viewport"; content = "width=device-width, initial-scale=1"; } ]<br>[ "title" "Quine - niccup example" ]<br>[ "style" (h.raw css) ]<br>[ "body"<br>[ "h1" "This page was generated by:" ]<br>[ "h2" "flake.nix" ]<br>[ "pre" [ "code" flakeSrc ] ]<br>[ "h2" "build.nix" ]<br>[ "pre" [ "code" buildSrc ] ]<br>[ "p.meta" "Copy both files, run 'nix build', and you'll get this exact page." ]<br>];
in pkgs.runCommand "quine" {} ''<br>mkdir -p $out<br>cp ${pkgs.writeText "index.html" page} $out/index.html<br>''