Files
control4-knx-presence/flake.nix
T
2026-10-07 23:39:39 +02:00

109 lines
3.1 KiB
Nix

{
description = "c3c-knx-presence development environment";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
# Shared control4-utils library
# sync by running nix lock update control4-utils, then nix run .#sync-utils
control4-utils.url = "git+ssh://git@git.c3c.cz/arnie/nix-config.git?dir=flakes/control4-utils";
control4-utils.inputs.nixpkgs.follows = "nixpkgs";
};
outputs =
{
self,
nixpkgs,
flake-utils,
control4-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"
''}";
};
# Replace src/control4-utils with the shared copy; run from the project root
sync-utils = {
type = "app";
program = "${pkgs.writeShellScript "sync-utils" ''
set -euo pipefail
${control4-utils.apps.${system}.default.program} src
''}";
};
};
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 .
'';
};
}
);
}