Skip to content

Create Flake.nix for Nix users#52

Open
lambdachad wants to merge 2 commits intoremoteoss:mainfrom
lambdachad:main
Open

Create Flake.nix for Nix users#52
lambdachad wants to merge 2 commits intoremoteoss:mainfrom
lambdachad:main

Conversation

@lambdachad
Copy link
Copy Markdown

This provides a flake.nix so Nix users can easily build and instally this library like so:

  • nix build github:remoteoss/dexter
  • nix profile install github:remoteoss/dexter
  • Adding github:remoteoss/dexter as input to flake.nix and installing it with by adding package as dexter.packages.x86_64-linux.default

@anddani
Copy link
Copy Markdown
Contributor

anddani commented Apr 27, 2026

I would suggest vendoring all go dependencies in dexter in order to avoid having to update the vendorHash.

I made an attempt at this previously but encountered some issues with one of the dependencies (treesitter I believe). It referenced some .c file with a relative import and the nix build failed.

@JesseHerrick
Copy link
Copy Markdown
Member

Thanks for the contribution @lambdachad! I have never used Nix before, so I definitely appreciate the advice from @anddani. I'll see if some colleagues can take a look and I'll also see about trying this.

Now that we have the tokenizer, I think we might be able to replace tree-sitter with it and remove the dependency, so that might not be a problem in the future.

Is there any way we can automate version bumps in Nix? If not, we should also add logic to the release make task to do this.

Copy link
Copy Markdown
Contributor

@anddani anddani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a flake, the exact version is not semantically important since you always reference flake inputs by their revision (when a git repo is referenced).

Comment thread flake.nix
{
packages.default = pkgs.buildGoModule {
pname = "dexter";
version = "0.6.0";
Copy link
Copy Markdown
Contributor

@anddani anddani Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
version = "0.6.0";
version = self.shortRev or self.dirtyRev or "dev";

@anddani
Copy link
Copy Markdown
Contributor

anddani commented Apr 28, 2026

Regarding vendoring.

When I set vendorHash = null; and commit the vendored dependencies, I get the following error when running nix build:

error: Cannot build '/nix/store/2083h6pjkqplgh3y5sqdgm2lnnpfrbp5-dexter-68598bb.drv'.
       Reason: builder failed with exit code 1.
       Output paths:
         /nix/store/xbh71mz62ga9anw3pqz0zkg72cs72gwg-dexter-68598bb
       Last 20 log lines:
       > Running phase: unpackPhase
       > unpacking source archive /nix/store/hx63hkdly29snaq0wqschihv1bcn924x-nq20hc2yp9zzha93drpzwi83hmympmpg-source
       > source root is nq20hc2yp9zzha93drpzwi83hmympmpg-source
       > Running phase: patchPhase
       > Running phase: updateAutotoolsGnuConfigScriptsPhase
       > Running phase: configurePhase
       > Running phase: buildPhase
       > Building subPackage .
       > github.com/remoteoss/dexter: no non-test Go files in /nix/var/nix/builds/nix-build-dexter-68598bb.drv-87833-2022350038/nq20hc2yp9zzha93drpzwi83hmympmpg-source
       > Building subPackage ./cmd
       > # github.com/tree-sitter/tree-sitter-elixir/bindings/go
       > vendor/github.com/tree-sitter/tree-sitter-elixir/bindings/go/binding.go:4:11: fatal error: '../../src/parser.c' file not found
       >     4 |  #include "../../src/parser.c"
       >       |           ^~~~~~~~~~~~~~~~~~~~
       > 1 error generated.
       > # github.com/tree-sitter/go-tree-sitter
       > vendor/github.com/tree-sitter/go-tree-sitter/tree_cursor.go:5:10: fatal error: 'tree_sitter/api.h' file not found
       >     5 | #include <tree_sitter/api.h>
       >       |          ^~~~~~~~~~~~~~~~~~~
       > 1 error generated.
       For full logs, run:
         nix log /nix/store/2083h6pjkqplgh3y5sqdgm2lnnpfrbp5-dexter-68598bb.drv

I am not familiar with Go so I am not sure what the best course of action would be. I'll see if I can find some examples from other projects. But I think that if you are about to remove the treesitter Go dependency, this won't be a problem anymore.

@lambdachad
Copy link
Copy Markdown
Author

Yeah this error is why I had to include the modules like I did in the initial example. The tree sitter requires dependencies that aren't included by default.

@lambdachad
Copy link
Copy Markdown
Author

If tree sitter is removed then the flake.nix becomes really simple and easy to maintain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants