Packaging the lgpio Python package

Hi,

I am trying to package the lgpio Python package (Linux-native GPIO access without board specifics).

The Input

This is my python-lgpio.nix:

{ lib, python3Packages, fetchPypi, swig, ... }:

with python3Packages;
buildPythonPackage rec {
  pname = "lgpio";
  version = "0.2.2.0";
  format = "setuptools";

  src = fetchPypi {
    pname = pname;
    inherit version;
    hash = "sha256-ETcuZTsgD3ags++KI6BzXIXsZ4qfhVC5iTFR7Q+GP/8=";
  };

  nativeBuildInputs = [ setuptools swig ];

  meta = with lib; {
    homepage = "http://abyz.me.uk/lg/py_lgpio.html";
    description = "Linux SBC GPIO module";
    license = licenses.unlicense;
    platforms = platforms.linux;
    maintainers = with maintainers; [ ];
  };
}

When I build it with nix-build -E 'with import <nixpkgs> {}; callPackage ./python-lgpio.nix {}', this weird error appears:

The Error

this derivation will be built:
  /nix/store/rwaypmw3zqvn8zqdc8mqz9bxf3zxi65w-python3.11-lgpio-0.2.2.0.drv
building '/nix/store/rwaypmw3zqvn8zqdc8mqz9bxf3zxi65w-python3.11-lgpio-0.2.2.0.drv'...
Sourcing python-remove-tests-dir-hook
Sourcing python-catch-conflicts-hook.sh
Sourcing python-remove-bin-bytecode-hook.sh
Sourcing setuptools-build-hook
Using setuptoolsBuildPhase
Sourcing pypa-install-hook
Using pypaInstallPhase
Sourcing python-imports-check-hook.sh
Using pythonImportsCheckPhase
Sourcing python-namespaces-hook
Sourcing python-catch-conflicts-hook.sh
Sourcing setuptools-check-hook
Using setuptoolsCheckPhase
Running phase: unpackPhase
unpacking source archive /nix/store/nd3r7gb84apmg9a70hrpbzzxzqjv6ymd-lgpio-0.2.2.0.tar.gz
source root is lgpio-0.2.2.0
setting SOURCE_DATE_EPOCH to timestamp 1711661664 of file lgpio-0.2.2.0/setup.cfg
Running phase: patchPhase
Running phase: updateAutotoolsGnuConfigScriptsPhase
Running phase: configurePhase
no configure script, doing nothing
Running phase: buildPhase
Executing setuptoolsBuildPhase
running bdist_wheel
running build
running build_py
running build_ext
building '_lgpio' extension
swigging lgpio.i to lgpio_wrap.c
swig -python -o lgpio_wrap.c lgpio.i
creating build
creating build/temp.linux-x86_64-cpython-311
gcc -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -I/nix/store/lq64w720ci2l6xsavbvm85kal6kzdxq2-libxcrypt-4.4.36/include -fPIC -Isrc -I/nix/store/4rf5qybw37b4lh1g0xczlv14sqdbmnpm-python3-3.11.9/include/python3.11 -c lgpio_wrap.c -o build/temp.linux-x86_64-cpython-311/lgpio_wrap.o
lgpio_wrap.c: In function ‘PyInit__lgpio’:
lgpio_wrap.c:6773:15: warning: ‘__builtin___strncpy_chk’ output truncated before terminating nul copying 10 bytes from a string of the same length [8;;https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wstringop-truncation-Wstringop-truncation8;;]
 6773 |               strncpy(buff, "swig_ptr: ", 10);
      |               ^
creating build/lib.linux-x86_64-cpython-311
gcc -shared -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-bzip2-1.0.8/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-expat-2.6.2/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-libffi-3.4.6/lib -L/nix/store/lq64w720ci2l6xsavbvm85kal6kzdxq2-libxcrypt-4.4.36/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-mpdecimal-4.0.0/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-ncurses-6.4/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-openssl-3.0.14/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-sqlite-3.45.3/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-xz-5.4.7/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-zlib-1.3.1/lib -L/nix/store/jyh52p2cxrjn8r4ywdv2am5pjkj1xcqa-tzdata-2024a/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-gdbm-1.23/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-readline-8.2p10/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-bzip2-1.0.8/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-expat-2.6.2/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-libffi-3.4.6/lib -L/nix/store/lq64w720ci2l6xsavbvm85kal6kzdxq2-libxcrypt-4.4.36/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-mpdecimal-4.0.0/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-ncurses-6.4/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-openssl-3.0.14/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-sqlite-3.45.3/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-xz-5.4.7/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-zlib-1.3.1/lib -L/nix/store/jyh52p2cxrjn8r4ywdv2am5pjkj1xcqa-tzdata-2024a/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-gdbm-1.23/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-readline-8.2p10/lib build/temp.linux-x86_64-cpython-311/lgpio_wrap.o -L/nix/store/4rf5qybw37b4lh1g0xczlv14sqdbmnpm-python3-3.11.9/lib -llgpio -o build/lib.linux-x86_64-cpython-311/_lgpio.cpython-311-x86_64-linux-gnu.so
/nix/store/7v7g86ml0ri171gfcrs1d442px5bi1p3-binutils-2.41/bin/ld: cannot find -llgpio: No such file or directory
collect2: error: ld returned 1 exit status
error: command '/nix/store/r73z9i18vbjcph7k2f3isrysxzx6sqjx-gcc-wrapper-13.2.0/bin/gcc' failed with exit code 1
/nix/store/dd7nxjnni7nzm0846fq5xrm89ais5lwz-stdenv-linux/setup: line 1579: pop_var_context: head of shell_variables not a function context
error: builder for '/nix/store/rwaypmw3zqvn8zqdc8mqz9bxf3zxi65w-python3.11-lgpio-0.2.2.0.drv' failed with exit code 1;
       last 10 log lines:
       > lgpio_wrap.c: In function ‘PyInit__lgpio’:
       > lgpio_wrap.c:6773:15: warning: ‘__builtin___strncpy_chk’ output truncated before terminating nul copying 10 bytes from a string of the same length [8;;https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wstringop-truncation-Wstringop-truncation8;;]
       >  6773 |               strncpy(buff, "swig_ptr: ", 10);
       >       |               ^
       > creating build/lib.linux-x86_64-cpython-311
       > gcc -shared -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-bzip2-1.0.8/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-expat-2.6.2/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-libffi-3.4.6/lib -L/nix/store/lq64w720ci2l6xsavbvm85kal6kzdxq2-libxcrypt-4.4.36/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-mpdecimal-4.0.0/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-ncurses-6.4/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-openssl-3.0.14/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-sqlite-3.45.3/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-xz-5.4.7/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-zlib-1.3.1/lib -L/nix/store/jyh52p2cxrjn8r4ywdv2am5pjkj1xcqa-tzdata-2024a/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-gdbm-1.23/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-readline-8.2p10/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-bzip2-1.0.8/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-expat-2.6.2/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-libffi-3.4.6/lib -L/nix/store/lq64w720ci2l6xsavbvm85kal6kzdxq2-libxcrypt-4.4.36/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-mpdecimal-4.0.0/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-ncurses-6.4/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-openssl-3.0.14/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-sqlite-3.45.3/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-xz-5.4.7/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-zlib-1.3.1/lib -L/nix/store/jyh52p2cxrjn8r4ywdv2am5pjkj1xcqa-tzdata-2024a/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-gdbm-1.23/lib -L/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-readline-8.2p10/lib build/temp.linux-x86_64-cpython-311/lgpio_wrap.o -L/nix/store/4rf5qybw37b4lh1g0xczlv14sqdbmnpm-python3-3.11.9/lib -llgpio -o build/lib.linux-x86_64-cpython-311/_lgpio.cpython-311-x86_64-linux-gnu.so
       > /nix/store/7v7g86ml0ri171gfcrs1d442px5bi1p3-binutils-2.41/bin/ld: cannot find -llgpio: No such file or directory
       > collect2: error: ld returned 1 exit status
       > error: command '/nix/store/r73z9i18vbjcph7k2f3isrysxzx6sqjx-gcc-wrapper-13.2.0/bin/gcc' failed with exit code 1
       > /nix/store/dd7nxjnni7nzm0846fq5xrm89ais5lwz-stdenv-linux/setup: line 1579: pop_var_context: head of shell_variables not a function context
       For full logs, run 'nix log /nix/store/rwaypmw3zqvn8zqdc8mqz9bxf3zxi65w-python3.11-lgpio-0.2.2.0.drv'.

What I don’t understand

  1. What the heck are all these bogus (non-existing) eeeeeeeeeeeeeeeeeee nix store paths? Looks like a sandboxing kind of thing to prevent hard-coding some paths?
  2. It doesn’t find a liblgpio.so apparently - but isn’t it supposed to build that itself?

Further Info

1 Like

Hey! I made already effort to package this at #316936 . You may still encounter kernel related issues as described in issue #122993 .

1 Like