Skip to content

Development with nix

Meghan edited this page Jan 15, 2022 · 25 revisions

Traditional approach

Here is a sample shell.nix for building/developing zig.

with import <nixpkgs> {};

pkgs.mkShell {
  nativeBuildInputs = with pkgs; [
    cmake
    gdb
    ninja
    qemu
  ] ++ (with llvmPackages_13; [
    clang
    clang-unwrapped
    lld
    llvm
  ]);

  hardeningDisable = [ "all" ];
}

The hardeningDisable part is crucial, otherwise you will get compile errors.

Flake

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:
    let
      system = "x86_64-linux";
      pkgs = inputs.nixpkgs.legacyPackages.${system};
    in
      {
         devShell.${system} = pkgs.mkShell {
           nativeBuildInputs = with pkgs; [
             cmake
             gdb
             ninja
             qemu
           ] ++ (with llvmPackages_13; [
             clang
             clang-unwrapped
             lld
             llvm
           ]);

           hardeningDisable = [ "all" ];
         };
      };
}