This page was generated by:

flake.nix

{
  description = "Self-rendering quine example using niccup";

  inputs = {
    niccup.url = "github:embedding-shapes/niccup";
    nixpkgs.follows = "niccup/nixpkgs";
  };

  outputs = { nixpkgs, niccup, ... }:
    let
      systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
    in {
      packages = nixpkgs.lib.genAttrs systems (system: {
        default = import ./build.nix {
          pkgs = import nixpkgs { inherit system; };
          h = niccup.lib;
        };
      });
    };
}

build.nix

{ pkgs, h }:

let
  flakeSrc = builtins.readFile ./flake.nix;
  buildSrc = builtins.readFile ./build.nix;

  css = ''
    body { max-width: 800px; margin: 2rem auto; padding: 0 1rem; font-family: system-ui; background: #fafafa; color: #333; }
    @media (prefers-color-scheme: dark) { body { background: #1a1a2e; color: #eee; } }
    h1 { border-bottom: 2px solid #0066cc; padding-bottom: 0.5rem; }
    h2 { color: #666; margin-top: 1.5rem; font-size: 1rem; font-family: ui-monospace, monospace; }
    @media (prefers-color-scheme: dark) { h2 { color: #999; } }
    pre { background: #1a1a2e; color: #eee; padding: 1rem; border-radius: 8px; overflow-x: auto; font-size: 0.85rem; line-height: 1.4; }
    code { font-family: ui-monospace, monospace; }
    .meta { color: #666; font-style: italic; margin-top: 2rem; }
    @media (prefers-color-scheme: dark) { .meta { color: #888; } }
  '';

  page = h.render [
    "html" { lang = "en"; }
    [ "head"
      [ "meta" { charset = "utf-8"; } ]
      [ "meta" { name = "viewport"; content = "width=device-width, initial-scale=1"; } ]
      [ "title" "Quine - niccup example" ]
      [ "style" (h.raw css) ]
    ]
    [ "body"
      [ "h1" "This page was generated by:" ]
      [ "h2" "flake.nix" ]
      [ "pre" [ "code" flakeSrc ] ]
      [ "h2" "build.nix" ]
      [ "pre" [ "code" buildSrc ] ]
      [ "p.meta" "Copy both files, run 'nix build', and you'll get this exact page." ]
    ]
  ];

in pkgs.runCommand "quine" {} ''
  mkdir -p $out
  cp ${pkgs.writeText "index.html" page} $out/index.html
''

Copy both files, run 'nix build', and you'll get this exact page.