@@ -0,0 +1,61 @@
1+{ lib
2+, fetchFromGitHub
3+, buildPythonPackage
4+, pythonOlder
5+, smbus-cffi
6+, urwid
7+}:
8+
9+buildPythonPackage rec {
10+ pname = "pijuice";
11+ version = "1.7";
12+ disabled = pythonOlder "3.6";
13+
14+ src = fetchFromGitHub {
15+ owner = "PiSupply";
16+ repo = "PiJuice";
17+ # rev hash retrieved from the latest modification on file Software/Source/VERSION, as this project
18+ # does not use Github tags facility
19+ rev = "3ba6719ab614a3dc7495d5d9c900dd4ea977c7e3";
20+ sha256 = "GoNN07YgVaktpeY5iYDbfpy5fxkU1x0V3Sb1hgGAQt4=";
21+ };
22+
23+ patches = [
24+ # The pijuice_cli.cli file doesn't have a shebang as the first line of the
25+ # script. Without it, the pythonWrapPrograms hook will not wrap the program.
26+ # Add a python shebang here so that the the hook is triggered.
27+ ./patch-shebang.diff
28+ ];
29+
30+ PIJUICE_BUILD_BASE = 1;
31+
32+ preBuild = ''
33+ cd Software/Source
34+ '';
35+
36+ propagatedBuildInputs = [ smbus-cffi urwid ];
37+
38+ # Remove the following files from the package:
39+ #
40+ # pijuice_cli - A precompiled ELF binary that is a setuid wrapper for calling
41+ # pijuice_cli.py
42+ #
43+ # pijuiceboot - a precompiled ELF binary for flashing firmware. Not needed for
44+ # the python library.
45+ #
46+ # pijuice_sys.py - A program that acts as a system daemon for monitoring the
47+ # pijuice.
48+ preFixup = ''
49+ rm $out/bin/pijuice_cli
50+ rm $out/bin/pijuice_sys.py
51+ rm $out/bin/pijuiceboot
52+ mv $out/bin/pijuice_cli.py $out/bin/pijuice_cli
53+ '';
54+
55+ meta = with lib; {
56+ description = "Library and resources for PiJuice HAT for Raspberry Pi";
57+ homepage = "https://github.com/PiSupply/PiJuice";
58+ license = licenses.gpl3Plus;
59+ maintainers = with maintainers; [ hexagonal-sun ];
60+ };
61+}