-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
104 lines (93 loc) · 3.43 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
94
95
96
97
98
99
100
101
102
103
104
{
description = "Description for the project";
# Inputs are the flake references that are used in the flake.
# Nix will fetch the flake and stores the hash in the flake.lock file.
inputs = {
# Nixpkgs provides the many packags that are normally available in NixOS.
#
# WARNING:
# We currently pin the verion to 0.2311.555610 to ensure that the zig build
# works correctly. Recent updates to nixpkgs did introduce breaking changes to
# the build environemnt variables, which makes the Zig compiler fail.
#
# Issue: https://github.com/ziglang/zig/issues/18998
# When resolves remove the '=' from the URL to update to the latest stable
# version of nixpkgs.
nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/=0.2311.555610.tar.gz";
# Flake parts is a library to write flakes in a more modular way similar to
# NixOS modules.
parts.url = "github:hercules-ci/flake-parts";
# pgzx flake provides us with extra tools and a supported version of the Zig compiler.
# The flake re-exports the zig-overlay and zls flakes.
pgzx = {
url = "github:xataio/pgzx";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = inputs: let
name = "example";
version = "0.1";
in
inputs.parts.lib.mkFlake {inherit inputs;} {
# Supported system for which we want to be able to build the project on.
systems = ["x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin"];
perSystem = {
config,
lib,
pkgs,
system,
...
}: {
# Ensure that 'pkgs' has the dependencies from the pgzx flake available.
_module.args.pkgs = import inputs.nixpkgs {
inherit system;
overlays = [
inputs.pgzx.overlays.default
];
config = {
# extra configurations
#allowBroken = true;
#allowUnfree = true;
};
};
# The projects default package is the package that is built when we run `nix build`
#
# The devshell will import the projects build dependencies.
packages.default = pkgs.stdenvNoCC.mkDerivation {
pname = name;
version = version;
src = ./.;
nativeBuildInputs = [
pkgs.zigpkgs.master
pkgs.pkg-config
];
buildInputs = [
pkgs.openssl
];
};
devShells.default = let
# Load the shell configuration from devshell.nix.
userShell = (import ./devshell.nix) {
inherit lib pkgs;
# Pass the default package as project to the devshell. This
# allows the devshell to import the project and its dependencies.
project = config.packages.default;
};
mkShell = pkgs.mkShell.override {
# optionally override the default configuration of the mkShell derivation.
};
in
mkShell (userShell
// {
# Optionally override or extend the shell configuration.
# For example when using the pre-commit-hook module we want to
# merge the merge the shell hooks of our flake with the
# pre-commit-hook shellHook to ensure the all dependencies are
# properly configured when entering the shell.
shellHook = ''
${userShell.shellHook or ""}
'';
});
};
};
}