Skip to content

Commit bbf98a2

Browse files
committed
meshtasticd: build from source
1 parent b8ba9f2 commit bbf98a2

File tree

1 file changed

+109
-30
lines changed

1 file changed

+109
-30
lines changed
Lines changed: 109 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,155 @@
11
{
2-
lib,
32
stdenv,
4-
fetchurl,
5-
autoPatchelfHook,
6-
dpkg,
3+
lib,
4+
fetchFromGitHub,
5+
fetchzip,
6+
libarchive,
7+
pkg-config,
8+
platformio-core,
9+
writableTmpDirAsHomeHook,
10+
bluez,
711
i2c-tools,
812
libX11,
913
libgpiod_1,
1014
libinput,
1115
libusb1,
1216
libuv,
1317
libxkbcommon,
14-
udevCheckHook,
1518
ulfius,
19+
openssl,
20+
gnutls,
21+
jansson,
22+
zlib,
23+
libmicrohttpd,
24+
orcania,
25+
yder,
1626
yaml-cpp,
27+
udevCheckHook,
28+
versionCheckHook,
29+
makeBinaryWrapper,
30+
python3Packages,
31+
withWeb ? false,
32+
meshtastic-web, # Only used if `withWeb` is set to `true`.
1733
}:
34+
let
35+
version = "2.7.16.a597230";
36+
37+
platformio-deps-native = fetchzip {
38+
url = "https://github.com/meshtastic/firmware/releases/download/v${version}/platformio-deps-native-tft-${version}.zip";
39+
hash = "sha256-Jo7e6zsCaiJs6NyIRmD6BWJFwbs0xVlUih206ePUpwk=";
40+
};
41+
in
1842
stdenv.mkDerivation (finalAttrs: {
1943
pname = "meshtasticd";
20-
version = "2.6.11.25";
44+
inherit version;
2145

22-
src = fetchurl {
23-
url = "https://download.opensuse.org/repositories/network:/Meshtastic:/beta/Debian_12/amd64/meshtasticd_${finalAttrs.version}~obs60ec05e~beta_amd64.deb";
24-
hash = "sha256-7JCv+1YgsCLwboGE/2f+8iyLLoUsKn3YdJ9Atnfj7Zw=";
46+
src = fetchFromGitHub {
47+
owner = "meshtastic";
48+
repo = "firmware";
49+
hash = "sha256-oU3Z8qjBNeNGPGT74VStAPHgsGqsQJKngHJR6m2CBa0=";
50+
tag = "v${finalAttrs.version}";
51+
fetchSubmodules = true;
2552
};
2653

54+
strictDeps = true;
55+
2756
nativeBuildInputs = [
28-
autoPatchelfHook
29-
dpkg
57+
libarchive
58+
pkg-config
59+
(platformio-core.overridePythonAttrs (oldAttrs: {
60+
dependencies = oldAttrs.dependencies ++ [
61+
python3Packages.grpcio-tools
62+
];
63+
}))
64+
writableTmpDirAsHomeHook
65+
makeBinaryWrapper
3066
];
3167

32-
dontConfigure = true;
33-
dontBuild = true;
34-
35-
strictDeps = true;
36-
3768
buildInputs = [
69+
bluez
70+
gnutls
3871
i2c-tools
72+
jansson
3973
libX11
4074
libgpiod_1
4175
libinput
76+
libmicrohttpd
4277
libusb1
4378
libuv
4479
libxkbcommon
80+
openssl
81+
orcania
4582
ulfius
4683
yaml-cpp
84+
yder
85+
zlib
4786
];
4887

49-
autoPatchelfIgnoreMissingDeps = [
50-
"libyaml-cpp.so.0.7"
51-
];
88+
preConfigure = ''
89+
mkdir -p platformio-deps-native
90+
cp -ar ${platformio-deps-native}/. platformio-deps-native
91+
chmod +w -R platformio-deps-native
92+
93+
export PLATFORMIO_CORE_DIR=platformio-deps-native/core
94+
export PLATFORMIO_LIBDEPS_DIR=platformio-deps-native/libdeps
95+
export PLATFORMIO_PACKAGES_DIR=platformio-deps-native/packages
96+
'';
97+
98+
buildPhase = ''
99+
runHook preBuild
100+
101+
platformio run --environment native-tft
102+
103+
runHook postBuild
104+
'';
52105

53106
installPhase = ''
54107
runHook preInstall
55108
56-
mkdir -p {$out,$out/bin}
57-
cp -r {usr,lib} $out/
109+
install -Dm644 bin/org.meshtastic.meshtasticd.svg -t $out/share/icons/hicolor/scalable/apps/
110+
install -Dm644 bin/org.meshtastic.meshtasticd.desktop -t $out/share/applications/
111+
install -Dm755 .pio/build/native-tft/program $out/bin/meshtasticd
58112
59-
patchelf --replace-needed libyaml-cpp.so.0.7 libyaml-cpp.so.0.8 $out/usr/bin/meshtasticd
113+
wrapProgram $out/bin/meshtasticd \
114+
--add-flags "-c $out/share/meshtasticd/config.yaml"
60115
61-
ln -s $out/usr/bin/meshtasticd $out/bin/meshtasticd
116+
install -Dm644 bin/config-dist.yaml $out/share/meshtasticd/config.yaml
117+
substituteInPlace $out/share/meshtasticd/config.yaml \
118+
--replace-fail "/etc/meshtasticd/config.d" "$out/share/meshtasticd/config.d" \
119+
--replace-fail "/etc/meshtasticd/available.d" "$out/share/meshtasticd/available.d"
120+
''
121+
+ lib.optionalString withWeb ''
122+
substituteInPlace $out/share/meshtasticd/config.yaml \
123+
--replace-fail "/usr/share/meshtasticd/web" "${meshtastic-web}"
124+
''
125+
+ ''
126+
install -d $out/share/meshtasticd/config.d
127+
install -d $out/share/meshtasticd/available.d
62128
63-
substituteInPlace $out/lib/systemd/system/meshtasticd.service \
64-
--replace-fail "/usr/bin/meshtasticd" "$out/bin/meshtasticd" \
65-
--replace-fail 'User=meshtasticd' 'DynamicUser=yes' \
66-
--replace-fail 'Group=meshtasticd' ""
129+
cp -R bin/config.d/* $out/share/meshtasticd/available.d
130+
131+
install -Dm644 bin/config.d/MUI/X11_480x480.yaml $out/share/meshtasticd/config.d/MUI.yaml
132+
133+
install -d $out/share/meshtasticd/maps
134+
135+
for file in pio/libdeps/native-tft/meshtastic-device-ui/maps/*.zip; do
136+
bsdtar -xf "$file" --no-same-owner --strip-components=1 -C $out/share/meshtasticd/maps;
137+
done
138+
139+
install -Dm644 bin/99-meshtasticd-udev.rules -t $out/etc/udev/rules.d
67140
68141
runHook postInstall
69142
'';
70143

71144
doInstallCheck = true;
72-
nativeInstallCheckInputs = [ udevCheckHook ];
145+
nativeInstallCheckInputs = [
146+
udevCheckHook
147+
versionCheckHook
148+
];
149+
versionCheckProgramArg = "--version";
150+
preVersionCheck = ''
151+
version="${lib.versions.major finalAttrs.version}.${lib.versions.minor finalAttrs.version}.${lib.versions.patch finalAttrs.version}"
152+
'';
73153

74154
meta = {
75155
description = "Meshtastic daemon for communicating with Meshtastic devices";
@@ -81,8 +161,7 @@ stdenv.mkDerivation (finalAttrs: {
81161
homepage = "https://github.com/meshtastic/firmware";
82162
mainProgram = "meshtasticd";
83163
license = lib.licenses.gpl3Plus;
84-
platforms = [ "x86_64-linux" ];
85-
sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
164+
platforms = lib.platforms.linux;
86165
maintainers = with lib.maintainers; [ drupol ];
87166
};
88167
})

0 commit comments

Comments
 (0)