Files
personal-site/flake.nix
T
aner 818d253a07
Build and Deploy / deploy (push) Failing after 32s
Getting ready for CI/CD
2026-05-20 09:44:49 +03:00

193 lines
6.4 KiB
Nix

{
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='<div id="back-banner" style="position:fixed;top:0;left:0;right:0;padding:.4rem 1rem;background:rgba(0,0,0,.82);backdrop-filter:blur(4px);-webkit-backdrop-filter:blur(4px);z-index:9999;font-family:-apple-system,BlinkMacSystemFont,sans-serif;font-size:.82rem;border-bottom:1px solid rgba(255,255,255,.08);"><a href="/" style="color:#93c5fd;text-decoration:none;font-weight:500;"> aner.zakobar.com</a></div>'
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|<body([^>]*)>|<body\1>$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"
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" <<EOF
#+THINGS_TITLE: $title
#+THINGS_DESC: $desc
#+THINGS_PATH: $slug
#+THINGS_FLAKE: $flake_url
EOF
echo "Created: $filename"
echo ""
echo "Add to flake.nix inputs:"
echo " ''${slug} = {"
echo " url = \"$flake_url\";"
echo " inputs.nixpkgs.follows = \"nixpkgs\";"
echo " };"
echo ""
echo "Add let binding before 'site =':"
echo " ''${camel}Pkg = inputs.''${slug}.packages.\''${system}.default;"
echo ""
echo "Add to installPhase after 'cp -r public/. \$out/':"
echo " mkdir -p \$out/''${slug}"
echo " cp -r \''${''${camel}Pkg}/. \$out/''${slug}/"
echo ""
echo "Then run: nix flake lock"
'';
};
new-post = pkgs.writeShellApplication {
name = "new-post";
runtimeInputs = [ pkgs.coreutils pkgs.gnused ];
text = ''
if [ $# -eq 0 ]; then
echo "Usage: new-post \"Post Title\""
exit 1
fi
title="$*"
slug=$(echo "$title" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g' | sed 's/-\+/-/g' | sed 's/^-//;s/-$//')
date=$(date +%Y-%m-%d)
filename="content/blog/''${date}-''${slug}.org"
mkdir -p content/blog
cat > "$filename" <<EOF
#+TITLE: $title
#+DATE: $date
*
EOF
echo "Created: $filename"
'';
};
in {
packages.default = site;
devShells.default = pkgs.mkShell {
packages = [ new-post new-thing pkgs.nodejs ];
};
apps = {
default = {
type = "app";
program = "${serve}/bin/serve";
};
tunnel = {
type = "app";
program = "${tunnel}/bin/tunnel";
};
};
}
);
}