koe
January 16, 2026, 6:49pm
1
Anyone else use Nix flake-based development environments? I am curious to see how others approach this, maybe I can improve my own setup!
I use it to manage both my zig versions as well as my development environment. I essentially use Mitchell Hashimoto’s overlay and build ZLS from scratch with the specified zig version. Seems to work.
My best go as a Nix novice:
{
description = "YOUR DESCRIPTION HERE";
inputs = {
# grab nixpkgs, I use unstable!
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
# for 'foreach' system
utils.url = "github:numtide/flake-utils";
# grab zig overlay for zig
zig-flake.url = "github:mitchellh/zig-overlay";
# put our zig into zls to ensure it matches
zls-flake = {
url = "github:zigtools/zls?ref=master";
inputs.nixpkgs.follows = "nixpkgs";
inputs.zig-overlay.follows = "zig-flake";
};
};
This file has been truncated. show original
I’ve never used flakes before. I use nix-shell with these two lines:
hardeningDisable = [ "all" ];
buildInputs = [ cmake ];
1 Like
I personally use the below.
silversquirl/zig-flake is a bit faster with nightlies
(if you use zls) I personally like keeping the version of zls project specific
I don’t need another c compiler, so I keep it out of my shell
Outside of that I emulate forEachSystem to have one less dependency
{
description = "Zig dev environment";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
zig = {
url = "github:silversquirl/zig-flake/compat";
inputs.nixpkgs.follows = "nixpkgs";
};
zls = {
url = "github:zigtools/zls";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
nixpkgs,
zig,
zls,
...
}:
let
forAllSystems = f: builtins.mapAttrs f nixpkgs.legacyPackages;
in
{
devShells = forAllSystems (
system: pkgs: {
default = pkgs.mkShellNoCC {
packages = [
zig.packages.${system}.nightly
zls.packages.${system}.zls
];
};
}
);
};
}
2 Likes