]> gitweb.ps.run Git - chirp/blob - flake.nix
60987e717a0bfc63b57b7e2daf88d1110d1573f8
[chirp] / 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       zighttp = env.pkgs.fetchFromGitHub {
16         owner = "patrick-scho";
17         repo = "zighttp";
18         rev = "274c46eb3f7e9987cc9260bb70c43b4f5d8555ac";
19         sha256 = "sha256-SUFHiA0r46QfzhlO6Ie1CByzC/+qPR2kyAbeDEdKOJ0=";
20       };
21       ziglmdb = env.pkgs.fetchFromGitHub {
22         owner = "patrick-scho";
23         repo = "ziglmdb";
24         rev = "88cb74a430fa9629c8127c3a866c40e79a8e4612";
25         sha256 = "sha256-SUFHiA0r46QfzhlO6Ie1CByzC/+qPR2kyAbeDEdKOJ0=";
26       };
27     in with builtins; with env.pkgs.lib; rec {
28       # Produces clean binaries meant to be ship'd outside of nix
29       # nix build .#foreign
30       packages.foreign = env.package {
31         src = cleanSource ./.;
32
33         # Packages required for compiling
34         nativeBuildInputs = with env.pkgs; [];
35
36         # Packages required for linking
37         buildInputs = with env.pkgs; [];
38
39         # Smaller binaries and avoids shipping glibc.
40         zigPreferMusl = true;
41       };
42
43       # nix build .
44       packages.default = packages.foreign.override (attrs: {
45         # Prefer nix friendly settings.
46         zigPreferMusl = false;
47
48         # Executables required for runtime
49         # These packages will be added to the PATH
50         zigWrapperBins = with env.pkgs; [];
51
52         # Libraries required for runtime
53         # These packages will be added to the LD_LIBRARY_PATH
54         zigWrapperLibs = attrs.buildInputs or [];
55       });
56
57       # For bundling with nix bundle for running outside of nix
58       # example: https://github.com/ralismark/nix-appimage
59       apps.bundle = {
60         type = "app";
61         program = "${packages.foreign}/bin/default";
62       };
63
64       # nix run .
65       apps.default = env.app [] "zig build run -- \"$@\"";
66
67       # nix run .#build
68       apps.build = env.app [] ''
69           mkdir -p ext
70           ln -s ${zighttp} ext/zighttp
71           ln -s ${ziglmdb} ext/ziglmdb
72           zig build "$@"
73       '';
74
75       # nix run .#test
76       apps.test = env.app [] "zig build test -- \"$@\"";
77
78       # nix run .#docs
79       apps.docs = env.app [] "zig build docs -- \"$@\"";
80
81       # nix run .#zig2nix
82       apps.zig2nix = env.app [] "zig2nix \"$@\"";
83
84       # nix develop
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;
93       };
94     }));
95 }