Files
quartz-org-roam/flake.nix
2026-02-20 17:54:12 +01:00

94 lines
3.1 KiB
Nix

{
description = "Quartz org-roam dev shell and build app";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
pipeline.url = "path:./pipeline";
};
outputs = { self, nixpkgs, flake-utils, pipeline }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
fs = pkgs.lib.fileset;
pipelineApp = pipeline.packages.${system}.default;
# 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
'';
};
# The build application wrapper script
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"
# Run the pre-compiled pipeline escript (org md, citations transform)
${pipelineApp}/bin/pipeline "$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"
'';
};
in
{
devShells.default = pkgs.mkShell {
buildInputs = [
pkgs.nodejs_22
pkgs.elixir
pkgs.mcp-nixos
];
shellHook = ''
echo "Node $(node --version) / npm $(npm --version)"
elixir --version 2>/dev/null | head -1 || true
'';
};
packages.default = buildApp;
packages.build = buildApp;
packages.pipeline = pipelineApp;
apps.default = { type = "app"; program = "${buildApp}/bin/build"; };
apps.build = { type = "app"; program = "${buildApp}/bin/build"; };
});
}