2 description = "Zig project flake";
5 zig2nix.url = "github:Cloudef/zig2nix";
8 outputs = { zig2nix, ... }: let
9 flake-utils = zig2nix.inputs.flake-utils;
10 in (flake-utils.lib.eachDefaultSystem (system: let
12 # Check the flake.nix in zig2nix project for more options:
13 # <https://github.com/Cloudef/zig2nix/blob/master/flake.nix>
14 env = zig2nix.outputs.zig-env.${system} {};
15 in with builtins; with env.pkgs.lib; rec {
16 # Produces clean binaries meant to be ship'd outside of nix
18 packages.foreign = env.package {
19 src = cleanSource ./.;
21 # Packages required for compiling
22 nativeBuildInputs = with env.pkgs; [];
24 # Packages required for linking
25 buildInputs = with env.pkgs; [];
27 # Smaller binaries and avoids shipping glibc.
32 packages.default = packages.foreign.override (attrs: {
33 # Prefer nix friendly settings.
34 zigPreferMusl = false;
36 # Executables required for runtime
37 # These packages will be added to the PATH
38 zigWrapperBins = with env.pkgs; [];
40 # Libraries required for runtime
41 # These packages will be added to the LD_LIBRARY_PATH
42 zigWrapperLibs = attrs.buildInputs or [];
45 # For bundling with nix bundle for running outside of nix
46 # example: https://github.com/ralismark/nix-appimage
49 program = "${packages.foreign}/bin/default";
53 apps.default = env.app [] "zig build run -- \"$@\"";
56 apps.build = env.app [] "zig build \"$@\"";
59 apps.test = env.app [] "zig build test -- \"$@\"";
62 apps.docs = env.app [] "zig build docs -- \"$@\"";
65 apps.zig2nix = env.app [] "zig2nix \"$@\"";
68 devShells.default = env.mkShell {
69 # Packages required for compiling, linking and running
70 # Libraries added here will be automatically added to the LD_LIBRARY_PATH and PKG_CONFIG_PATH
71 nativeBuildInputs = []
72 ++ packages.default.nativeBuildInputs
73 ++ packages.default.buildInputs
74 ++ packages.default.zigWrapperBins
75 ++ packages.default.zigWrapperLibs;