-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoverlay.nix
More file actions
342 lines (300 loc) · 15 KB
/
Copy pathoverlay.nix
File metadata and controls
342 lines (300 loc) · 15 KB
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
final: prev:
let
# --- THE TROJAN HORSE ---
darwinDummy = name: prev.stdenv.mkDerivation {
pname = "${name}-mac-dummy";
version = "1.0.0";
unpackPhase = "true";
installPhase = "mkdir -p $out";
meta = {
platforms = prev.lib.platforms.all;
badPlatforms = [];
};
};
# CRITICAL FIX: This MUST track 'final' so it sees the .extend patches below!
rosPkgs = final.rosPackages.jazzy;
rawDepsMap = builtins.fromJSON (builtins.readFile ./deps.json);
depsMap = builtins.removeAttrs rawDepsMap [ "_comment" ];
systemDeps = {
"eigen" = prev.eigen;
"libboost-dev" = prev.boost;
"libopencv-dev" = prev.opencv;
"yaml-cpp" = prev.yaml-cpp;
"moreutils" = prev.moreutils;
"tmux" = prev.tmux;
"tmuxinator" = prev.tmuxinator;
"libncurses" = prev.ncurses;
"libncurses-dev" = prev.ncurses;
"libpcl-all-dev" = prev.pcl;
"apr" = prev.apr;
"git" = prev.git;
"curl" = prev.curl;
"libjsoncpp-dev" = prev.jsoncpp;
"libjsoncpp" = prev.jsoncpp;
"libtins-dev" = prev.libtins;
"net-tools" = prev.net-tools;
"nmap" = prev.nmap;
"spdlog" = prev.spdlog;
"vtk" = prev.vtk;
"qtbase5-dev" = prev.qt5.qtbase;
};
linuxOnlyDeps = [
"lttng-tools"
"lttng-ust"
"lttng-modules"
"tracetools"
"ros2trace"
"tracetools-launch"
"tracetools-read"
"tracetools-trace"
"elfutils"
"libcap"
"acl"
"attr"
];
resolveDep = name:
let
nixName = builtins.replaceStrings ["_"] ["-"] name;
in
if prev.stdenv.isDarwin && (builtins.elem name linuxOnlyDeps || builtins.elem nixName linuxOnlyDeps) then
builtins.trace "⚠️ MAC WORKAROUND: Dropping Linux-only dependency '${name}'" null
else if builtins.hasAttr name systemDeps then systemDeps.${name}
else if builtins.hasAttr name depsMap then final.mrsCustomPkgs.${name}
else if builtins.hasAttr nixName rosPkgs then rosPkgs.${nixName}
else if builtins.hasAttr name rosPkgs then rosPkgs.${name}
else builtins.trace "⚠️ WARNING: Dependency '${name}' not found!"
null;
mrsPackages = prev.lib.mapAttrs (pkgName: pkgData:
let
fetchedRepo = builtins.fetchGit {
url = pkgData.git_remote;
rev = pkgData.git_rev;
# submodules = true;
};
srcPath = if (pkgData.path or "") == "" then fetchedRepo else fetchedRepo + "/${pkgData.path}";
resolvedExecDepends = builtins.filter (x: x != null) (builtins.map resolveDep (pkgData.exec_depends or []));
in
if (pkgData.build_type or "") == "raw_copy" then
prev.stdenv.mkDerivation {
pname = pkgName;
version = pkgData.version;
src = srcPath;
dontConfigure = true;
dontBuild = true;
dontStrip = true;
installPhase = let
mapping = pkgData.install_mapping or { "*" = "."; };
copyCommands = prev.lib.mapAttrsToList (src: dest:
if src == "*" && dest == "." then "cp -a * $out/"
else "mkdir -p \"$out/$(dirname \"${dest}\")\"\ncp -a \"${src}\" \"$out/${dest}\""
) mapping;
in "mkdir -p $out\n${builtins.concatStringsSep "\n" copyCommands}";
propagatedBuildInputs = resolvedExecDepends;
}
else if pkgData.build_type == "cmake" then
prev.stdenv.mkDerivation {
pname = pkgName;
version = pkgData.version;
src = "${fetchedRepo}/${pkgData.path}";
nativeBuildInputs = [ prev.cmake prev.pkg-config ];
buildInputs = map resolveDep pkgData.build_depends;
cmakeFlags = [ "-DCMAKE_POLICY_VERSION_MINIMUM=3.5" ];
}
else
rosPkgs.buildRosPackage {
pname = pkgName;
version = pkgData.version;
src = srcPath;
buildType = "ament_cmake";
__structuredAttrs = true;
cmakeFlags = [ "-DCMAKE_NINJA_FORCE_RESPONSE_FILE=1" ];
env.NIX_CFLAGS_COMPILE = "-Wno-error=nonnull -Wno-nonnull -Wno-register -DPyEval_CallObject=PyObject_CallObject";
env.ROS_DISTRO = "jazzy";
separateDebugInfo = false;
dontStrip = true;
nativeBuildInputs = builtins.filter (x: x != null) (builtins.map resolveDep pkgData.buildtool_depends);
buildInputs = builtins.filter (x: x != null) (builtins.map resolveDep pkgData.build_depends);
propagatedBuildInputs = builtins.filter (x: x != null) (builtins.map resolveDep (pkgData.exec_depends ++ (pkgData.build_export_depends or [])));
passthru.test_depends = builtins.filter (x: x != null) (builtins.map resolveDep pkgData.test_depends);
doCheck = false;
postInstall = "mkdir -p $out";
}
) depsMap;
in {
mrsCustomPkgs = mrsPackages // {
livox-sdk2 = if builtins.hasAttr "livox-sdk2" mrsPackages then
mrsPackages."livox-sdk2".overrideAttrs (old: {
env = (old.env or {}) // {
NIX_CFLAGS_COMPILE = (old.env.NIX_CFLAGS_COMPILE or "")
+ " -Wno-unknown-warning-option -Wno-deprecated-declarations -Wno-unused-private-field -Wno-delete-non-abstract-non-virtual-dtor -Wno-non-c-typedef-for-linkage -Wno-unused-const-variable -Wno-unused-parameter -Wno-ignored-qualifiers";
};
postPatch = (old.postPatch or "") + ''
echo "Stripping aggressive -Werror flags from Livox CMake files..."
find . -type f -name "CMakeLists.txt" -exec sed -i 's/-Werror//g' {} +
find . -type f -name "*.cmake" -exec sed -i 's/-Werror//g' {} +
echo "Injecting warning suppressions directly into CMake..."
sed -i '1i set(CMAKE_CXX_FLAGS "''${CMAKE_CXX_FLAGS} -Wno-error=deprecated-literal-operator -Wno-error=deprecated-declarations")' CMakeLists.txt
'' + (if prev.stdenv.isDarwin then ''
echo "Bypassing macOS ranlib I/O error by forcing the static target to build as shared..."
find . -type f -name "CMakeLists.txt" -exec sed -i 's/livox_lidar_sdk_static STATIC/livox_lidar_sdk_static SHARED/g' {} +
'' else "");
})
else {};
# 2. Comprehensive fix for livox_ros_driver2 (macOS + Nix Sandbox + VTK Leak)
livox_ros_driver2 = if builtins.hasAttr "livox_ros_driver2" mrsPackages then
mrsPackages."livox_ros_driver2".overrideAttrs (old: {
buildInputs = (old.buildInputs or []) ++ [
final.mrsCustomPkgs."livox-sdk2"
prev.vtk
prev.qt5.qtbase
];
# Cleanly merge the C++ flags here as well
env = (old.env or {}) // {
NIX_CFLAGS_COMPILE = (old.env.NIX_CFLAGS_COMPILE or "")
+ " -Wno-unknown-warning-option -Wno-deprecated-declarations -Wno-unused-private-field -Wno-delete-non-abstract-non-virtual-dtor -Wno-non-c-typedef-for-linkage -Wno-unused-const-variable -Wno-unused-parameter -Wno-ignored-qualifiers";
};
postPatch = (old.postPatch or "") + ''
echo "Fixing macOS 'long' vs 'long long' strictness for ROS 2 parameters..."
find . -type f \( -name "*.cpp" -o -name "*.h" -o -name "*.hpp" \) -exec sed -i -E 's/std::vector<\s*long\s*>/std::vector<int64_t>/g' {} +
find . -type f \( -name "*.cpp" -o -name "*.h" -o -name "*.hpp" \) -exec sed -i -E 's/std::vector<\s*long\s+int\s*>/std::vector<int64_t>/g' {} +
find . -type f \( -name "*.cpp" -o -name "*.h" -o -name "*.hpp" \) -exec sed -i -E 's/\bvector<\s*long\s*>/vector<int64_t>/g' {} +
echo "Bypassing pcl_ros VTK::GUISupportQt leak with a dummy target..."
# Satisfies CMake's target requirement without actually linking Qt GUI libraries
sed -i '1i add_library(VTK::GUISupportQt INTERFACE IMPORTED)' CMakeLists.txt
echo "Fixing hardcoded Linux .so extensions for macOS compatibility..."
# By removing 'lib' and '.so', CMake will dynamically search for .dylib on macOS and .so on Linux
sed -i 's/liblivox_lidar_sdk_shared\.so/livox_lidar_sdk_shared/g' CMakeLists.txt
echo "Stripping hardcoded /usr/local/lib path for Nix hermeticity..."
sed -i 's|/usr/local/lib||g' CMakeLists.txt
'';
})
else {};
};
lttng-tools = if prev.stdenv.isDarwin then darwinDummy "lttng-tools" else prev.lttng-tools;
lttng-ust = if prev.stdenv.isDarwin then darwinDummy "lttng-ust" else prev.lttng-ust;
lttng-modules = if prev.stdenv.isDarwin then darwinDummy "lttng-modules" else prev.lttng-modules;
elfutils = if prev.stdenv.isDarwin then darwinDummy "elfutils" else prev.elfutils;
libcap = if prev.stdenv.isDarwin then darwinDummy "libcap" else prev.libcap;
acl = if prev.stdenv.isDarwin then darwinDummy "acl" else prev.acl;
attr = if prev.stdenv.isDarwin then darwinDummy "attr" else prev.attr;
glib = if prev.stdenv.isDarwin then prev.glib.overrideAttrs (old: {
mesonFlags = (old.mesonFlags or []) ++ [ "-Dlibelf=disabled" ];
}) else prev.glib;
openldap = if prev.stdenv.isDarwin then prev.openldap.overrideAttrs (old: {
doCheck = false;
}) else prev.openldap;
laszip = if prev.stdenv.isDarwin then prev.laszip.overrideAttrs (old: {
postPatch = (old.postPatch or "") + ''
echo "" > dll/CMakeLists.txt
'';
}) else prev.laszip;
rosPackages = prev.rosPackages // {
jazzy = prev.rosPackages.jazzy.overrideScope (rosFinal: rosPrev: {
foonathan-memory-vendor = rosPrev.foonathan-memory-vendor.overrideAttrs (old: {
# 1. The Native Nix Sledgehammer:
# Inject the flag directly into the Nix compiler wrapper so every single
# C++ compilation step inherits it, regardless of CMake isolation.
NIX_CFLAGS_COMPILE = toString (old.NIX_CFLAGS_COMPILE or "") + " -Wno-error=deprecated-literal-operator";
# 2. The CMake Top-of-File Injection:
# Use `sed -i '1i ...'` to physically insert the warning suppression at
# Line 1 of the file, guaranteeing it executes before ExternalProject_Add.
postPatch = (old.postPatch or "") + ''
sed -i '1i set(CMAKE_CXX_FLAGS "''${CMAKE_CXX_FLAGS} -Wno-error=deprecated-literal-operator")' CMakeLists.txt
'';
});
rosbag2-transport = rosPrev.rosbag2-transport.overrideAttrs (old: {
postPatch = (old.postPatch or "") + ''
echo "Fixing Clang TSA attribute placement vs brace initialization on macOS..."
substituteInPlace src/rosbag2_transport/locked_priority_queue.hpp \
--replace-fail 'size_t insert_sequence_number_{0} RCPPUTILS_TSA_GUARDED_BY(queue_mutex_);' \
'size_t insert_sequence_number_ RCPPUTILS_TSA_GUARDED_BY(queue_mutex_){0};'
'';
});
libmavconn = rosPrev.libmavconn.overrideAttrs (old: {
postPatch = (old.postPatch or "") + ''
# 7. Clean up Clang literal operator warnings
find . -type f -name "*.hpp" -exec sed -i 's/operator"" _KiB/operator""_KiB/g' {} +
echo "Injecting macOS endianness polyfill..."
cat << 'EOF' > mac_endian.h
#ifdef __APPLE__
#include <libkern/OSByteOrder.h>
#ifndef htole16
#define htole16(x) OSSwapHostToLittleInt16(x)
#define le16toh(x) OSSwapLittleToHostInt16(x)
#define htole32(x) OSSwapHostToLittleInt32(x)
#define le32toh(x) OSSwapLittleToHostInt32(x)
#define htole64(x) OSSwapHostToLittleInt64(x)
#define le64toh(x) OSSwapLittleToHostInt64(x)
#endif
#endif
EOF
# Inject the polyfill directly into CMakeLists.txt after the project() declaration
sed -i '/project(/a add_compile_options("-include" "''${CMAKE_CURRENT_SOURCE_DIR}/mac_endian.h")' CMakeLists.txt
'';
});
mavros = rosPrev.mavros.overrideAttrs (old: {
postPatch = (old.postPatch or "") + ''
echo "Injecting macOS endianness polyfill for mavros..."
cat << 'EOF' > mac_endian.h
#ifdef __APPLE__
#include <libkern/OSByteOrder.h>
#ifndef htole16
#define htole16(x) OSSwapHostToLittleInt16(x)
#define le16toh(x) OSSwapLittleToHostInt16(x)
#define htole32(x) OSSwapHostToLittleInt32(x)
#define le32toh(x) OSSwapLittleToHostInt32(x)
#define htole64(x) OSSwapHostToLittleInt64(x)
#define le64toh(x) OSSwapLittleToHostInt64(x)
#endif
#endif
EOF
# Inject the polyfill directly into CMakeLists.txt after the project() declaration
sed -i '/project(/a add_compile_options("-include" "''${CMAKE_CURRENT_SOURCE_DIR}/mac_endian.h")' CMakeLists.txt
'';
});
mavros-extras = rosPrev.mavros-extras.overrideAttrs (old: {
postPatch = (old.postPatch or "") + ''
echo "Injecting macOS endianness polyfill for mavros..."
cat << 'EOF' > mac_endian.h
#ifdef __APPLE__
#include <libkern/OSByteOrder.h>
#ifndef htole16
#define htole16(x) OSSwapHostToLittleInt16(x)
#define le16toh(x) OSSwapLittleToHostInt16(x)
#define htole32(x) OSSwapHostToLittleInt32(x)
#define le32toh(x) OSSwapLittleToHostInt32(x)
#define htole64(x) OSSwapHostToLittleInt64(x)
#define le64toh(x) OSSwapLittleToHostInt64(x)
#endif
#endif
EOF
echo "Injecting macOS dynamic lookup linker flag for mavros_extras_plugins..."
# Append the Apple-specific linker flag to the end of CMakeLists.txt
cat << 'EOF' >> CMakeLists.txt
if(APPLE)
set_target_properties(mavros_extras_plugins PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
endif()
EOF
# Inject the polyfill directly into CMakeLists.txt after the project() declaration
sed -i '/project(/a add_compile_options("-include" "''${CMAKE_CURRENT_SOURCE_DIR}/mac_endian.h")' CMakeLists.txt
#### fixed in upstream already, should be part of the next release
echo "Globally migrating tf2::fromMsg to tf2::transformToEigen across all plugins..."
find src/plugins -type f -name "*.cpp" -exec sed -i -E 's/tf2::fromMsg\(([^,]*transform[^,]*),\s*([^)]+)\);/\2 = tf2::transformToEigen(\1);/gi' {} +
echo "Reverting regex overshoot for quaternion and translation sub-fields..."
# This undoes the damage if the regex accidentally caught .rotation or .translation fields
find src/plugins -type f -name "*.cpp" -exec sed -i -E 's/([a-zA-Z0-9_]+)\s*=\s*tf2::transformToEigen\(([^)]*\.(rotation|translation))\);/tf2::fromMsg(\2, \1);/gi' {} +
####
#### fixed in upstream (https://github.com/mavlink/mavros/pull/2221), will be part of the next release
substituteInPlace src/plugins/hil.cpp \
--replace-fail 'auto lin_vel = ftf::transform' 'Eigen::Vector3d lin_vel = ftf::transform' \
--replace-fail 'auto ang_vel = ftf::transform' 'Eigen::Vector3d ang_vel = ftf::transform'
substituteInPlace src/plugins/mount_control.cpp \
--replace-fail 'auto vec = Eigen::Vector3d' 'Eigen::Vector3d vec = Eigen::Vector3d'
substituteInPlace src/plugins/landing_target.cpp \
--replace-fail 'Eigen::Vector2f angle;' 'Eigen::Vector2f angle = Eigen::Vector2f::Zero();'
####
'';
});
});
};
}