-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
64 lines (53 loc) · 1.61 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
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixpkgs-unstable";
};
outputs = {
self,
nixpkgs,
...
} @ inputs: let
system = "aarch64-darwin";
pkgs = import nixpkgs {
inherit system;
};
# Zig compiler does not support the isysroot flag, and it is not needed
removeSysroot = ''
export NIX_CFLAGS_COMPILE=$(echo $NIX_CFLAGS_COMPILE | sed 's|-isysroot /nix/store/[^ ]*||')
'';
# Zig can't find the supporting libGL.tbd, we can add it to the linker flags
nixLDFlags = "-L${pkgs.darwin.apple_sdk.frameworks.OpenGL}/Library/Frameworks/OpenGL.framework/Versions/A/Libraries";
in {
packages.${system}.default = pkgs.stdenv.mkDerivation {
name = "phy";
src = ./.;
nativeBuildInputs = [pkgs.zig.hook];
buildInputs = [pkgs.darwin.apple_sdk.frameworks.OpenGL pkgs.glfw];
# The shader paths are hardcoded in the source code
patchPhase = ''
sed -i "s|shader/vertex.glsl|$out/shader/vertex.glsl|" src/app.zig
sed -i "s|shader/fragment.glsl|$out/shader/fragment.glsl|" src/app.zig
'';
NIX_LDFLAGS = nixLDFlags;
buildPhase = removeSysroot;
postInstall = ''
mkdir -p $out/shader
cp shader/* $out/shader
'';
};
devShells.${system}.default = pkgs.mkShell {
packages = [
pkgs.clangStdenv
pkgs.glfw
pkgs.zls
pkgs.zig
pkgs.darwin.apple_sdk.frameworks.OpenGL
];
shellHook = ''
export NIX_LDFLAGS=${nixLDFlags}$NIX_LDFLAGS
${removeSysroot}
'';
};
formatter.${system} = pkgs.alejandra;
};
}