-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
164 lines (142 loc) · 5.65 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
{
description = "tomato flake";
# bc flakes and git submodules dont really like each other, you need to
# append '.?submodules=1#' to the nix commands.
# $ nix bundle --bundler github:ralismark/nix-appimage 'git+file:///home/green/workspace/tox/tomato?submodules=1#'
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/release-24.05";
flake-utils.url = "github:numtide/flake-utils";
nlohmann-json = {
url = "github:nlohmann/json/v3.11.3"; # TODO: read version from file
flake = false;
};
sdl3 = {
url = "github:libsdl-org/SDL/90b2e2527eeb6614cedd15f61062f62680252be6"; # keep in sync with cmake
flake = false;
};
sdl3_image = {
url = "github:libsdl-org/SDL_image/6f4584340b9b78542d11bf0232a1a0862de1f0a9";
flake = false;
};
implot = {
url = "github:epezent/implot/47522f47054d33178e7defa780042bd2a06b09f9";
flake = false;
};
};
outputs = { self, nixpkgs, flake-utils, nlohmann-json, sdl3, sdl3_image, implot }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
stdenv = (pkgs.stdenvAdapters.keepDebugInfo pkgs.stdenv);
#stdenv = (pkgs.stdenvAdapters.withCFlags [ "-march=x86-64-v3" ] (pkgs.stdenvAdapters.keepDebugInfo pkgs.stdenv));
in {
#packages.default = pkgs.stdenv.mkDerivation {
packages.default = stdenv.mkDerivation {
pname = "tomato";
version = "0.0.0";
src = ./.;
submodules = 1; # does nothing
nativeBuildInputs = with pkgs; [
cmake
ninja
pkg-config
patchelf
];
# for some reason, buildInputs performs some magic an converts them to build dependencies, not runtime dependencies
# also, non static dependencies (?? how to ensure ??)
dlopenBuildInputs = with pkgs; [
dbus
xorg.libX11
xorg.libXext
xorg.xorgproto
libxkbcommon
xorg.libICE
xorg.libXi
xorg.libXScrnSaver
xorg.libXcursor
xorg.libXinerama
xorg.libXrandr
xorg.libXxf86vm
libGL
pipewire
libayatana-appindicator
# sdl3_image:
libpng
libjpeg
libjxl
libavif
#libwebp # still using our own loader
];
buildInputs = with pkgs; [
#(libsodium.override { stdenv = pkgs.pkgsStatic.stdenv; })
#pkgsStatic.libsodium
libsodium
libopus
libvpx
] ++ self.packages.${system}.default.dlopenBuildInputs;
cmakeFlags = [
"-DTOMATO_TOX_AV=ON"
"-DTOMATO_ASAN=OFF"
"-DCMAKE_BUILD_TYPE=RelWithDebInfo"
#"-DCMAKE_BUILD_TYPE=Debug"
#"-DCMAKE_C_FLAGS:STRING=-Og"
#"-DCMAKE_CXX_FLAGS:STRING=-Og"
# TODO: use package instead
"-DFETCHCONTENT_SOURCE_DIR_JSON=${nlohmann-json}" # we care about the version
"-DFETCHCONTENT_SOURCE_DIR_ZSTD=${pkgs.zstd.src}" # we dont care about the version (we use 1.4.x features)
"-DFETCHCONTENT_SOURCE_DIR_LIBWEBP=${pkgs.libwebp.src}"
"-DFETCHCONTENT_SOURCE_DIR_SDL3=${sdl3}"
"-DFETCHCONTENT_SOURCE_DIR_SDL3_IMAGE=${sdl3_image}"
"-DSDLIMAGE_JXL=ON"
"-DFETCHCONTENT_SOURCE_DIR_IMPLOT=${implot}" # could use pkgs.implot.src for outdated version
];
# TODO: replace with install command
installPhase = ''
mkdir -p $out/bin
mv bin/tomato $out/bin
'';
dontStrip = true; # does nothing
# copied from nixpkgs's SDL2 default.nix
# SDL is weird in that instead of just dynamically linking with
# libraries when you `--enable-*` (or when `configure` finds) them
# it `dlopen`s them at runtime. In principle, this means it can
# ignore any missing optional dependencies like alsa, pulseaudio,
# some x11 libs, wayland, etc if they are missing on the system
# and/or work with wide array of versions of said libraries. In
# nixpkgs, however, we don't need any of that. Moreover, since we
# don't have a global ld-cache we have to stuff all the propagated
# libraries into rpath by hand or else some applications that use
# SDL API that requires said libraries will fail to start.
#
# You can grep SDL sources with `grep -rE 'SDL_(NAME|.*_SYM)'` to
# list the symbols used in this way.
# TODO: only patch if building FOR nix (like not for when static building)
postFixup =
let
#rpath = lib.makeLibraryPath (dlopenPropagatedBuildInputs ++ dlopenBuildInputs);
rpath = nixpkgs.lib.makeLibraryPath (self.packages.${system}.default.dlopenBuildInputs);
in
nixpkgs.lib.optionalString (pkgs.stdenv.hostPlatform.extensions.sharedLibrary == ".so") ''
patchelf --set-rpath "$(patchelf --print-rpath $out/bin/tomato):${rpath}" "$out/bin/tomato"
'';
};
#packages.debug = pkgs.enableDebugging self.packages.${system}.default;
devShells.${system}.default = pkgs.mkShell {
#inputsFrom = with pkgs; [ SDL2 ];
buildInputs = [ self.packages.${system}.default ]; # this makes a prebuild tomato available in the shell, do we want this?
packages = with pkgs; [
cmake
pkg-config
];
shellHook = ''
echo hello to tomato dev shell!
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/run/opengl-driver/lib
'';
};
apps.default = {
type = "app";
program = "${self.packages.${system}.default}/bin/tomato";
};
}
);
}