|
| 1 | +{ |
| 2 | + lib, |
| 3 | + stdenv, |
| 4 | + src, |
| 5 | + version, |
| 6 | + basename, |
| 7 | + autoPatchelfHook, |
| 8 | + makeWrapper, |
| 9 | + gnutar, |
| 10 | + unzip, |
| 11 | + makeDesktopItem, |
| 12 | + stlinkServerVersion, |
| 13 | + stlinkUdevVersion, |
| 14 | + jlinkUdevVersion, |
| 15 | + |
| 16 | + # Core libraries |
| 17 | + glib, |
| 18 | + gtk3, |
| 19 | + gdk-pixbuf, |
| 20 | + pango, |
| 21 | + cairo, |
| 22 | + atk, |
| 23 | + zlib, |
| 24 | + freetype, |
| 25 | + fontconfig, |
| 26 | + libx11, |
| 27 | + libxrender, |
| 28 | + libxtst, |
| 29 | + libxi, |
| 30 | + libxext, |
| 31 | + libxrandr, |
| 32 | + libxcursor, |
| 33 | + libxcomposite, |
| 34 | + libxdamage, |
| 35 | + libxfixes, |
| 36 | + libxinerama, |
| 37 | + libxxf86vm, |
| 38 | + libxcb, |
| 39 | + libxau, |
| 40 | + libxdmcp, |
| 41 | + xcbutilimage, |
| 42 | + xcbutilrenderutil, |
| 43 | + xcbutilwm, |
| 44 | + xcbutilkeysyms, |
| 45 | + libxkbcommon, |
| 46 | + dbus, |
| 47 | + dbus-glib, |
| 48 | + |
| 49 | + # Wayland support |
| 50 | + wayland, |
| 51 | + |
| 52 | + # OpenGL |
| 53 | + libGL, |
| 54 | + libGLU, |
| 55 | + mesa, |
| 56 | + |
| 57 | + # USB support (for debugging probes) |
| 58 | + libusb1, |
| 59 | + hidapi, |
| 60 | + |
| 61 | + # Ncurses (mentioned in installer) |
| 62 | + ncurses5, |
| 63 | + |
| 64 | + # For GDB |
| 65 | + expat, |
| 66 | + python3, |
| 67 | + |
| 68 | + # SSL/crypto |
| 69 | + openssl, |
| 70 | + |
| 71 | + # Additional libraries |
| 72 | + alsa-lib, |
| 73 | + at-spi2-atk, |
| 74 | + at-spi2-core, |
| 75 | + cups, |
| 76 | + udev, |
| 77 | + nspr, |
| 78 | + nss, |
| 79 | + |
| 80 | + # For CubeProgrammer |
| 81 | + pcsclite, |
| 82 | + xercesc, |
| 83 | +}: |
| 84 | + |
| 85 | +stdenv.mkDerivation (finalAttrs: { |
| 86 | + pname = "stm32cubeide"; |
| 87 | + inherit version src; |
| 88 | + |
| 89 | + strictDeps = true; |
| 90 | + __structuredAttrs = true; |
| 91 | + |
| 92 | + nativeBuildInputs = [ |
| 93 | + autoPatchelfHook |
| 94 | + makeWrapper |
| 95 | + gnutar |
| 96 | + unzip |
| 97 | + ]; |
| 98 | + |
| 99 | + buildInputs = [ |
| 100 | + # Core libraries |
| 101 | + glib |
| 102 | + gtk3 |
| 103 | + gdk-pixbuf |
| 104 | + pango |
| 105 | + cairo |
| 106 | + atk |
| 107 | + zlib |
| 108 | + freetype |
| 109 | + fontconfig |
| 110 | + libx11 |
| 111 | + libxrender |
| 112 | + libxtst |
| 113 | + libxi |
| 114 | + libxext |
| 115 | + libxrandr |
| 116 | + libxcursor |
| 117 | + libxcomposite |
| 118 | + libxdamage |
| 119 | + libxfixes |
| 120 | + libxinerama |
| 121 | + libxxf86vm |
| 122 | + libxcb |
| 123 | + libxau |
| 124 | + libxdmcp |
| 125 | + xcbutilimage |
| 126 | + xcbutilrenderutil |
| 127 | + xcbutilwm |
| 128 | + xcbutilkeysyms |
| 129 | + libxkbcommon |
| 130 | + dbus |
| 131 | + dbus-glib |
| 132 | + |
| 133 | + # Wayland support |
| 134 | + wayland |
| 135 | + |
| 136 | + # OpenGL |
| 137 | + libGL |
| 138 | + libGLU |
| 139 | + mesa |
| 140 | + |
| 141 | + # USB support (for debugging probes) |
| 142 | + libusb1 |
| 143 | + hidapi |
| 144 | + |
| 145 | + # Ncurses (mentioned in installer) |
| 146 | + ncurses5 |
| 147 | + |
| 148 | + # For GDB |
| 149 | + stdenv.cc.cc.lib |
| 150 | + expat |
| 151 | + python3 |
| 152 | + |
| 153 | + # SSL/crypto |
| 154 | + openssl |
| 155 | + |
| 156 | + # Additional libraries |
| 157 | + alsa-lib |
| 158 | + at-spi2-atk |
| 159 | + at-spi2-core |
| 160 | + cups |
| 161 | + udev |
| 162 | + nspr |
| 163 | + nss |
| 164 | + |
| 165 | + # For CubeProgrammer |
| 166 | + pcsclite |
| 167 | + xercesc |
| 168 | + ]; |
| 169 | + |
| 170 | + unpackPhase = '' |
| 171 | + runHook preUnpack |
| 172 | +
|
| 173 | + mkdir source |
| 174 | + cd source |
| 175 | + unzip $src |
| 176 | + bash ${basename}.sh --noexec --target . |
| 177 | +
|
| 178 | + runHook postUnpack |
| 179 | + ''; |
| 180 | + |
| 181 | + dontConfigure = true; |
| 182 | + dontBuild = true; |
| 183 | + |
| 184 | + installPhase = '' |
| 185 | + runHook preInstall |
| 186 | +
|
| 187 | + # Extract the main tarball |
| 188 | + mkdir -p $out/opt/stm32cubeide |
| 189 | + tar -xzf ${basename}.tar.gz -C $out/opt/stm32cubeide --strip-components=0 |
| 190 | +
|
| 191 | + # Create bin directory |
| 192 | + mkdir -p $out/bin |
| 193 | +
|
| 194 | + # Create wrapper script for the main IDE |
| 195 | + makeWrapper $out/opt/stm32cubeide/stm32cubeide $out/bin/stm32cubeide \ |
| 196 | + --prefix LD_LIBRARY_PATH : "${lib.makeLibraryPath finalAttrs.buildInputs}" \ |
| 197 | + --set GTK_THEME "Adwaita" |
| 198 | +
|
| 199 | + # Also create wayland-compatible wrapper (still uses x11 backend) |
| 200 | + makeWrapper $out/opt/stm32cubeide/stm32cubeide $out/bin/stm32cubeide_wayland \ |
| 201 | + --prefix LD_LIBRARY_PATH : "${lib.makeLibraryPath finalAttrs.buildInputs}" \ |
| 202 | + --set GDK_BACKEND x11 \ |
| 203 | + --set GTK_THEME "Adwaita" |
| 204 | +
|
| 205 | + # Create wrapper for headless build |
| 206 | + if [ -f $out/opt/stm32cubeide/headless-build.sh ]; then |
| 207 | + makeWrapper $out/opt/stm32cubeide/headless-build.sh $out/bin/stm32cubeide-headless \ |
| 208 | + --prefix LD_LIBRARY_PATH : "${lib.makeLibraryPath finalAttrs.buildInputs}" |
| 209 | + fi |
| 210 | +
|
| 211 | + # Desktop file |
| 212 | + mkdir -p $out/share/applications |
| 213 | + cp -r ${finalAttrs.desktopItem}/share/applications/*.desktop $out/share/applications |
| 214 | + cp -r ${finalAttrs.desktopItemCompat}/share/applications/*.desktop $out/share/applications |
| 215 | +
|
| 216 | + # Copy icon |
| 217 | + mkdir -p $out/share/pixmaps |
| 218 | + mkdir -p $out/share/icons/hicolor/stm32cubeide/apps |
| 219 | + if [ -f $out/opt/stm32cubeide/icon.xpm ]; then |
| 220 | + cp $out/opt/stm32cubeide/icon.xpm $out/share/pixmaps/stm32cubeide.xpm |
| 221 | + cp $out/opt/stm32cubeide/icon.xpm $out/share/icons/hicolor/stm32cubeide/apps/stm32cubeide.xpm |
| 222 | + fi |
| 223 | +
|
| 224 | + # Install stlink-server from the separate package |
| 225 | + mkdir -p $out/opt/stlink-server |
| 226 | + bash st-stlink-server.${stlinkServerVersion}-linux-amd64.install.sh \ |
| 227 | + --noexec --target $out/opt/stlink-server |
| 228 | +
|
| 229 | + if [ -f $out/opt/stlink-server/stlink-server ]; then |
| 230 | + chmod +x $out/opt/stlink-server/stlink-server |
| 231 | + makeWrapper $out/opt/stlink-server/stlink-server $out/bin/stlink-server \ |
| 232 | + --prefix LD_LIBRARY_PATH : "${lib.makeLibraryPath [ libusb1 ]}" |
| 233 | + fi |
| 234 | +
|
| 235 | + # install the various udev rules |
| 236 | + mkdir udev |
| 237 | + bash segger-jlink-udev-rules-${jlinkUdevVersion}-linux-noarch.sh --noexec --target udev |
| 238 | + bash st-stlink-udev-rules-${stlinkUdevVersion}-linux-noarch.sh --noexec --target udev |
| 239 | + mkdir -p $out/lib/udev/rules.d |
| 240 | + cp udev/*.rules $out/lib/udev/rules.d/ |
| 241 | +
|
| 242 | + runHook postInstall |
| 243 | + ''; |
| 244 | + |
| 245 | + # autoPatchelfHook settings |
| 246 | + autoPatchelfIgnoreMissingDeps = [ |
| 247 | + # These are bundled with the application |
| 248 | + "libjli.so" |
| 249 | + "libSTLinkUSBDriver.so" |
| 250 | + "libhsmp11.so" |
| 251 | + "libPreparation.so.1" |
| 252 | + # Bundled Qt6 (for CubeProgrammer) |
| 253 | + "libQt6Core.so.6" |
| 254 | + "libQt6DBus.so.6" |
| 255 | + "libQt6Gui.so.6" |
| 256 | + "libQt6Network.so.6" |
| 257 | + "libQt6OpenGL.so.6" |
| 258 | + "libQt6Qml.so.6" |
| 259 | + "libQt6SerialPort.so.6" |
| 260 | + "libQt6Widgets.so.6" |
| 261 | + "libQt6XcbQpa.so.6" |
| 262 | + "libQt6Xml.so.6" |
| 263 | + "libQt6EglFSDeviceIntegration.so.6" |
| 264 | + "libQt6WaylandEglClientHwIntegration.so.6" |
| 265 | + "libQt6WaylandClient.so.6" |
| 266 | + # Bundled Qt4 (for JLink tools) |
| 267 | + "libQtCore.so.4" |
| 268 | + "libQtGui.so.4" |
| 269 | + # Bundled JLink |
| 270 | + "libjlinkarm.so" |
| 271 | + "libjlinkarm.so.8" |
| 272 | + # Optional FFmpeg plugins for JRE (not needed for IDE) |
| 273 | + "libavformat-ffmpeg.so.56" |
| 274 | + "libavcodec-ffmpeg.so.56" |
| 275 | + "libavformat.so.54" |
| 276 | + "libavcodec.so.54" |
| 277 | + "libavformat.so.56" |
| 278 | + "libavcodec.so.56" |
| 279 | + "libavformat.so.57" |
| 280 | + "libavcodec.so.57" |
| 281 | + "libavformat.so.58" |
| 282 | + "libavcodec.so.58" |
| 283 | + "libavformat.so.59" |
| 284 | + "libavcodec.so.59" |
| 285 | + "libavformat.so.60" |
| 286 | + "libavcodec.so.60" |
| 287 | + # xerces versioned lib (we have 3.3, it wants 3.2) |
| 288 | + "libxerces-c-3.2.so" |
| 289 | + ]; |
| 290 | + |
| 291 | + # Set rpath for bundled libraries to find each other |
| 292 | + postFixup = '' |
| 293 | + # Fix the CubeProgrammer tools to find their bundled libs |
| 294 | + CUBEPROG_DIR=$(find $out/opt/stm32cubeide/plugins -type d -name "com.st.stm32cube.ide.mcu.externaltools.cubeprogrammer.linux64_*" | head -1) |
| 295 | + if [ -n "$CUBEPROG_DIR" ]; then |
| 296 | + patchelf --set-rpath "$CUBEPROG_DIR/tools/lib:${lib.makeLibraryPath finalAttrs.buildInputs}" \ |
| 297 | + $CUBEPROG_DIR/tools/bin/STM32_Programmer_CLI || true |
| 298 | + fi |
| 299 | +
|
| 300 | + # Fix JLink tools to find their bundled libs |
| 301 | + JLINK_DIR=$(find $out/opt/stm32cubeide/plugins -type d -name "com.st.stm32cube.ide.mcu.externaltools.jlink.linux64_*" | head -1) |
| 302 | + if [ -n "$JLINK_DIR" ]; then |
| 303 | + for bin in $JLINK_DIR/tools/bin/JLink*; do |
| 304 | + if [ -f "$bin" ] && [ -x "$bin" ]; then |
| 305 | + patchelf --set-rpath "$JLINK_DIR/tools/bin:${lib.makeLibraryPath finalAttrs.buildInputs}" "$bin" || true |
| 306 | + fi |
| 307 | + done |
| 308 | + fi |
| 309 | +
|
| 310 | + # Fix the bundled JRE |
| 311 | + JRE_DIR=$(find $out/opt/stm32cubeide/plugins -type d -name "com.st.stm32cube.ide.jre.linux64_*" | head -1) |
| 312 | + if [ -n "$JRE_DIR" ] && [ -d "$JRE_DIR/jre" ]; then |
| 313 | + for bin in $JRE_DIR/jre/bin/*; do |
| 314 | + if [ -f "$bin" ] && [ -x "$bin" ]; then |
| 315 | + patchelf --set-rpath "$JRE_DIR/jre/lib:$JRE_DIR/jre/lib/server:${lib.makeLibraryPath finalAttrs.buildInputs}" "$bin" || true |
| 316 | + fi |
| 317 | + done |
| 318 | + for lib in $JRE_DIR/jre/lib/*.so $JRE_DIR/jre/lib/server/*.so; do |
| 319 | + if [ -f "$lib" ]; then |
| 320 | + patchelf --set-rpath "$JRE_DIR/jre/lib:$JRE_DIR/jre/lib/server:${lib.makeLibraryPath finalAttrs.buildInputs}" "$lib" || true |
| 321 | + fi |
| 322 | + done |
| 323 | + fi |
| 324 | + ''; |
| 325 | + |
| 326 | + desktopItem = makeDesktopItem { |
| 327 | + name = "stm32cubeide"; |
| 328 | + comment = "Integrated Development Environment for STM32"; |
| 329 | + genericName = "STM32 IDE"; |
| 330 | + desktopName = "STM32CubeIDE ${version}"; |
| 331 | + exec = "stm32cubeide %F"; |
| 332 | + icon = "stm32cubeide"; |
| 333 | + terminal = false; |
| 334 | + startupNotify = true; |
| 335 | + categories = [ |
| 336 | + "Development" |
| 337 | + "IDE" |
| 338 | + "Electronics" |
| 339 | + ]; |
| 340 | + mimeTypes = [ "application/x-stm32cubeide" ]; |
| 341 | + }; |
| 342 | + |
| 343 | + desktopItemCompat = makeDesktopItem { |
| 344 | + name = "stm32cubeide_wayland"; |
| 345 | + comment = "Integrated Development Environment for STM32 (Wayland compatibility with X11)"; |
| 346 | + genericName = "STM32 IDE"; |
| 347 | + desktopName = "STM32CubeIDE ${version} (Wayland Compat)"; |
| 348 | + exec = "stm32cubeide_wayland %F"; |
| 349 | + icon = "stm32cubeide"; |
| 350 | + terminal = false; |
| 351 | + startupNotify = true; |
| 352 | + categories = [ |
| 353 | + "Development" |
| 354 | + "IDE" |
| 355 | + "Electronics" |
| 356 | + ]; |
| 357 | + mimeTypes = [ "application/x-stm32cubeide" ]; |
| 358 | + }; |
| 359 | + |
| 360 | + meta = { |
| 361 | + description = "Integrated Development Environment for STM32 microcontrollers"; |
| 362 | + homepage = "https://www.st.com/en/development-tools/stm32cubeide.html"; |
| 363 | + license = lib.licenses.unfree; |
| 364 | + platforms = [ "x86_64-linux" ]; |
| 365 | + maintainers = with lib.maintainers; [ sempiternal-aurora ]; |
| 366 | + sourceProvenance = [ lib.sourceTypes.binaryNativeCode ]; |
| 367 | + }; |
| 368 | +}) |
0 commit comments