about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPjotr Prins <pjotr.public01@thebird.nl>2026-11-27 11:55:11 +0000
committerPjotr Prins <pjotr.public01@thebird.nl>2026-11-27 11:55:11 +0000
commit8f7afb1930def16d2fc2fb0493070c8296f840cd (patch)
tree3ace2b85590acc1f1b345ccf08a88aaf1370b570
parentcd9f46633bcc55ab2a72cda1a0f1a667e79c2e57 (diff)
downloadgenenetwork4-8f7afb1930def16d2fc2fb0493070c8296f840cd.tar.gz
guix: vendor the extracted search engine, so a store build can link it
The branch adds gn-search-engine as a git dependency; a store build has no
network, so `cargo build --offline' stopped at "can't checkout from
https://github.com/Alexanderlacuna/gn-search".

gn-search is a workspace (crates/engine, crates/schema, crates/indexer),
which the two existing git dependencies here are not, so this is a little
more than another stanza: the checkout is fetched once, and 'vendor-gn-search
flattens the two crates GN4 links into standalone vendored directories --
writing out the `version.workspace = true' inheritance a directory source
cannot resolve -- then a second phase points the git source at them.

One lock rewrite has to be allowed, and --offline is what makes it safe:
gn-search-schema is a path dependency inside the workspace, which cargo
records under the git source, while a vendored directory can only be found
by name and version. The first resolve moves that one line to the registry
source, resolved entirely against guix-vendor; 'install still runs --locked.
-rw-r--r--guix.scm102
1 files changed, 102 insertions, 0 deletions
diff --git a/guix.scm b/guix.scm
index f14142c..c2ce685 100644
--- a/guix.scm
+++ b/guix.scm
@@ -21,6 +21,8 @@
   (guix gexp)
   (guix packages)
   (guix download)          ; url-fetch, for the pinned xapian-1.4 source
+  (guix git-download)      ; git-fetch, for the gn-search checkout
+  (guix build utils)       ; substitute*, copy-recursively in 'vendor-gn-search
   (guix build-system cargo)
   (gnu packages llvm)      ; clang-13: libclang for autocxx codegen
   (gnu packages databases) ; lmdb: embedded key/value store
@@ -50,6 +52,28 @@
 ;; native-inputs).  Guix's own `xapian` has moved on to 2.1.0, so pin the
 ;; last 1.4 release here instead of tracking it; drop this pin once
 ;; xapian-rs targets Xapian 2.
+;; The extracted search engine (github.com/Alexanderlacuna/gn-search) is a
+;; cargo *workspace* -- crates/engine, crates/schema, crates/indexer -- and
+;; Cargo.toml pins it by git revision, so a store build (which has no
+;; network) cannot fetch it.  Fetch the checkout here and let the
+;; 'vendor-gn-search phase below turn the two crates GN4 links
+;; (gn-search-engine, gn-search-schema) into vendored *directory* sources.
+;;
+;; They cannot be used as they stand: their Cargo.toml inherits
+;; `version.workspace = true`, `xapian-rs.workspace = true` and so on from
+;; the workspace root, and a vendored directory has no workspace root above
+;; it.  The phase writes the inheritance out in full, which is the same
+;; manifest cargo vendor would produce.
+(define gn-search-source
+  (origin
+    (method git-fetch)
+    (uri (git-reference (url "https://github.com/Alexanderlacuna/gn-search")
+                        (commit "b00139d50369bdc6146337e4448da772d9a4af61")))
+    ;; The input label IS the file-name, and 'vendor-gn-search looks
+    ;; the checkout up as "gn-search".
+    (file-name "gn-search")
+    (sha256 (base32 "1fi4rflljxikbsv3y4ad5mafflv85d2vfaccnrf1dhfpf2j54r27"))))
+
 (define xapian-1.4
   (package
     (inherit xapian)
@@ -178,6 +202,47 @@ replace-with = 'vendored-sources'
                               (display "{\"files\":{}}" port)))))
                       (list "^rust-xapian-rs" "^rust-correlation_rust")))))
 
+               ;; gn-search is a workspace, and a directory source has no
+               ;; workspace root: flatten the two crates GN4 links into
+               ;; standalone vendored dirs named <name>-<version>, the
+               ;; layout `cargo vendor' would have produced.  The xapian-rs
+               ;; pin inside them is the same revision this package
+               ;; vendors, so the source replacement above covers it.
+               (add-after 'unpack-rust-crates 'vendor-gn-search
+                 (lambda* (#:key inputs #:allow-other-keys)
+                   (let ((checkout (assoc-ref inputs "gn-search"))
+                         (vendor "guix-vendor"))
+                     (define (flatten crate vendored)
+                       (let ((dir (string-append vendor "/" vendored)))
+                         (copy-recursively (string-append checkout crate) dir)
+                         (substitute* (string-append dir "/Cargo.toml")
+                           (("version.workspace = true")
+                            "version = \"0.1.0\"")
+                           (("edition.workspace = true")
+                            "edition = \"2021\"")
+                           (("license.workspace = true")
+                            "license = \"AGPL-3.0-or-later\"")
+                           (("gn-search-schema.workspace = true")
+                            "gn-search-schema = \"0.1.0\"")
+                           (("serde_json.workspace = true")
+                            "serde_json = \"1.0.151\"")
+                           (("serde.workspace = true")
+                            "serde = { version = \"1.0.229\", features = [\"derive\"] }")
+                           (("utoipa = \\{ workspace = true, optional = true \\}")
+                            "utoipa = { version = \"5\", optional = true }")
+                           (("xapian-rs.workspace = true")
+                            (string-append
+                             "xapian-rs = { git = \"https://github.com/Alexanderlacuna/xapian-rs\""
+                             ", rev = \"70c5eace78dbca29c434cb103cb8b2c5d4246f0d\" }")))
+                         ;; A git checkout carries no checksum in the lock;
+                         ;; stub it like the two git deps above.
+                         (call-with-output-file
+                             (string-append dir "/.cargo-checksum.json")
+                           (lambda (port)
+                             (display "{\"files\":{}}" port)))))
+                     (flatten "/crates/engine" "gn-search-engine-0.1.0")
+                     (flatten "/crates/schema" "gn-search-schema-0.1.0"))))
+
                ;; The correlation engine is a second git dependency, so it
                ;; needs its own source-replacement stanza: cargo resolves a
                ;; git source by the exact id in Cargo.lock.
@@ -195,6 +260,39 @@ replace-with = 'vendored-sources'
 "
                              git-url rev git-url rev)
                      (close-port port))))
+               ;; The gn-search crates are vendored as directory sources by
+               ;; 'vendor-gn-search; cargo still has to be told that the git
+               ;; source in Cargo.lock resolves there instead of the network.
+               ;; Same stanza shape as the two git deps above, appended after
+               ;; them so .cargo/config exists.
+               (add-after 'vendor-correlation-crate 'vendor-gn-search-crate
+                 (lambda* (#:key #:allow-other-keys)
+                   (let* ((rev "b00139d50369bdc6146337e4448da772d9a4af61")
+                          (git-url "https://github.com/Alexanderlacuna/gn-search")
+                          (port (open-file ".cargo/config" "a"
+                                           #:encoding "utf-8")))
+                     (format port "
+[source.\"git+~a?rev=~a\"]
+git = \"~a\"
+rev = \"~a\"
+replace-with = 'vendored-sources'
+"
+                             git-url rev git-url rev)
+                     (close-port port)
+                     ;; One lock rewrite has to be allowed here, and this is
+                     ;; the only place --offline makes it safe to allow it:
+                     ;; gn-search-schema is a *path* dependency inside the
+                     ;; upstream workspace, and cargo records such a package
+                     ;; under the git source.  Vendored as a directory source
+                     ;; it can only be found by name and version, i.e. as a
+                     ;; replacement for crates.io, so the first resolve moves
+                     ;; that one line from the git source to the registry
+                     ;; source -- resolved against guix-vendor, never the
+                     ;; network.  The lock restored by 'patch-cargo-checksums
+                     ;; is read-only (it comes from the store), hence the
+                     ;; chmod; 'install still runs with --locked.
+                     (make-file-writable "Cargo.lock"))))
+
                ;; The install phase must pass --locked: `cargo install'
                ;; re-resolves the dependency graph and, for a
                ;; source-replaced GIT dependency, refuses to trust the
@@ -267,6 +365,10 @@ replace-with = 'vendored-sources'
     (native-inputs
      (list git-minimal
            python
+           ;; The extracted search engine's checkout; 'vendor-gn-search
+           ;; flattens it into the two vendored crates GN4 links.  An origin
+           ;; is a legal input: the label is its file-name, "gn-search".
+           gn-search-source
            ;; The correlation engine computes p-values through rgsl, and
            ;; gsl-sys finds GSL with pkg-config at build time.
            gsl