-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Development with nix
devins2518 edited this page Jun 5, 2022
·
26 revisions
Here is a sample shell.nix
for building/developing zig.
with import <nixpkgs> {};
pkgs.mkShell {
nativeBuildInputs = with pkgs; [
cmake
gdb
ninja
qemu
wasmtime
] ++ (with llvmPackages_13; [
clang
clang-unwrapped
lld
llvm
]);
hardeningDisable = [ "all" ];
}
The hardeningDisable
part is crucial, otherwise you will get compile errors.
Alternatively, you can use this sample flake.nix
:
{
description = "A flake for Zig development";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
};
outputs = inputs: inputs.flake-utils.lib.eachDefaultSystem (system:
let
pkgs = inputs.nixpkgs.legacyPackages.${system};
in
{
devShell.${system} = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
cmake
gdb
ninja
qemu
wasmtime
] ++ (with llvmPackages_13; [
clang
clang-unwrapped
lld
llvm
]);
hardeningDisable = [ "all" ];
};
}
);
}
If using macOS, you may need to include the following to properly use nix's clang.
shellHook = with pkgs.llvmPackages_13; ''
export CPATH="${clang}" # Use clang's stdlib
export LDFLAGS="-stdlib=libc++ -lc++abi" # Link against the stdlib
'';