Files
control4-knx-presence/flake.nix
T
2026-07-06 23:21:42 +02:00

93 lines
2.4 KiB
Nix

{
description = "c3c-knx-presence development environment";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs =
{
self,
nixpkgs,
flake-utils,
}:
let
version = "0.0.1";
gitRev = self.shortRev or self.dirtyShortRev;
driverName = "c3c-knx-presence";
in
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
formatter = pkgs.nixfmt-rfc-style;
devShells.default = pkgs.mkShell {
packages = with pkgs; [
luajit
zip
unzip
libxml2
];
shellHook = ''
echo "${driverName} dev shell"
echo " build build .c4z into working dir"
'';
};
apps.default = {
type = "app";
program = "${pkgs.writeShellScript "build-c4z" ''
set -euo pipefail
nix build
# Move the file into a predefined directory mounted in the Composer Pro environment
rm -f ../compiled/${driverName}.c4z
cp -L result/${driverName}.c4z ../compiled
echo "Built ${gitRev}: ../compiled/${driverName}.c4z"
''}";
};
packages.default = pkgs.stdenv.mkDerivation {
pname = driverName;
inherit version;
src = ./.;
nativeBuildInputs = [
pkgs.libxml2
pkgs.luajit
pkgs.zip
];
buildPhase = ''
# Prepare build dir
cp -r src build-src
${pkgs.lowdown}/bin/lowdown -s README.md > build-src/www/documentation.html
# Validate Lua syntax (compile-check only; driver.lua calls into the
# real Control4 "C4" global at load time, so it cannot be executed here)
cd build-src
luajit -e "assert(loadfile('driver.lua'))"
cd -
# Validate driver manifest
xmllint --noout build-src/driver.xml
# Stamp git rev into driver.lua
( ${pkgs.gnused}/bin/sed -i 's/DRIVER_VERSION = "uninitialized"/DRIVER_VERSION = "${gitRev}"/' build-src/driver.lua)
'';
installPhase = ''
mkdir -p $out
cd build-src
zip -rq $out/${driverName}.c4z .
'';
};
}
);
}