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 zighttp = env.pkgs.fetchFromGitHub {
16 owner = "patrick-scho";
18 rev = "274c46eb3f7e9987cc9260bb70c43b4f5d8555ac";
19 sha256 = "sha256-SUFHiA0r46QfzhlO6Ie1CByzC/+qPR2kyAbeDEdKOJ0=";
21 ziglmdb = env.pkgs.fetchFromGitHub {
22 owner = "patrick-scho";
24 rev = "88cb74a430fa9629c8127c3a866c40e79a8e4612";
25 sha256 = "sha256-SUFHiA0r46QfzhlO6Ie1CByzC/+qPR2kyAbeDEdKOJ0=";
27 in with builtins; with env.pkgs.lib; rec {
28 # Produces clean binaries meant to be ship'd outside of nix
30 packages.foreign = env.package {
31 src = cleanSource ./.;
33 # Packages required for compiling
34 nativeBuildInputs = with env.pkgs; [];
36 # Packages required for linking
37 buildInputs = with env.pkgs; [];
39 # Smaller binaries and avoids shipping glibc.
44 packages.default = packages.foreign.override (attrs: {
45 # Prefer nix friendly settings.
46 zigPreferMusl = false;
48 # Executables required for runtime
49 # These packages will be added to the PATH
50 zigWrapperBins = with env.pkgs; [];
52 # Libraries required for runtime
53 # These packages will be added to the LD_LIBRARY_PATH
54 zigWrapperLibs = attrs.buildInputs or [];
57 # For bundling with nix bundle for running outside of nix
58 # example: https://github.com/ralismark/nix-appimage
61 program = "${packages.foreign}/bin/default";
65 apps.default = env.app [] "zig build run -- \"$@\"";
68 apps.build = env.app [] ''
70 ln -s ${zighttp} ext/zighttp
71 ln -s ${ziglmdb} ext/ziglmdb
76 apps.test = env.app [] "zig build test -- \"$@\"";
79 apps.docs = env.app [] "zig build docs -- \"$@\"";
82 apps.zig2nix = env.app [] "zig2nix \"$@\"";
85 devShells.default = env.mkShell {
86 # Packages required for compiling, linking and running
87 # Libraries added here will be automatically added to the LD_LIBRARY_PATH and PKG_CONFIG_PATH
88 nativeBuildInputs = []
89 ++ packages.default.nativeBuildInputs
90 ++ packages.default.buildInputs
91 ++ packages.default.zigWrapperBins
92 ++ packages.default.zigWrapperLibs;