]> gitweb.ps.run Git - iftint.zig/blob - flake.nix
codebaze
[iftint.zig] / flake.nix
1 {
2   description = "Zig project flake";
3
4   inputs = {
5     zig2nix.url = "github:Cloudef/zig2nix";
6   };
7
8   outputs = { zig2nix, ... }: let
9     flake-utils = zig2nix.inputs.flake-utils;
10   in (flake-utils.lib.eachDefaultSystem (system: let
11       # Zig flake helper
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
17       # nix build .#foreign
18       packages.foreign = env.package {
19         src = cleanSource ./.;
20
21         # Packages required for compiling
22         nativeBuildInputs = with env.pkgs; [];
23
24         # Packages required for linking
25         buildInputs = with env.pkgs; [];
26
27         # Smaller binaries and avoids shipping glibc.
28         zigPreferMusl = true;
29       };
30
31       # nix build .
32       packages.default = packages.foreign.override (attrs: {
33         # Prefer nix friendly settings.
34         zigPreferMusl = false;
35
36         # Executables required for runtime
37         # These packages will be added to the PATH
38         zigWrapperBins = with env.pkgs; [];
39
40         # Libraries required for runtime
41         # These packages will be added to the LD_LIBRARY_PATH
42         zigWrapperLibs = attrs.buildInputs or [];
43       });
44
45       # For bundling with nix bundle for running outside of nix
46       # example: https://github.com/ralismark/nix-appimage
47       apps.bundle = {
48         type = "app";
49         program = "${packages.foreign}/bin/default";
50       };
51
52       # nix run .
53       apps.default = env.app [] "zig build run -- \"$@\"";
54
55       # nix run .#build
56       apps.build = env.app [] "zig build \"$@\"";
57
58       # nix run .#test
59       apps.test = env.app [] "zig build test -- \"$@\"";
60
61       # nix run .#docs
62       apps.docs = env.app [] "zig build docs -- \"$@\"";
63
64       # nix run .#zig2nix
65       apps.zig2nix = env.app [] "zig2nix \"$@\"";
66
67       # nix develop
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;
76       };
77     }));
78 }