Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Use upstreamed poetry2nix overrides for hid and pyusb
From 96f7801fd773242cb584d68415b6c72b7db1e123 Mon Sep 17 00:00:00 2001
From: Steve Purcell <steve@sanityinc.com>
Date: Tue, 11 May 2021 15:10:45 +1200
Subject: [PATCH] Use upstreamed poetry2nix overrides for hid and pyusb
---
nix/sources.json | 12 ++++++++++++
shell.nix | 32 +++++---------------------------
2 files changed, 17 insertions(+), 27 deletions(-)
diff --git a/nix/sources.json b/nix/sources.json
index 7afca37073..caf5cb7d29 100644
--- a/nix/sources.json
+++ b/nix/sources.json
@@ -22,5 +22,17 @@
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/c0e881852006b132236cbf0301bd1939bb50867e.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
+ },
+ "poetry2nix": {
+ "branch": "master",
+ "description": "Convert poetry projects to nix automagically [maintainer=@adisbladis] ",
+ "homepage": "",
+ "owner": "nix-community",
+ "repo": "poetry2nix",
+ "rev": "2d27d44397242b28c3f0081e0432e4f6c951f3a1",
+ "sha256": "06syfg150r59m4kksj5547b5kwxjxjaif5hiljcq966kb9hxsvmv",
+ "type": "tarball",
+ "url": "https://github.com/nix-community/poetry2nix/archive/2d27d44397242b28c3f0081e0432e4f6c951f3a1.tar.gz",
+ "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
}
}
diff --git a/shell.nix b/shell.nix
index e164b74acf..a04e251b51 100644
--- a/shell.nix
+++ b/shell.nix
@@ -1,39 +1,17 @@
{ avr ? true, arm ? true, teensy ? true }:
let
# We specify sources via Niv: use "niv update nixpkgs" to update nixpkgs, for example.
- sources = import ./nix/sources.nix {};
- pkgs = import sources.nixpkgs {};
+ sources = import ./nix/sources.nix { };
+ pkgs = import sources.nixpkgs { };
+
+ poetry2nix = pkgs.callPackage (import sources.poetry2nix) { };
# Builds the python env based on nix/pyproject.toml and
# nix/poetry.lock Use the "poetry update --lock", "poetry add
# --lock" etc. in the nix folder to adjust the contents of those
# files if the requirements*.txt files change
- pythonEnv = pkgs.poetry2nix.mkPoetryEnv {
+ pythonEnv = poetry2nix.mkPoetryEnv {
projectDir = ./nix;
- overrides = pkgs.poetry2nix.overrides.withDefaults (self: super: {
- hid = super.hid.overridePythonAttrs (old: {
- postPatch =
- ''
- found=
- for name in libhidapi-hidraw libhidapi-libusb libhidapi-iohidmanager libhidapi; do
- full_path=${pkgs.hidapi.out}/lib/$name${pkgs.stdenv.hostPlatform.extensions.sharedLibrary}
- if test -f $full_path; then
- found=t
- sed -i -e "s|'$name\..*'|'$full_path'|" hid/__init__.py
- fi
- done
- test -n "$found" || { echo "ERROR: No known libraries found in ${pkgs.hidapi.out}/lib, please update/fix this build expression."; exit 1; }
- '';
- });
- pyusb = super.pyusb.overridePythonAttrs (old: {
- postPatch =
- ''
- libusb=${pkgs.libusb1.out}/lib/libusb-1.0${pkgs.stdenv.hostPlatform.extensions.sharedLibrary}
- test -f $libusb || { echo "ERROR: $libusb doesn't exist, please update/fix this build expression."; exit 1; }
- sed -i -e "s|find_library=None|find_library=lambda _:\"$libusb\"|" usb/backend/libusb1.py
- '';
- });
- });
};
in
--
2.30.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment