From 338d4cb34e7530581e88fb98e5c61148654ac3f8 Mon Sep 17 00:00:00 2001 From: didier amyot Date: Wed, 3 Jun 2026 19:33:52 -0400 Subject: [PATCH] Add /version endpoint with build metadata - /version returns JSON with build_date and git_commit from env vars - NixOS module injects GIT_COMMIT (first 8 chars of self.rev) and BUILD_DATE (self.lastModified) into systemd service environment --- flake.nix | 4 ++++ main.go | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/flake.nix b/flake.nix index 6a03814..99d37cf 100644 --- a/flake.nix +++ b/flake.nix @@ -28,6 +28,8 @@ let cfg = config.services.st-pierre; st-pierre-pkg = self.packages.${pkgs.stdenv.hostPlatform.system}.default; + gitHash = if (self ? rev) then builtins.substring 0 8 self.rev else "dirty"; + lastUpdated = if (self ? lastModified) then builtins.toString self.lastModified else "0"; in { options.services.st-pierre = { @@ -141,6 +143,8 @@ EMBEDDING_BASE_URL = cfg.embeddingBaseUrl; EMBEDDING_MODEL = cfg.embeddingModel; SQLITE_PATH = builtins.toString cfg.sqlitePath; + GIT_COMMIT = gitHash; + BUILD_DATE = lastUpdated; } // lib.optionalAttrs (cfg.openaiApiKey != null) { OPENAI_API_KEY = cfg.openaiApiKey; diff --git a/main.go b/main.go index 6431291..a979444 100644 --- a/main.go +++ b/main.go @@ -83,6 +83,13 @@ func main() { w.WriteHeader(http.StatusOK) w.Write([]byte("ok")) }) + mux.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + json.NewEncoder(w).Encode(map[string]string{ + "build_date": os.Getenv("BUILD_DATE"), + "git_commit": os.Getenv("GIT_COMMIT"), + }) + }) mux.Handle("/mcp", authMiddleware(token, streamableServer)) httpServer := &http.Server{