Skip to content

Commit c7da5e7

Browse files
committed
meshtasticd: build from source
1 parent a54a517 commit c7da5e7

File tree

1 file changed

+109
-31
lines changed

1 file changed

+109
-31
lines changed
Lines changed: 109 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,166 @@
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+
withDefaultConfig ? false,
32+
meshtastic-web, # Only used if `withDefaultConfig` 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+
# This has been advised by the Meshtastic's developer.
60+
# Without it, it will try to install grpcio-tools by itself and fail.
61+
(platformio-core.overridePythonAttrs (oldAttrs: {
62+
dependencies = oldAttrs.dependencies ++ [
63+
python3Packages.grpcio-tools
64+
];
65+
}))
66+
writableTmpDirAsHomeHook
67+
makeBinaryWrapper
3068
];
3169

32-
dontConfigure = true;
33-
dontBuild = true;
34-
35-
strictDeps = true;
36-
3770
buildInputs = [
71+
bluez
72+
gnutls
3873
i2c-tools
74+
jansson
3975
libX11
4076
libgpiod_1
4177
libinput
78+
libmicrohttpd
4279
libusb1
4380
libuv
4481
libxkbcommon
82+
openssl
83+
orcania
4584
ulfius
4685
yaml-cpp
86+
yder
87+
zlib
4788
];
4889

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

53108
installPhase = ''
54109
runHook preInstall
55110
56-
mkdir -p {$out,$out/bin}
57-
cp -r {usr,lib} $out/
58-
59-
patchelf --replace-needed libyaml-cpp.so.0.7 libyaml-cpp.so.0.8 $out/usr/bin/meshtasticd
111+
install -d $out/share/meshtasticd/config.d
112+
install -d $out/share/meshtasticd/available.d
113+
cp -R bin/config.d/* $out/share/meshtasticd/available.d
60114
61-
ln -s $out/usr/bin/meshtasticd $out/bin/meshtasticd
115+
install -Dm644 bin/org.meshtastic.meshtasticd.svg -t $out/share/icons/hicolor/scalable/apps/
116+
install -Dm644 bin/org.meshtastic.meshtasticd.desktop -t $out/share/applications/
117+
install -Dm755 .pio/build/native-tft/program $out/bin/meshtasticd
62118
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' ""
119+
install -Dm644 bin/99-meshtasticd-udev.rules -t $out/etc/udev/rules.d
120+
''
121+
+ lib.optionalString withDefaultConfig ''
122+
install -Dm644 bin/config-dist.yaml $out/share/meshtasticd/config.yaml
123+
substituteInPlace $out/share/meshtasticd/config.yaml \
124+
--replace-fail "/etc/meshtasticd/config.d" "$out/share/meshtasticd/config.d" \
125+
--replace-fail "/etc/meshtasticd/available.d" "$out/share/meshtasticd/available.d"
126+
wrapProgram $out/bin/meshtasticd \
127+
--add-flags "-c $out/share/meshtasticd/config.yaml"
128+
install -Dm644 bin/config.d/MUI/X11_480x480.yaml $out/share/meshtasticd/config.d/MUI.yaml
129+
substituteInPlace $out/share/meshtasticd/config.yaml \
130+
--replace-fail "/usr/share/meshtasticd/web" "${meshtastic-web}"
67131
132+
install -d $out/share/meshtasticd/maps
133+
for file in pio/libdeps/native-tft/meshtastic-device-ui/maps/*.zip; do
134+
bsdtar -xf "$file" --no-same-owner --strip-components=1 -C $out/share/meshtasticd/maps;
135+
done
136+
''
137+
+ ''
68138
runHook postInstall
69139
'';
70140

71141
doInstallCheck = true;
72-
nativeInstallCheckInputs = [ udevCheckHook ];
142+
nativeInstallCheckInputs = [
143+
udevCheckHook
144+
versionCheckHook
145+
];
146+
versionCheckProgramArg = "--version";
147+
preVersionCheck = ''
148+
version="${lib.versions.major finalAttrs.version}.${lib.versions.minor finalAttrs.version}.${lib.versions.patch finalAttrs.version}"
149+
'';
73150

74151
meta = {
75152
description = "Meshtastic daemon for communicating with Meshtastic devices";
76153
longDescription = ''
77154
This package has `udev` rules installed as part of the package.
78155
Add `services.udev.packages = [ pkgs.meshtasticd ]` into your NixOS
79156
configuration to enable them.
157+
158+
To enable the default configuration, set the `withDefaultConfig` parameter to true.
80159
'';
81160
homepage = "https://github.com/meshtastic/firmware";
82161
mainProgram = "meshtasticd";
83162
license = lib.licenses.gpl3Plus;
84-
platforms = [ "x86_64-linux" ];
85-
sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
163+
platforms = lib.platforms.linux;
86164
maintainers = with lib.maintainers; [ drupol ];
87165
};
88166
})

0 commit comments

Comments
 (0)