push sheeet
Some checks failed
Periodic Merges (6h) / master → staging-nixos (push) Failing after 12m50s
Periodic Merges (6h) / master → staging-next (push) Failing after 12m54s
Periodic Merges (24h) / merge-base(master,staging) → haskell-updates (push) Failing after 11m54s
Periodic Merges (6h) / staging-next → staging (push) Failing after 12m13s
Periodic Merges (24h) / staging-next-25.05 → staging-25.05 (push) Failing after 13m24s
Periodic Merges (24h) / release-25.05 → staging-next-25.05 (push) Failing after 14m28s

This commit is contained in:
Dark Steveneq
2025-10-09 14:15:47 +02:00
commit 646b892680
49168 changed files with 5897842 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
{
stdenv,
usbrelay,
python3,
installShellFiles,
udevCheckHook,
}:
let
python = python3.withPackages (
ps: with ps; [
usbrelay-py
paho-mqtt
]
);
in
# This is a separate derivation, not just an additional output of
# usbrelay, because otherwise, we have a cyclic dependency between
# usbrelay (default.nix) and the python module (python.nix).
stdenv.mkDerivation {
pname = "usbrelayd";
inherit (usbrelay) src version;
postPatch = ''
substituteInPlace 'usbrelayd.service' \
--replace '/usr/bin/python3' "${python}/bin/python3" \
--replace '/usr/sbin/usbrelayd' "$out/bin/usbrelayd"
'';
nativeBuildInputs = [
installShellFiles
udevCheckHook
];
buildInputs = [ python ];
dontBuild = true;
doInstallCheck = true;
installPhase = ''
runHook preInstall;
install -m 644 -D usbrelayd $out/bin/usbrelayd
install -m 644 -D usbrelayd.service $out/lib/systemd/system/usbrelayd.service
install -m 644 -D 50-usbrelay.rules $out/lib/udev/rules.d/50-usbrelay.rules
install -m 644 -D usbrelayd.conf $out/etc/usbrelayd.conf # include this as an example
installManPage usbrelayd.8
runHook postInstall
'';
meta = {
description = "USB Relay MQTT service";
inherit (usbrelay.meta)
homepage
license
maintainers
platforms
;
};
}

View File

@@ -0,0 +1,45 @@
{
stdenv,
lib,
fetchFromGitHub,
hidapi,
installShellFiles,
}:
stdenv.mkDerivation (finalAttrs: {
pname = "usbrelay";
version = "1.2.1";
src = fetchFromGitHub {
owner = "darrylb123";
repo = "usbrelay";
rev = finalAttrs.version;
sha256 = "sha256-9jEiMmBEpqY4+nKh3H8N/JrLohp/7oPK3rPmRjp2gvc=";
};
nativeBuildInputs = [
installShellFiles
];
buildInputs = [
hidapi
];
makeFlags = [
"DIR_VERSION=${finalAttrs.version}"
"PREFIX=${placeholder "out"}"
"LDCONFIG=${stdenv.cc.libc.bin}/bin/ldconfig"
];
postInstall = ''
installManPage usbrelay.1
'';
meta = with lib; {
description = "Tool to control USB HID relays";
mainProgram = "usbrelay";
homepage = "https://github.com/darrylb123/usbrelay";
license = licenses.gpl2Plus;
maintainers = with maintainers; [ wentasah ];
platforms = platforms.linux;
};
})

View File

@@ -0,0 +1,17 @@
{ buildPythonPackage, usbrelay }:
buildPythonPackage {
format = "setuptools";
pname = "usbrelay_py";
inherit (usbrelay) version src;
preConfigure = ''
cd usbrelay_py
'';
buildInputs = [ usbrelay ];
pythonImportsCheck = [ "usbrelay_py" ];
inherit (usbrelay) meta;
}

View File

@@ -0,0 +1,69 @@
# NixOS test for usbrelayd
#
# It is not stored in nixos/tests directory, because it requires the
# USB relay connected to the host computer and as such, it cannot be
# run automatically.
#
# Run this test as:
#
# nix-build test.nix -A driverInteractive && ./result/bin/nixos-test-driver --no-interactive
#
# The interactive driver is required because the default
# (non-interactive) driver uses qemu without support for passing USB
# devices to the guest (see
# https://discourse.nixos.org/t/hardware-dependent-nixos-tests/18564
# for discussion of other alternatives).
import ../../../../nixos/tests/make-test-python.nix (
{ pkgs, ... }:
{
name = "usbrelayd";
nodes.machine = {
virtualisation.qemu.options = [
"-device qemu-xhci"
"-device usb-host,vendorid=0x16c0,productid=0x05df"
];
services.usbrelayd.enable = true;
systemd.services.usbrelayd = {
after = [ "mosquitto.service" ];
};
services.mosquitto = {
enable = true;
listeners = [
{
acl = [ "pattern readwrite #" ];
omitPasswordAuth = true;
settings.allow_anonymous = true;
}
];
};
environment.systemPackages = [
pkgs.usbrelay
pkgs.mosquitto
];
documentation.nixos.enable = false; # building nixos manual takes long time
};
testScript = ''
import os
if os.waitstatus_to_exitcode(os.system("lsusb -d 16c0:05df")) != 0:
print("No USB relay detected, skipping test")
import sys
sys.exit(2)
machine.start()
# usbrelayd is started by udev when an relay is detected
machine.wait_for_unit("usbrelayd.service")
stdout = machine.succeed("usbrelay")
relay_id = stdout.split(sep="_")[0]
assert relay_id != ""
import time
time.sleep(1)
machine.succeed(f"mosquitto_pub -h localhost -t cmnd/{relay_id}/1 -m ON")
time.sleep(1)
machine.succeed(f"mosquitto_pub -h localhost -t cmnd/{relay_id}/1 -m OFF")
print("Did you see the relay switching on and off?")
'';
}
)