Skip to content

Commit f3e80c7

Browse files
authored
winbox4: add MacOS aarch64 support (#384296)
2 parents aaf817b + 39a5458 commit f3e80c7

File tree

3 files changed

+177
-108
lines changed

3 files changed

+177
-108
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
pname,
3+
version,
4+
hash,
5+
fetchurl,
6+
stdenvNoCC,
7+
undmg,
8+
metaCommon ? { },
9+
}:
10+
11+
stdenvNoCC.mkDerivation (finalAttrs: {
12+
inherit pname version;
13+
14+
src = fetchurl {
15+
name = "WinBox-${finalAttrs.version}.dmg";
16+
url = "https://download.mikrotik.com/routeros/winbox/${finalAttrs.version}/WinBox.dmg";
17+
inherit hash;
18+
};
19+
20+
sourceRoot = ".";
21+
22+
nativeBuildInputs = [ undmg ];
23+
24+
installPhase = ''
25+
runHook preInstall
26+
27+
mkdir -p $out/{bin,Applications}
28+
cp -R "WinBox.app" "$out/Applications/WinBox.app"
29+
ln -s "$out/Applications/WinBox.app/Contents/MacOS/WinBox" "$out/bin/WinBox"
30+
31+
runHook postInstall
32+
'';
33+
34+
meta = metaCommon // {
35+
platforms = [ "aarch64-darwin" ];
36+
};
37+
})
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
{
2+
pname,
3+
version,
4+
hash,
5+
autoPatchelfHook,
6+
copyDesktopItems,
7+
fetchurl,
8+
fontconfig,
9+
freetype,
10+
lib,
11+
libGL,
12+
libxkbcommon,
13+
makeDesktopItem,
14+
makeWrapper,
15+
stdenvNoCC,
16+
unzip,
17+
writeShellApplication,
18+
xorg,
19+
zlib,
20+
metaCommon ? { },
21+
}:
22+
23+
stdenvNoCC.mkDerivation (finalAttrs: {
24+
inherit pname version;
25+
26+
src = fetchurl {
27+
name = "WinBox_Linux-${finalAttrs.version}.zip";
28+
url = "https://download.mikrotik.com/routeros/winbox/${finalAttrs.version}/WinBox_Linux.zip";
29+
inherit hash;
30+
};
31+
32+
sourceRoot = ".";
33+
34+
nativeBuildInputs = [
35+
autoPatchelfHook
36+
copyDesktopItems
37+
# makeBinaryWrapper does not support --run
38+
makeWrapper
39+
unzip
40+
];
41+
42+
buildInputs = [
43+
fontconfig
44+
freetype
45+
libGL
46+
libxkbcommon
47+
xorg.libxcb
48+
xorg.xcbutilimage
49+
xorg.xcbutilkeysyms
50+
xorg.xcbutilrenderutil
51+
xorg.xcbutilwm
52+
zlib
53+
];
54+
55+
installPhase = ''
56+
runHook preInstall
57+
58+
install -Dm644 "assets/img/winbox.png" "$out/share/pixmaps/winbox.png"
59+
install -Dm755 "WinBox" "$out/bin/WinBox"
60+
61+
wrapProgram "$out/bin/WinBox" --run "${lib.getExe finalAttrs.migrationScript}"
62+
63+
runHook postInstall
64+
'';
65+
66+
desktopItems = [
67+
(makeDesktopItem {
68+
name = "winbox";
69+
desktopName = "WinBox";
70+
comment = "GUI administration for Mikrotik RouterOS";
71+
exec = "WinBox";
72+
icon = "winbox";
73+
categories = [ "Utility" ];
74+
})
75+
];
76+
77+
migrationScript = writeShellApplication {
78+
name = "winbox-migrate";
79+
text = ''
80+
XDG_DATA_HOME=''${XDG_DATA_HOME:-$HOME/.local/share}
81+
targetFile="$XDG_DATA_HOME/MikroTik/WinBox/Addresses.cdb"
82+
83+
if [ -f "$targetFile" ]; then
84+
echo "NixOS: WinBox 4 data already present at $(dirname "$targetFile"). Skipping automatic migration."
85+
exit 0
86+
fi
87+
88+
# cover both wine prefix variants
89+
# latter was used until https://github.com/NixOS/nixpkgs/pull/329626 was merged on 2024/07/24
90+
winePrefixes=(
91+
"''${WINEPREFIX:-$HOME/.wine}"
92+
"''${WINBOX_HOME:-$XDG_DATA_HOME/winbox}/wine"
93+
)
94+
sourceFilePathSuffix="drive_c/users/$USER/AppData/Roaming/Mikrotik/Winbox/Addresses.cdb"
95+
selectedSourceFile=""
96+
97+
for prefix in "''${winePrefixes[@]}"
98+
do
99+
echo "NixOS: Probing WinBox 3 data path at $prefix..."
100+
if [ -f "$prefix/$sourceFilePathSuffix" ]; then
101+
selectedSourceFile="$prefix/$sourceFilePathSuffix"
102+
break
103+
fi
104+
done
105+
106+
if [ -z "$selectedSourceFile" ]; then
107+
echo "NixOS: WinBox 3 data not found. Skipping automatic migration."
108+
exit 0
109+
fi
110+
111+
echo "NixOS: Automatically migrating WinBox 3 data..."
112+
install -Dvm644 "$selectedSourceFile" "$targetFile"
113+
'';
114+
};
115+
116+
meta = metaCommon // {
117+
platforms = [ "x86_64-linux" ];
118+
};
119+
})
Lines changed: 21 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,128 +1,41 @@
11
{
2-
autoPatchelfHook,
3-
copyDesktopItems,
4-
fetchurl,
5-
fontconfig,
6-
freetype,
72
lib,
8-
libGL,
9-
libxkbcommon,
10-
makeDesktopItem,
11-
makeWrapper,
3+
callPackage,
124
stdenvNoCC,
13-
unzip,
14-
writeShellApplication,
15-
xorg,
16-
zlib,
175
}:
18-
19-
stdenvNoCC.mkDerivation (finalAttrs: {
6+
let
207
pname = "winbox";
218
version = "4.0beta20";
229

23-
src = fetchurl {
24-
name = "WinBox_Linux-${finalAttrs.version}.zip";
25-
url = "https://download.mikrotik.com/routeros/winbox/${finalAttrs.version}/WinBox_Linux.zip";
26-
hash = "sha256-mU+z7yRYKXnGAXHB5LS5SVUgIzRlR9nV2FzXispntF0=";
27-
};
28-
29-
sourceRoot = ".";
30-
31-
nativeBuildInputs = [
32-
autoPatchelfHook
33-
copyDesktopItems
34-
# makeBinaryWrapper does not support --run
35-
makeWrapper
36-
unzip
37-
];
38-
39-
buildInputs = [
40-
fontconfig
41-
freetype
42-
libGL
43-
libxkbcommon
44-
xorg.libxcb
45-
xorg.xcbutilimage
46-
xorg.xcbutilkeysyms
47-
xorg.xcbutilrenderutil
48-
xorg.xcbutilwm
49-
zlib
50-
];
51-
52-
installPhase = ''
53-
runHook preInstall
54-
55-
install -Dm644 "assets/img/winbox.png" "$out/share/pixmaps/winbox.png"
56-
install -Dm755 "WinBox" "$out/bin/WinBox"
57-
58-
wrapProgram "$out/bin/WinBox" --run "${lib.getExe finalAttrs.migrationScript}"
59-
60-
runHook postInstall
61-
'';
62-
63-
desktopItems = [
64-
(makeDesktopItem {
65-
name = "winbox";
66-
desktopName = "Winbox";
67-
comment = "GUI administration for Mikrotik RouterOS";
68-
exec = "WinBox";
69-
icon = "winbox";
70-
categories = [ "Utility" ];
71-
})
72-
];
73-
74-
migrationScript = writeShellApplication {
75-
name = "winbox-migrate";
76-
text = ''
77-
XDG_DATA_HOME=''${XDG_DATA_HOME:-$HOME/.local/share}
78-
targetFile="$XDG_DATA_HOME/MikroTik/WinBox/Addresses.cdb"
79-
80-
if [ -f "$targetFile" ]; then
81-
echo "NixOS: WinBox 4 data already present at $(dirname "$targetFile"). Skipping automatic migration."
82-
exit 0
83-
fi
84-
85-
# cover both wine prefix variants
86-
# latter was used until https://github.com/NixOS/nixpkgs/pull/329626 was merged on 2024/07/24
87-
winePrefixes=(
88-
"''${WINEPREFIX:-$HOME/.wine}"
89-
"''${WINBOX_HOME:-$XDG_DATA_HOME/winbox}/wine"
90-
)
91-
sourceFilePathSuffix="drive_c/users/$USER/AppData/Roaming/Mikrotik/Winbox/Addresses.cdb"
92-
selectedSourceFile=""
93-
94-
for prefix in "''${winePrefixes[@]}"
95-
do
96-
echo "NixOS: Probing WinBox 3 data path at $prefix..."
97-
if [ -f "$prefix/$sourceFilePathSuffix" ]; then
98-
selectedSourceFile="$prefix/$sourceFilePathSuffix"
99-
break
100-
fi
101-
done
102-
103-
if [ -z "$selectedSourceFile" ]; then
104-
echo "NixOS: WinBox 3 data not found. Skipping automatic migration."
105-
exit 0
106-
fi
107-
108-
echo "NixOS: Automatically migrating WinBox 3 data..."
109-
install -Dvm644 "$selectedSourceFile" "$targetFile"
110-
'';
111-
};
112-
113-
meta = {
10+
metaCommon = {
11411
description = "Graphical configuration utility for RouterOS-based devices";
11512
homepage = "https://mikrotik.com";
11613
downloadPage = "https://mikrotik.com/download";
117-
changelog = "https://download.mikrotik.com/routeros/winbox/${finalAttrs.version}/CHANGELOG";
11814
sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
11915
license = lib.licenses.unfree;
120-
platforms = [ "x86_64-linux" ];
12116
mainProgram = "WinBox";
12217
maintainers = with lib.maintainers; [
12318
Scrumplex
12419
yrd
12520
savalet
12621
];
12722
};
23+
x86_64-zip = callPackage ./build-from-zip.nix {
24+
inherit pname version metaCommon;
25+
26+
hash = "sha256-mU+z7yRYKXnGAXHB5LS5SVUgIzRlR9nV2FzXispntF0=";
27+
};
28+
29+
x86_64-dmg = callPackage ./build-from-dmg.nix {
30+
inherit pname version metaCommon;
31+
32+
hash = "sha256-tLsreK6YsqsbMaY4dil34eiHxAG7GrZYyll6BX9dsx8=";
33+
};
34+
in
35+
(if stdenvNoCC.hostPlatform.isDarwin then x86_64-dmg else x86_64-zip).overrideAttrs (oldAttrs: {
36+
meta = oldAttrs.meta // {
37+
platforms = x86_64-zip.meta.platforms ++ x86_64-dmg.meta.platforms;
38+
mainProgram = "WinBox";
39+
changelog = "https://download.mikrotik.com/routeros/winbox/${oldAttrs.version}/CHANGELOG";
40+
};
12841
})

0 commit comments

Comments
 (0)