feat: unified org-garden

This commit is contained in:
Ignacio Ballesteros
2026-02-21 13:10:30 +01:00
parent a4582230b5
commit 678fb315d3
10 changed files with 415 additions and 102 deletions

107
flake.nix
View File

@@ -1,5 +1,5 @@
{
description = "Quartz org-roam dev shell and build app";
description = "Quartz org-roam org notes to website";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
@@ -11,95 +11,31 @@
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
fs = pkgs.lib.fileset;
orgGardenApp = org-garden.packages.${system}.default;
# Re-export org-garden's packages
orgGardenPkgs = org-garden.packages.${system};
# Pre-fetched npm dependency tree (node_modules).
# src is filtered to only package.json + package-lock.json so that
# edits to Quartz source files do not invalidate this derivation.
quartzDeps = pkgs.buildNpmPackage {
pname = "quartz-deps";
version = "4.5.2";
src = fs.toSource {
root = ./.;
fileset = fs.unions [
./package.json
./package-lock.json
];
};
npmDepsHash = "sha256-7u+VlIx44B3/ivM9vLMIOn+e4TL4eS6B682vhS+Ikb4=";
dontBuild = true;
installPhase = ''
mkdir -p $out
cp -r node_modules $out/node_modules
'';
};
# Convenience aliases
orgGardenApp = orgGardenPkgs.default;
# The build application wrapper script (one-shot build)
buildApp = pkgs.writeShellApplication {
name = "build";
runtimeInputs = [ pkgs.nodejs_22 ];
text = ''
NOTES_DIR="''${1:?Usage: build <path-to-notes-dir>}"
NOTES_DIR=$(realpath "$NOTES_DIR")
ORIG_CWD=$(pwd)
# Set up a writable working copy of the repo in a temp dir
WORK=$(mktemp -d)
trap 'rm -rf "$WORK"' EXIT
cp -r ${self}/. "$WORK/repo"
chmod -R u+w "$WORK/repo"
# Drop in pre-built node_modules
ln -s ${quartzDeps}/node_modules "$WORK/repo/node_modules"
# 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"
# 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
{
# All packages come from org-garden
packages = orgGardenPkgs // {
default = orgGardenApp;
};
# Apps
apps = {
default = { type = "app"; program = "${orgGardenApp}/bin/org-garden"; };
org-garden = { type = "app"; program = "${orgGardenApp}/bin/org-garden"; };
};
# Dev shell for working on the repo
devShells.default = pkgs.mkShell {
buildInputs = [
pkgs.nodejs_22
pkgs.elixir
pkgs.mcp-nixos
];
shellHook = ''
@@ -107,14 +43,5 @@
elixir --version 2>/dev/null | head -1 || true
'';
};
packages.default = buildApp;
packages.build = buildApp;
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"; };
});
}