-
Notifications
You must be signed in to change notification settings - Fork 8
/
flake.nix
93 lines (76 loc) · 2.93 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
{
description = "Zig project flake";
inputs = {
zls.url = "github:zigtools/zls?ref=0.13.0";
zig2nix.url = "github:Cloudef/zig2nix";
};
outputs = { zig2nix, zls, ... }: let
flake-utils = zig2nix.inputs.flake-utils;
in (flake-utils.lib.eachDefaultSystem (system: let
zlsPkg = zls.packages.${system}.default;
# Zig flake helper
# Check the flake.nix in zig2nix project for more options:
# <https://github.com/Cloudef/zig2nix/blob/master/flake.nix>
env = zig2nix.outputs.zig-env.${system} {
zig = zig2nix.outputs.packages.${system}.zig."0.13.0".bin;
};
system-triple = env.lib.zigTripleFromString system;
in with builtins; with env.lib; with env.pkgs.lib; rec {
# nix build .#target.{zig-target}
# e.g. nix build .#target.x86_64-linux-gnu
packages.target = genAttrs allTargetTriples (target: env.packageForTarget target ({
src = cleanSource ./.;
nativeBuildInputs = with env.pkgs; [ pkg-config ];
buildInputs = with env.pkgsForTarget target; [ libgit2 ];
# Smaller binaries and avoids shipping glibc.
zigPreferMusl = true;
# This disables LD_LIBRARY_PATH mangling, binary patching etc...
# The package won't be usable inside nix.
zigDisableWrap = true;
} // optionalAttrs (!pathExists ./build.zig.zon) {
pname = "git-vain";
version = "2.0.0";
}));
# nix build .
packages.default = packages.target.${system-triple}.override {
# Prefer nix friendly settings.
zigPreferMusl = false;
zigDisableWrap = false;
};
# For bundling with nix bundle for running outside of nix
# example: https://github.com/ralismark/nix-appimage
apps.bundle.target = genAttrs allTargetTriples (target: let
pkg = packages.target.${target};
in {
type = "app";
program = "${pkg}/bin/default";
});
# default bundle
apps.bundle.default = apps.bundle.target.${system-triple};
# nix run .
apps.default = env.app [] "zig build run -- \"$@\"";
# nix run .#build
apps.build = env.app [] "zig build \"$@\"";
# nix run .#test
apps.test = env.app [] "zig build test -- \"$@\"";
# nix run .#docs
apps.docs = env.app [] "zig build docs -- \"$@\"";
# nix run .#deps
apps.deps = env.showExternalDeps;
# nix run .#zon2json
apps.zon2json = env.app [env.zon2json] "zon2json \"$@\"";
# nix run .#zon2json-lock
apps.zon2json-lock = env.app [env.zon2json-lock] "zon2json-lock \"$@\"";
# nix run .#zon2nix
apps.zon2nix = env.app [env.zon2nix] "zon2nix \"$@\"";
# nix develop
devShells.default = env.mkShell {
nativeBuildInputs = [ zlsPkg ];
buildInputs = [ env.pkgs.libgit2 ];
# https://github.com/ziglang/zig/issues/18998
shellHook = ''
unset NIX_CFLAGS_COMPILE
'';
};
}));
}