{ description = "Personal website"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; flake-utils.url = "github:numtide/flake-utils"; word-embedding-golf = { url = "github:anerisgreat/word-embedding-golf"; inputs.nixpkgs.follows = "nixpkgs"; }; ar-globe-explorer = { url = "github:anerisgreat/ar-world-border-viewer"; inputs.nixpkgs.follows = "nixpkgs"; }; }; outputs = { self, nixpkgs, flake-utils, ... } @ inputs: flake-utils.lib.eachSystem [ "x86_64-linux" "aarch64-linux" ] (system: let pkgs = import nixpkgs { inherit system; }; wordEmbeddingGolfPkg = inputs.word-embedding-golf.packages.${system}.default; arGlobeExplorerPkg = inputs.ar-globe-explorer.packages.${system}.default; site = pkgs.stdenv.mkDerivation { name = "personal-site"; src = pkgs.lib.cleanSource ./.; nativeBuildInputs = [ pkgs.emacs-nox ]; buildPhase = '' mkdir -p public export HOME=$(mktemp -d) emacs --batch --load ./build.el ''; installPhase = '' cp -r public/. $out/ mkdir -p $out/word-embedding-golf cp -r ${wordEmbeddingGolfPkg}/. $out/word-embedding-golf/ mkdir -p $out/ar-globe-explorer cp -r ${arGlobeExplorerPkg}/. $out/ar-globe-explorer/ # Inject a "back to site" banner into all sub-project HTML pages BANNER='
' for dir in $out/word-embedding-golf $out/ar-globe-explorer; do find "$dir" -name "*.html" | while IFS= read -r f; do sed -i -E "s|]*)>|$BANNER|" "$f" done done ''; }; serve = pkgs.writeShellApplication { name = "serve"; runtimeInputs = [ pkgs.python3 pkgs.psmisc ]; text = '' fuser -k 8080/tcp 2>/dev/null || true echo "Serving site at http://localhost:8080" exec python -m http.server --bind 0.0.0.0 8080 -d ${site} ''; }; tunnel = pkgs.writeShellApplication { name = "tunnel"; runtimeInputs = [ pkgs.python3 pkgs.cloudflared pkgs.qrencode ]; text = '' echo "Starting local server and Cloudflare tunnel..." echo "" echo "Starting local server on http://localhost:8080..." python -m http.server --bind 0.0.0.0 8080 -d ${site} & SERVER_PID=$! sleep 2 echo "" echo "Starting HTTPS tunnel..." echo "Use the QR code below on your device:" echo "" cloudflared tunnel --url http://localhost:8080 2>&1 | \ while IFS= read -r line; do echo "$line" if echo "$line" | grep -q "https://.*trycloudflare.com"; then URL=$(echo "$line" | grep -o "https://[^ ]*trycloudflare.com") echo "" echo "==========================================" echo "TUNNEL URL: $URL" echo "==========================================" echo "" echo "QR Code:" echo "" qrencode -t ANSIUTF8 "$URL" echo "" fi done kill $SERVER_PID 2>/dev/null ''; }; new-thing = pkgs.writeShellApplication { name = "new-thing"; runtimeInputs = [ pkgs.coreutils pkgs.gnused ]; excludeShellChecks = [ "SC2001" ]; text = '' if [ $# -lt 3 ]; then echo "Usage: new-thing \"Title\" \"flake-url\" \"Short description\"" exit 1 fi title="$1" flake_url="$2" desc="$3" slug=$(echo "$title" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g' | sed 's/-\+/-/g' | sed 's/^-//;s/-$//') camel=$(echo "$slug" | sed 's/-\([a-z]\)/\u\1/g') filename="things/''${slug}.org" mkdir -p things cat > "$filename" <