Zig CLI usually fails with 'error: AccessDenied'

I’m trying to write a new Zig project (and first-time learning the language) on my NixOS machine. I setup a trivial package derivation and devshell and wanted to try and run the boilerplate code zig init creates, only to be hit with this peculiar error message.

$ zig build test
error: AccessDenied

My first attempt to get it working was to dangerously use sudo to forcibly escalate it, and turns out that works (though I suppose it should’ve been obvious). Looked around but couldn’t find much of any info about this error in other NixOS spaces.

Any ziguanas have any idea what’s going on here? It’s become the main hurdle in order to actually start on development.

I will attach my boilerplate code to a GitHub repository so you may freely clone and test as well. All I did to obtain this error was zig build test.

Little update! I found out that ZIG_GLOBAL_CACHE_DIR was being set to /build/tmp.EaZHxMNihj (a mktemp folder it seems), which was disallowing it to create said folder given that its on the rootfs. Temporarily overwriting it via ZIG_GLOBAL_CACHE_DIR=$PWD/zig-cache zig build test fixes it and allows the command to work as normal. The real question now becomes why this is the case, perhaps something to do with zig.hook?

Well, solved! It turns out zig.hook sets the global cache dir to a completely inaccessible location for a standard cli build (though it works fine in nix build ofc). I’ll raise this issue to nixpkgs directly and go from there. Hopefully this helps any other new zig users trying to get things working on NixOS.

Issue already exists here: zig.hook causes AccessDenied in development shells · Issue #270415 · NixOS/nixpkgs · GitHub

1 Like