Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/bitcraze: init, cfclient: init at 2023.6 #346413

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
6 changes: 6 additions & 0 deletions maintainers/maintainer-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22260,6 +22260,12 @@
github = "vbrandl";
githubId = 20639051;
};
vbruegge = {
email = "lina@vanbruegge.de";
github = "vBruegge";
githubId = 113902289;
name = "Lina van Brügge";
};
vcanadi = {
email = "vito.canadi@gmail.com";
github = "vcanadi";
Expand Down
32 changes: 32 additions & 0 deletions nixos/modules/hardware/bitcraze.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
config,
lib,
pkgs,
...
}:

let
cfg = config.hardware.bitcraze;
in
{
options.hardware.bitcraze = {
enable = lib.mkOption {
type = lib.types.bool;
default = false;
description = ''
Bitcraze Crazyflie udev rules and ensure 'plugdev' group exists.
This is a prerequisite to using Bitcraze Crazyflie devices without being root, since Bitcraze Crazyflie USB descriptors will be owned by plugdev through udev.
'';
};
};

config = lib.mkIf cfg.enable {
services.udev.packages = [ pkgs.bitcraze-udev-rules ];
users.groups.plugdev = { };
};

meta.maintainers = with lib.maintainers; [
vbruegge
stargate01
];
}
1 change: 1 addition & 0 deletions nixos/modules/module-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
./config/zram.nix
./hardware/acpilight.nix
./hardware/all-firmware.nix
./hardware/bitcraze.nix
./hardware/bladeRF.nix
./hardware/brillo.nix
./hardware/ckb-next.nix
Expand Down
6 changes: 6 additions & 0 deletions pkgs/by-name/bi/bitcraze-udev-rules/99-bitcraze.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Crazyradio (normal operation)
SUBSYSTEM=="usb", ATTRS{idVendor}=="1915", ATTRS{idProduct}=="7777", MODE="0664", GROUP="plugdev"
# Bootloader
SUBSYSTEM=="usb", ATTRS{idVendor}=="1915", ATTRS{idProduct}=="0101", MODE="0664", GROUP="plugdev"
# Crazyflie (over USB)
SUBSYSTEM=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="5740", MODE="0664", GROUP="plugdev"
31 changes: 31 additions & 0 deletions pkgs/by-name/bi/bitcraze-udev-rules/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
lib,
stdenvNoCC,
fetchurl,
}:

stdenvNoCC.mkDerivation {
pname = "bitcraze-udev-rules";
version = "0.1.23";

dontUnpack = true;

installPhase = ''
runHook preInstall

install -Dm444 ${./99-bitcraze.rules} $out/lib/udev/rules.d/99-bitcraze.rules

runHook postInstall
'';

meta = with lib; {
description = "Udev rules for Bitcraze Crazyflie";
license = licenses.gpl2;
maintainers = with maintainers; [
vbruegge
stargate01
];
platforms = platforms.linux;
homepage = "https://github.com/bitcraze/crazyflie-lib-python/blob/master/docs/installation/usb_permissions.md";
};
}
92 changes: 92 additions & 0 deletions pkgs/development/python-modules/cfclient/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{
lib,
buildPythonPackage,
fetchFromGitHub,
pythonOlder,
cflib,
appdirs,
pyzmq,
pyqtgraph,
pyyaml,
numpy,
vispy,
pyserial,
pyqt6,
pyqt6-sip,
qasync,
packaging,
qtm,
xorg,
wrapQtAppsHook,
pythonRelaxDepsHook,
qt5,
}:

buildPythonPackage rec {
pname = "cfclient";
version = "2023.6";
format = "setuptools";
disabled = pythonOlder "3.7";

src = fetchFromGitHub {
owner = "bitcraze";
repo = "crazyflie-clients-python";
rev = version;
hash = "sha256-QQuULICE/RjhZj3GGeFJ0hFrFJJ9FphQndeqWQCf59A=";
};

postPatch = ''
echo '{"version": "${version}"}' > src/cfclient/version.json
'';

propagatedBuildInputs = [
cflib
appdirs
pyzmq
pyqtgraph
pyyaml
numpy
vispy
pyserial
pyqt6
pyqt6-sip
qasync
packaging
qtm
pyqtgraph
];

buildInputs = [
qt5.qtbase
xorg.libXinerama
];

nativeBuildInputs = [
wrapQtAppsHook
pythonRelaxDepsHook
];

postFixup = ''
wrapQtApp $out/bin/cfclient
'';

pythonRelaxDeps = true;

dontWrapQtApps = true;

pythonImportsCheck = [ "cfclient" ];

doCheck = false;

meta = with lib; {
homepage = "https://github.com/bitcraze/crazyflie-clients-python";
description = "Host applications and library for Crazyflie written in Python";
license = licenses.gpl2;
platforms = platforms.linux;
maintainers = with maintainers; [
vbruegge
stargate01
];
mainProgram = "cfclient";
};
}
78 changes: 78 additions & 0 deletions pkgs/development/python-modules/cflib/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
stdenv,
lib,
buildPythonPackage,
fetchFromGitHub,
libusb-package,
pyusb,
scipy,
numpy,
pytestCheckHook,
pyyaml,
pythonOlder,
bitcraze-udev-rules,
pythonRelaxDepsHook,
}:

buildPythonPackage rec {
pname = "cflib";
version = "0.1.23";
format = "setuptools";
disabled = pythonOlder "3.7";

src = fetchFromGitHub {
owner = "bitcraze";
repo = "crazyflie-lib-python";
rev = version;
hash = "sha256-OZQAisA9b3YIf3zEC5RlrW70h4tgCBC19/KEvle+kLY=";
};

propagatedBuildInputs =
[
pyusb
scipy
numpy
libusb-package
]
++ lib.optionals stdenv.isLinux [
bitcraze-udev-rules
];

nativeBuildInputs = [
pythonRelaxDepsHook
];

pythonRelaxDeps = true;

nativeCheckInputs = [
pytestCheckHook
];

checkInputs = [
pyyaml
];

disabledTestPaths = [
# Disable tests which require a physical device connection
"sys_test/single_cf_grounded/test_bootloader.py"
"sys_test/single_cf_grounded/test_link.py"
"sys_test/single_cf_grounded/test_power_switch.py"
"sys_test/swarm_test_rig/test_connection.py"
"sys_test/swarm_test_rig/test_logging.py"
"sys_test/swarm_test_rig/test_memory_map.py"
"sys_test/swarm_test_rig/test_response_time.py"
];

pythonImportsCheck = [ "cflib" ];

meta = with lib; {
homepage = "https://github.com/bitcraze/crazyflie-lib-python";
description = "Python library to communicate with Crazyflie";
license = licenses.gpl2;
platforms = platforms.linux;
maintainers = with maintainers; [
vbruegge
stargate01
];
};
}
75 changes: 75 additions & 0 deletions pkgs/development/python-modules/libusb-package/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
lib,
buildPythonPackage,
fetchFromGitHub,
libusb1,
pytestCheckHook,
python,
pythonOlder,
setuptools-scm,
importlib-resources,
pyusb,
}:

buildPythonPackage rec {
pname = "libusb-package";
version = "1.0.26.2";
format = "setuptools";
disabled = pythonOlder "3.7";

src = fetchFromGitHub {
owner = "pyocd";
repo = "libusb-package";
rev = "v${version}";
hash = "sha256-bM+v3eeQQHiBKsFky51KdDYlRjFzykQFkuFKkluqkjY=";
};

patches = [ ./fix-pytest.patch ];

# Replace the setup to not build libusb
postPatch = ''
cp -f ${./setup.py} setup.py
'';

SETUPTOOLS_SCM_PRETEND_VERSION = version;
buildInputs = [
setuptools-scm
];

propagatedBuildInputs = [
importlib-resources
];

propagatedNativeBuildInputs = [
libusb1
];

# Symlink the system libusb instead of building it
postInstall = ''
ln -fs "${libusb1}/lib/libusb-1.0.so" "$out/${python.sitePackages}/libusb_package/libusb-1.0.so"
'';

nativeCheckInputs = [
pytestCheckHook
libusb1
];

checkInputs = [
pyusb
];

pytestFlagsArray = [ "test.py" ];

pythonImportsCheck = [ "libusb_package" ];

meta = with lib; {
homepage = "https://github.com/pyocd/libusb-package";
description = "Packaged libusb shared libraries for Python";
license = licenses.asl20;
platforms = platforms.linux;
maintainers = with maintainers; [
vbruegge
stargate01
];
};
}
20 changes: 20 additions & 0 deletions pkgs/development/python-modules/libusb-package/fix-pytest.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
diff --git a/test.py b/test.py
index 93d2603e0440..078246bee35e 100644
--- a/test.py
+++ b/test.py
@@ -5,7 +5,7 @@ import libusb_package
import usb.core
import usb.backend.libusb1

-def main():
+def test_main():
# Test get_library_path().
path = libusb_package.get_library_path()
print(f"Path to included library: {path}")
@@ -29,6 +29,4 @@ def main():
except Exception as err:
print(f"{dev.idVendor:04x}:{dev.idProduct:04x}: error reading strings ({err})")

-if __name__ == "__main__":
- main()

6 changes: 6 additions & 0 deletions pkgs/development/python-modules/libusb-package/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from setuptools import setup

setup(
name='libusb_package',
packages=['libusb_package']
)
Loading