Skip to content

Commit 8e203d2

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

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+
(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 -d $out/share/meshtasticd/config.d
110+
install -d $out/share/meshtasticd/available.d
111+
cp -R bin/config.d/* $out/share/meshtasticd/available.d
58112
59-
patchelf --replace-needed libyaml-cpp.so.0.7 libyaml-cpp.so.0.8 $out/usr/bin/meshtasticd
113+
install -Dm644 bin/org.meshtastic.meshtasticd.svg -t $out/share/icons/hicolor/scalable/apps/
114+
install -Dm644 bin/org.meshtastic.meshtasticd.desktop -t $out/share/applications/
115+
install -Dm755 .pio/build/native-tft/program $out/bin/meshtasticd
60116
61-
ln -s $out/usr/bin/meshtasticd $out/bin/meshtasticd
62-
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' ""
117+
install -Dm644 bin/99-meshtasticd-udev.rules -t $out/etc/udev/rules.d
118+
''
119+
+ lib.optionalString withDefaultConfig ''
120+
install -Dm644 bin/config-dist.yaml $out/share/meshtasticd/config.yaml
121+
substituteInPlace $out/share/meshtasticd/config.yaml \
122+
--replace-fail "/etc/meshtasticd/config.d" "$out/share/meshtasticd/config.d" \
123+
--replace-fail "/etc/meshtasticd/available.d" "$out/share/meshtasticd/available.d"
124+
wrapProgram $out/bin/meshtasticd \
125+
--add-flags "-c $out/share/meshtasticd/config.yaml"
126+
install -Dm644 bin/config.d/MUI/X11_480x480.yaml $out/share/meshtasticd/config.d/MUI.yaml
127+
substituteInPlace $out/share/meshtasticd/config.yaml \
128+
--replace-fail "/usr/share/meshtasticd/web" "${meshtastic-web}"
67129
130+
install -d $out/share/meshtasticd/maps
131+
for file in pio/libdeps/native-tft/meshtastic-device-ui/maps/*.zip; do
132+
bsdtar -xf "$file" --no-same-owner --strip-components=1 -C $out/share/meshtasticd/maps;
133+
done
134+
''
135+
+ ''
68136
runHook postInstall
69137
'';
70138

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

74149
meta = {
75150
description = "Meshtastic daemon for communicating with Meshtastic devices";
76151
longDescription = ''
77152
This package has `udev` rules installed as part of the package.
78153
Add `services.udev.packages = [ pkgs.meshtasticd ]` into your NixOS
79154
configuration to enable them.
155+
156+
To enable the default configuration, set the `withDefaultConfig` parameter to true.
157+
158+
To enable the Meshtastic webserver files, set the `withWeb` 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)