Trying to Build my First Package on Guix

Hello.

I just downloaded Guix this weekend and have my system pretty well setup. However, I am a heretic and use neovim, but Treesitter is acting very funky on my system. In the guix repos the latest version is 0.25.3, and my nvim :checkhealth suggests having 0.26.9, so I figured hey lets package my first system.

Here is what I am trying. I am kinda guessing off of minimal documentation but I continuously get build errors.

(use-modules (guix)
             (guix packages)
             (guix download)
             (guix build-system trivial)
             (guix licenses)
             (guix utils)
             (srfi srfi-1)
             (gnu packages compression) ; provides `gzip`
             (gnu packages bash))  

(define-public tree-sitter-cli
  (package
    (name "tree-sitter-cli")
    (version "0.26.9")
    (source (origin
             (method url-fetch)
             (uri (string-append
                   "https://github.com/tree-sitter/tree-sitter/releases/download/v"
                   version
                   "/tree-sitter-linux-x64.gz"))
             (sha256
              (base32 "1ysyb312dpf4p5ql6750sadqry6fj79rz1lbrbkn8n56r8vj3s4w"))))
    (build-system trivial-build-system)
    (native-inputs `(("gzip" ,gzip)
                     ("bash" ,bash-minimal)))
    (arguments
     `(#:builder
       ,#~(lambda ()
           (let ((src (assoc-ref %build-inputs "source"))
                 (out (assoc-ref %outputs "out")))
             (invoke "mkdir" "-p" (string-append out "/bin"))
             (invoke "cp" src (string-append out "/tree-sitter.gz"))
             (invoke "bash" "-c" (string-append "gunzip -c " (string-append out "/tree-sitter.gz")
                                               " > " out "/bin/tree-sitter"))
             (invoke "chmod" "0755" (string-append out "/bin/tree-sitter"))
             0))))
    (home-page "https://github.com/tree-sitter/tree-sitter")
    (synopsis "tree-sitter-cli (prebuilt v0.26.9)")
    (description "Prebuilt tree-sitter CLI (linux x86_64) from upstream releases.")
    (license expat)))

tree-sitter-cli

I’m not quite sure I know what I am doing, so any helpful learnings is much appreciated! I am very new to Guile and Lisps in general, but am excited to learn!

The errors are pretty unhelpful and the logs in /var/log are empty:

building /gnu/store/l1ja76imb5mv17zz2wianifa0wz22sp4-tree-sitter-cli-0.26.9.drv...
builder for `/gnu/store/l1ja76imb5mv17zz2wianifa0wz22sp4-tree-sitter-cli-0.26.9.drv' failed to produce output path `/gnu/store/gc67ypxi72vldm90zsipkx33139akc2g-tree-sitter-cli-0.26.9'
build of /gnu/store/l1ja76imb5mv17zz2wianifa0wz22sp4-tree-sitter-cli-0.26.9.drv failed
View build log at '/var/log/guix/drvs/l1/ja76imb5mv17zz2wianifa0wz22sp4-tree-sitter-cli-0.26.9.drv.gz'.
cannot build derivation `/gnu/store/0cr164z2vfkyw2xc01cjh1p93dpqj958-profile.drv': 1 dependencies couldn't be built

Welcome! I’m a fellow neovim heretic and used this guide to setup my installation.

I’ve only made one other basic package definition myself, so I’m no means an expert.

Another neovim heretic here.

I use rocks.nvim to install my vim plugins.
Though I haven’t actually used any of them yet on this system, it worked like a charm on my previous OS.

As an additional note for debugging a package build script. I found the -K option to be helpful to see the results of the commands that did finish. The Guix documentation is all over the place, but this is in the guix build command documentation https://guix.gnu.org/manual/1.5.0/en/html_node/Common-Build-Options.html

I also noticed that you seem to be trying to package the binary build of tree-sitter? That may or may not work, but I think it’s expected for a Guix package to compile a package from source. (I’d be a little bit worried about the binary linking to an incorrect shared library, but I haven’t tested to confirm this at all.)

From Getting Started - Tree-sitter, it seems like tree-sitter has a pretty standard build setup.
I would probably start with the gnu-build-system then remove the configure step with
(delete 'configure).

;; ...
(build-system gnu-build-system)
(arguments
  (list
    #:phases
    #~(modify-phases
        %standard-phases
        (delete 'configure))))
;; ...

(I deleted some stuff from the code, so I’m not sure if all the braces line up)

Thanks for this tip! I should be able to get back to hacking on it tomorrow. I have a few ideas that I’m looking to try.

In general, I want to be able to make my own packages as coming from previous experience (with NixOS) there’s often some friction when trying to install library dependencies for various programming languages. I like to program in various things like Haskell and OCaml, but getting some of the dependencies set up is often a challenge. I figure if I can understand how some packages work with Guile, I’ll just start packing things that I can’t get with the native language package system.

I’ve just used lazy.nvim with a traditional .config setup. I’d be interested in setting something up declaratively but it worked out of the box besides tree-sitter

Assuming nothing has changed about the build process, you could just lean on most of the package definition that is already in guix by inheriting it, and then just changing version and hash, something like this:

(define-public tree-sitter-cli-next
  (package
   (inherit tree-sitter-cli)
   (name "tree-sitter-cli-next")
   (version "0.26.9")
   (source (origin
            (method git-fetch
            (uri (git-reference
                  (url "https://github.com/tree-sitter/tree-sitter")
                  (commit (string-append "v" version))))
            (file-name (git-file-name name version))
            (sha256
             (base32
              "$hash"))))))

Something like that might work.