1{
2 lib,
3 fetchFromGitHub,
4 buildPythonPackage,
5 pythonOlder,
6 smbus-cffi,
7 urwid,
8}:
9
10buildPythonPackage rec {
11 pname = "pijuice";
12 version = "1.7";
13 format = "setuptools";
14 disabled = pythonOlder "3.6";
15
16 src = fetchFromGitHub {
17 owner = "PiSupply";
18 repo = "PiJuice";
19 # Latest commit that fixes using the library against python 3.9 by renaming
20 # isAlive() to is_alive(). The former function was removed in python 3.9.
21 rev = "e2dca1f8dcfa12e009952a882c0674a545d193d6";
22 sha256 = "07Jr7RSjqI8j0tT0MNAjrN1sjF1+mI+V0vtKInvtxj8=";
23 };
24
25 patches = [
26 # The pijuice_cli.cli file doesn't have a shebang as the first line of the
27 # script. Without it, the pythonWrapPrograms hook will not wrap the program.
28 # Add a python shebang here so that the the hook is triggered.
29 ./patch-shebang.diff
30 ];
31
32 PIJUICE_BUILD_BASE = 1;
33 PIJUICE_VERSION = version;
34
35 preBuild = ''
36 cd Software/Source
37 '';
38
39 propagatedBuildInputs = [
40 smbus-cffi
41 urwid
42 ];
43
44 # Remove the following files from the package:
45 #
46 # pijuice_cli - A precompiled ELF binary that is a setuid wrapper for calling
47 # pijuice_cli.py
48 #
49 # pijuiceboot - a precompiled ELF binary for flashing firmware. Not needed for
50 # the python library.
51 #
52 # pijuice_sys.py - A program that acts as a system daemon for monitoring the
53 # pijuice.
54 preFixup = ''
55 rm $out/bin/pijuice_cli
56 rm $out/bin/pijuice_sys.py
57 rm $out/bin/pijuiceboot
58 mv $out/bin/pijuice_cli.py $out/bin/pijuice_cli
59 '';
60
61 # no tests
62 doCheck = false;
63
64 meta = with lib; {
65 description = "Library and resources for PiJuice HAT for Raspberry Pi";
66 mainProgram = "pijuice_cli";
67 homepage = "https://github.com/PiSupply/PiJuice";
68 license = licenses.gpl3Plus;
69 maintainers = with maintainers; [ hexagonal-sun ];
70 };
71}