1{ lib
2, fetchurl
3, makeDesktopItem
4, symlinkJoin
5, writeShellScriptBin
6, wine
7}:
8
9let
10 inherit (lib) last splitString;
11
12 pname = "winbox";
13 version = "3.38";
14 name = "${pname}-${version}";
15
16 executable = fetchurl (if (wine.meta.mainProgram == "wine64") then {
17 url = "https://download.mikrotik.com/winbox/${version}/winbox64.exe";
18 sha256 = "RV+j8FQigpwPprR2xuMYpDRMDwugSZD+O2ZmyPZDz54=";
19 } else {
20 url = "https://download.mikrotik.com/winbox/${version}/winbox.exe";
21 sha256 = "dh3P+otukhnEpVTqTu16MgIHVnJbzp4Voj+wZ3r5Fxg=";
22 });
23
24 # This is from the winbox AUR package:
25 # https://aur.archlinux.org/cgit/aur.git/tree/winbox64?h=winbox64&id=8edd93792af84e87592e8645ca09e9795931e60e
26 wrapper = writeShellScriptBin pname ''
27 export WINEPREFIX="''${WINBOX_HOME:-"''${XDG_DATA_HOME:-"''${HOME}/.local/share"}/winbox"}/wine"
28 export WINEDLLOVERRIDES="mscoree=" # disable mono
29 export WINEDEBUG=-all
30 if [ ! -d "$WINEPREFIX" ] ; then
31 mkdir -p "$WINEPREFIX"
32 ${wine}/bin/wineboot -u
33 fi
34
35 ${wine}/bin/${wine.meta.mainProgram} ${executable} "$@"
36 '';
37
38 desktopItem = makeDesktopItem {
39 name = pname;
40 desktopName = "Winbox";
41 comment = "GUI administration for Mikrotik RouterOS";
42 exec = pname;
43 icon = pname;
44 categories = [ "Utility" ];
45 startupWMClass = last (splitString "/" executable);
46 };
47
48 # The icon is also from the winbox AUR package (see above).
49 icon = fetchurl {
50 name = "winbox.png";
51 url = "https://aur.archlinux.org/cgit/aur.git/plain/winbox.png?h=winbox";
52 sha256 = "sha256-YD6u2N+1thRnEsXO6AHm138fRda9XEtUX5+EGTg004A=";
53 };
54in
55symlinkJoin {
56 inherit name pname version;
57 paths = [ wrapper desktopItem ];
58
59 postBuild = ''
60 mkdir -p "$out/share/pixmaps"
61 ln -s "${icon}" "$out/share/pixmaps/${pname}.png"
62 '';
63
64 meta = with lib; {
65 description = "Graphical configuration utility for RouterOS-based devices";
66 homepage = "https://mikrotik.com";
67 downloadPage = "https://mikrotik.com/download";
68 changelog = "https://wiki.mikrotik.com/wiki/Winbox_changelog";
69 sourceProvenance = with sourceTypes; [ binaryNativeCode ];
70 license = licenses.unfree;
71 maintainers = with maintainers; [ yrd ];
72 };
73}