How to build the Zig language server using zig-overlay nix flake?

Hi ! I would like to build zls with the zig version of zig-overlay in my nix shell. i tried to override the nativeBuildInputs of the zls flake like this

zig = zig_overlay.packages.${system}.master-2024-01-07;
zlsOverride = inputs.zls // { nativeBuildInputs = [ zig ]; };
zls = zlsOverride.packages.${system}.zls;

it compiles but zls always builds with the latest version and not the one I specified.
is there any way i can do what i want to do? i’m pretty new to nix…

I haven’t tried it but this should work:

zls = pkgs.zls.overrideAttrs(prev: {
  nativeBuildInputs = [ zig ];

Otherwise you can just replace Nixpkgs’ Zig with your own in an overlay:

pkgs = import nixpkgs {
  inherit system;
  overlays = [
    (final: prev: {
      inherit zig; # from zig = zig_overlay.packages.${system}.master-2024-01-07

This will build every package you get from Nixpkgs with that specific version of Zig.

1 Like