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

View File

@@ -12,14 +12,18 @@
pkgs = import nixpkgs { inherit system; };
fs = pkgs.lib.fileset;
# Emacs with ox-hugo — needed at runtime by the escript
# (export_org_files calls `emacs --batch` with ox-hugo).
# =========================================================================
# Emacs with ox-hugo
# =========================================================================
# Needed at runtime by the escript (export calls `emacs --batch` with ox-hugo)
emacsWithOxHugo = (pkgs.emacsPackagesFor pkgs.emacs-nox).emacsWithPackages
(epkgs: [ epkgs.ox-hugo ]);
# Pre-fetched Hex/Mix dependencies.
# src is filtered to mix.exs + mix.lock so source edits don't
# invalidate this derivation.
# =========================================================================
# Elixir Pipeline
# =========================================================================
# Pre-fetched Hex/Mix dependencies
mixDeps = pkgs.beamPackages.fetchMixDeps {
pname = "org-garden-mix-deps";
version = "0.1.0";
@@ -33,32 +37,103 @@
sha256 = "sha256-si7JAomY1HZ33m6ihUJP5i6PO39CE1clYvuMtn0CbPU=";
};
# Compiled org-garden escript (without runtime wrappers).
# Note: escript name is org_garden (from app: :org_garden in mix.exs)
# Compiled org-garden escript
orgGardenEscript = pkgs.beamPackages.mixRelease {
pname = "org-garden";
version = "0.1.0";
src = ./.;
src = fs.toSource {
root = ./.;
fileset = fs.unions [
./mix.exs
./mix.lock
./lib
];
};
escriptBinName = "org_garden";
mixFodDeps = mixDeps;
stripDebug = true;
};
# Wrapped org-garden that puts emacs (with ox-hugo) on PATH so
# the escript's System.cmd("emacs", ...) calls succeed.
# =========================================================================
# Quartz (fetched from upstream, patched)
# =========================================================================
# Pin to specific upstream commit
quartzVersion = "4.5.2";
quartzRev = "ec00a40aefca73596ab76e3ebe3a8e1129b43688";
# Fetch upstream Quartz source
quartzSrc = pkgs.fetchFromGitHub {
owner = "jackyzha0";
repo = "quartz";
rev = quartzRev;
hash = "sha256-HdtQB5+SRWiypOvAJuJa3Nodl4JHehp2Mz6Rj5gOG0w=";
};
# Apply our patches to Quartz
quartzPatched = pkgs.runCommand "quartz-patched-${quartzVersion}" {
src = quartzSrc;
} ''
cp -r $src $out
chmod -R u+w $out
cd $out
patch -p1 < ${./patches/01-glob-gitignore.patch}
patch -p1 < ${./patches/02-build-gitignore.patch}
patch -p1 < ${./patches/03-static-hugo.patch}
patch -p1 < ${./patches/04-oxhugofm-figure.patch}
'';
# Pre-fetch Quartz npm dependencies
quartzDeps = pkgs.buildNpmPackage {
pname = "org-garden-quartz-deps";
version = quartzVersion;
src = quartzPatched;
npmDepsHash = "sha256-7u+VlIx44B3/ivM9vLMIOn+e4TL4eS6B682vhS+Ikb4=";
dontBuild = true;
installPhase = ''
mkdir -p $out
cp -r node_modules $out/node_modules
'';
};
# =========================================================================
# Combined Application
# =========================================================================
# Wrapped org-garden with Quartz bundled
orgGardenApp = pkgs.writeShellApplication {
name = "org-garden";
runtimeInputs = [ emacsWithOxHugo pkgs.inotify-tools pkgs.nodejs_22 ];
text = ''
# Set up Quartz working directory
QUARTZ_WORK=$(mktemp -d)
trap 'rm -rf "$QUARTZ_WORK"' EXIT
# Copy patched Quartz source
cp -r ${quartzPatched}/. "$QUARTZ_WORK/"
chmod -R u+w "$QUARTZ_WORK"
# Copy default config files
cp ${./quartz-config/quartz.config.ts} "$QUARTZ_WORK/"
cp ${./quartz-config/quartz.layout.ts} "$QUARTZ_WORK/"
cp ${./quartz-config/globals.d.ts} "$QUARTZ_WORK/"
cp ${./quartz-config/index.d.ts} "$QUARTZ_WORK/"
# Link pre-built node_modules
ln -s ${quartzDeps}/node_modules "$QUARTZ_WORK/node_modules"
export QUARTZ_PATH="$QUARTZ_WORK"
export NODE_PATH="${pkgs.nodejs_22}/bin/node"
exec ${orgGardenEscript}/bin/org_garden "$@"
'';
};
in
{
packages.default = orgGardenApp;
packages.escript = orgGardenEscript;
packages.quartz-patched = quartzPatched;
devShells.default = pkgs.mkShell {
buildInputs = [