about summary refs log tree commit diff
path: root/scripts
diff options
context:
space:
mode:
authorPjotr <wrk@bosa.lan>2026-11-16 10:07:04 +0000
committerPjotr <wrk@bosa.lan>2026-11-16 10:07:04 +0000
commit744278e9881db1b9cd544fb8061bb616b9020886 (patch)
tree173105b0c5f70b29b707230a21c6911ff79ccaaf /scripts
parentc7bcd32190f0355ad3d6ba5a87ca7eec3fcf2604 (diff)
downloadai-memory-744278e9881db1b9cd544fb8061bb616b9020886.tar.gz
install.sh: build, root and link, so no store path is ever written down
guix build -f guix.scm prints a path that changes with every rebuild of the
tree, so the practical way to use it has been to copy a store hash into a
script -- and a copied hash outlives the source.  That is not hypothetical:
a store on this box was created by a binary that predated the gist column,
and the mismatch surfaced as an empty 'sql error (Error):' at write time.

scripts/install.sh builds from this checkout, GC-roots the result
(AI_MEMORY_ROOT, default ~/.local/state/ai-memory/root) so a guix gc cannot
take it away, links AI_MEMORY_LINK (default ~/.local/bin/ai-memory) so nobody
has to remember a hash, and then runs the binary once to prove it starts.
Two builds in a row give the same store path, which is what makes the root
stable between runs and not merely between rebuilds of the same day.

README and doc/SKILL.md now lead with it, and keep the bare guix build as the
unpinned alternative.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/install.sh62
1 files changed, 62 insertions, 0 deletions
diff --git a/scripts/install.sh b/scripts/install.sh
new file mode 100755
index 0000000..0bc8a8f
--- /dev/null
+++ b/scripts/install.sh
@@ -0,0 +1,62 @@
+#!/bin/sh
+# Build ai-memory from this checkout and put it on PATH, pinned.
+#
+# The reason this exists: `guix build -f guix.scm' prints a store path that
+# changes with every rebuild, so scripts end up hard-coding one and keep running
+# a binary that predates the source -- which is how a store was created with a
+# schema too old for the code that later wrote to it.
+#
+#   scripts/install.sh                 # build, GC-root it, link ~/.local/bin
+#   AI_MEMORY_ROOT=/opt/am scripts/install.sh
+#   scripts/install.sh --no-link       # do not touch ~/.local/bin
+#
+# The GC root is what keeps a `guix gc' from taking the binary away; the link is
+# what keeps people from having to remember a store hash.
+set -eu
+
+ROOT=${AI_MEMORY_ROOT:-${XDG_STATE_HOME:-$HOME/.local/state}/ai-memory/root}
+LINK=${AI_MEMORY_LINK:-${XDG_BIN_HOME:-$HOME/.local/bin}/ai-memory}
+here=$(cd "$(dirname "$0")/.." && pwd)
+
+link=yes
+for arg in "$@"; do
+	case $arg in
+	--no-link) link=no ;;
+	-h|--help) sed -n '2,15p' "$0" | sed 's/^# \{0,1\}//'; exit 0 ;;
+	*) echo "install.sh: unknown argument $arg" >&2; exit 2 ;;
+	esac
+done
+
+command -v guix >/dev/null 2>&1 || {
+	echo "install.sh: guix is not on PATH" >&2
+	exit 1
+}
+
+mkdir -p "$(dirname "$ROOT")"
+# Build from this checkout (guix.scm's source is a local-file, so the store path
+# is a function of the tree) and root it in one step.
+store=$(cd "$here" && guix build -f guix.scm --root="$ROOT")
+
+if [ ! -x "$ROOT/bin/ai-memory" ]; then
+	echo "install.sh: $ROOT/bin/ai-memory is missing after the build" >&2
+	exit 1
+fi
+
+echo "ai-memory: $store"
+echo "ai-memory: root $ROOT -> $(readlink -f "$ROOT")"
+
+if [ "$link" = yes ]; then
+	mkdir -p "$(dirname "$LINK")"
+	ln -sf "$ROOT/bin/ai-memory" "$LINK"
+	echo "ai-memory: $LINK -> $ROOT/bin/ai-memory"
+	case :$PATH: in
+	*:"$(dirname "$LINK")":*) ;;
+	*) echo "ai-memory: note: $(dirname "$LINK") is not on PATH" ;;
+	esac
+fi
+
+"$ROOT/bin/ai-memory" --help >/dev/null 2>&1 || {
+	echo "install.sh: $ROOT/bin/ai-memory does not run" >&2
+	exit 1
+}
+echo "ai-memory: ok"