nheko/devenv.nix
2026-03-11 00:44:53 +02:00

129 lines
3.1 KiB
Nix

{ pkgs, lib, config, inputs, ... }:
let
qtPackages = with pkgs.qt6Packages; [
qtbase
qtdeclarative
qtimageformats
qtkeychain
qtmultimedia
qtsvg
qttools
qtwayland
qt-jdenticon
];
gstreamerPackages = [
pkgs.gst_all_1.gstreamer
pkgs.gst_all_1.gst-plugins-base
(pkgs.gst_all_1.gst-plugins-good.override { qt6Support = true; })
pkgs.gst_all_1.gst-plugins-bad
];
cmakePackages = [
pkgs.cmark
pkgs.coeurl
pkgs.curl
pkgs.kdsingleapplication
pkgs.libevent
pkgs.libsecret
pkgs.lmdb
pkgs.lmdbxx
pkgs.mtxclient
pkgs.nlohmann_json
pkgs.olm
pkgs.re2
pkgs.spdlog
] ++ qtPackages ++ gstreamerPackages ++ [ pkgs.libnice ];
runtimePackages = [
pkgs.pipewire
];
qtPluginPath = lib.makeSearchPath "lib/qt-6/plugins" qtPackages;
qmlImportPath = lib.makeSearchPath "lib/qt-6/qml" qtPackages;
gstreamerPluginPath = lib.makeSearchPath "lib/gstreamer-1.0" gstreamerPackages;
runtimeLibraryPath = lib.makeLibraryPath runtimePackages;
cmakePrefixPath =
lib.concatStringsSep ":" (
(map (pkg: "${lib.getDev pkg}/lib/cmake") cmakePackages)
++ (map (pkg: "${lib.getDev pkg}") cmakePackages)
);
in
{
packages = [
pkgs.asciidoc
pkgs.cmake
pkgs.direnv
pkgs.gcc
pkgs.git
pkgs.gnumake
pkgs.gdb
pkgs.ninja
pkgs.pkg-config
pkgs.pipewire
pkgs.qt6Packages.wrapQtAppsHook
] ++ cmakePackages;
env = {
CMAKE_GENERATOR = "Ninja";
CMAKE_PREFIX_PATH = cmakePrefixPath;
GST_PLUGIN_SYSTEM_PATH_1_0 = gstreamerPluginPath;
LD_LIBRARY_PATH = runtimeLibraryPath;
NHEKO_BUILD_DIR = "build";
QT_PLUGIN_PATH = qtPluginPath;
QML2_IMPORT_PATH = qmlImportPath;
};
scripts."configure-nheko".exec = ''
cmake -S . -B "$NHEKO_BUILD_DIR" \
-G "$CMAKE_GENERATOR" \
-DCMAKE_BUILD_TYPE="''${CMAKE_BUILD_TYPE:-RelWithDebInfo}" \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
'';
scripts."build-nheko".exec = ''
if [ ! -f "$NHEKO_BUILD_DIR/CMakeCache.txt" ]; then
configure-nheko
fi
cmake --build "$NHEKO_BUILD_DIR" --parallel "''${NIX_BUILD_CORES:-$(nproc)}"
'';
scripts."test-nheko".exec = ''
build-nheko
ctest --test-dir "$NHEKO_BUILD_DIR" --output-on-failure
binary="$(find "$NHEKO_BUILD_DIR" -maxdepth 4 -type f -name nheko -executable | head -n 1)"
if [ -z "$binary" ]; then
echo "Unable to locate the built nheko binary under $NHEKO_BUILD_DIR" >&2
exit 1
fi
QT_QPA_PLATFORM=offscreen "$binary" --help >/dev/null
'';
scripts."run-nheko".exec = ''
build-nheko
binary="$(find "$NHEKO_BUILD_DIR" -maxdepth 4 -type f -name nheko -executable | head -n 1)"
if [ -z "$binary" ]; then
echo "Unable to locate the built nheko binary under $NHEKO_BUILD_DIR" >&2
exit 1
fi
exec "$binary" "$@"
'';
enterShell = ''
echo "nheko devenv ready"
echo " configure-nheko Configure the CMake build tree"
echo " build-nheko Build the nheko binary"
echo " test-nheko Run ctest and a headless --help smoke test"
echo " run-nheko Launch the built client"
'';
enterTest = ''
test-nheko
'';
}