feat: unified watch server under org-garden

This commit is contained in:
Ignacio Ballesteros
2026-02-21 00:36:31 +01:00
parent 1076bf31ed
commit a4582230b5
21 changed files with 679 additions and 296 deletions

View File

@@ -4,16 +4,16 @@
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
pipeline.url = "path:./pipeline";
org-garden.url = "path:./org-garden";
};
outputs = { self, nixpkgs, flake-utils, pipeline }:
outputs = { self, nixpkgs, flake-utils, org-garden }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
fs = pkgs.lib.fileset;
pipelineApp = pipeline.packages.${system}.default;
orgGardenApp = org-garden.packages.${system}.default;
# Pre-fetched npm dependency tree (node_modules).
# src is filtered to only package.json + package-lock.json so that
@@ -36,7 +36,7 @@
'';
};
# The build application wrapper script
# The build application wrapper script (one-shot build)
buildApp = pkgs.writeShellApplication {
name = "build";
runtimeInputs = [ pkgs.nodejs_22 ];
@@ -54,18 +54,43 @@
# Drop in pre-built node_modules
ln -s ${quartzDeps}/node_modules "$WORK/repo/node_modules"
# Run the pre-compiled pipeline escript (org md, citations transform)
${pipelineApp}/bin/pipeline "$NOTES_DIR" \
# Pass paths via environment for org-garden
export QUARTZ_PATH="$WORK/repo"
export NODE_PATH="${pkgs.nodejs_22}/bin/node"
# Run org-garden build (org md static site)
${orgGardenApp}/bin/org-garden build "$NOTES_DIR" \
--output "$WORK/repo" \
--content-dir "$WORK/repo/content"
# Build the static site from within the repo copy so relative paths
# (e.g. ./package.json in constants.js) resolve correctly.
# --output is absolute so the result lands in the caller's cwd.
cd "$WORK/repo"
node quartz/bootstrap-cli.mjs build \
--directory "$WORK/repo/content" \
--output "$ORIG_CWD/public"
# Copy public output to caller's cwd
cp -r "$WORK/repo/public" "$ORIG_CWD/public"
'';
};
# Development server with watch + live reload
notesApp = pkgs.writeShellApplication {
name = "notes";
runtimeInputs = [ pkgs.nodejs_22 orgGardenApp ];
text = ''
NOTES_DIR="''${1:?Usage: notes <notes-dir>}"
NOTES_DIR=$(realpath "$NOTES_DIR")
# Set up writable working copy
WORK=$(mktemp -d)
trap 'rm -rf "$WORK"' EXIT
cp -r ${self}/. "$WORK/repo"
chmod -R u+w "$WORK/repo"
ln -s ${quartzDeps}/node_modules "$WORK/repo/node_modules"
# Pass paths via environment
export QUARTZ_PATH="$WORK/repo"
export NODE_PATH="${pkgs.nodejs_22}/bin/node"
# org-garden reads these internally
org-garden serve "$NOTES_DIR" \
--output "$WORK/repo" \
--content-dir "$WORK/repo/content"
'';
};
in
@@ -85,9 +110,11 @@
packages.default = buildApp;
packages.build = buildApp;
packages.pipeline = pipelineApp;
packages.notes = notesApp;
packages.org-garden = orgGardenApp;
apps.default = { type = "app"; program = "${buildApp}/bin/build"; };
apps.build = { type = "app"; program = "${buildApp}/bin/build"; };
apps.notes = { type = "app"; program = "${notesApp}/bin/notes"; };
});
}