xbows-driver icon indicating copy to clipboard operation
xbows-driver copied to clipboard

Packaging for NixOS

Open peterhoeg opened this issue 4 years ago • 5 comments

In order to make this properly compile on NixOS, I use the following changes:

  1. Build libcrc and hidadpi-supercollider outside of the driver using the same commit referenced as submodules.
  2. A replaced CMakeLists.txt (see below) that will make cmake look for the 2 libraries mentioned above instead of using the vendored versions.
  3. Patch a few referenced paths. substituteInPlace is a sed wrapper that handles escaping paths and the likes and ${netpbm} is a reference to netpbm from where we get the rgb.txt.

Replace CMakeLists.txt with this:

    cmake_minimum_required(VERSION 3.5)

    set(CMAKE_POSITION_INDEPENDENT_CODE ON)

    find_library(HIDAPI_LIBRARY hidapi-libusb)
    find_library(CRC_LIBRARY crc)
    find_library(YAML_LIBRARY yaml-cpp)

    add_subdirectory(src)

And the patches:

    for f in kbdtest.cc kbdtest2.cc xbows.hh ; do
      substituteInPlace src/$f --replace '<hidapi' '<hidapi/hidapi'
    done

    substituteInPlace src/driver_parse.cc \
      --replace /usr/share/X11/rgb.txt ${netpbm}/share/netpbm/misc/rgb.txt

    sed -i src/CMakeLists.txt \
      -e '/crap/d'

peterhoeg avatar Aug 26 '19 13:08 peterhoeg

The full nix expressions is here: https://gist.github.com/peterhoeg/af34a63cd5c4a259a783e8764f637770

peterhoeg avatar Aug 26 '19 13:08 peterhoeg

If we can fix the cmake to correctly work in the NixOS env, I'd rather do that than use a script to edit the cmake config. If I can use find_library and then fall back to building the included version, would that work?

jlquinn avatar Aug 29 '19 04:08 jlquinn

If we can fix the cmake to correctly work in the NixOS env, I'd rather do that than use a script to edit the cmake config

I'm 100% with you on this. NixOS is a little special, so we often have to work around things but it's BY FAR preferable to have proper support upstream.

That being said, it looks like NixOS will be the first distribution to start carrying your work!

If I can use find_library and then fall back to building the included version, would that work?

Yep, that sounds like the way to go. Just FYI, on latest master (2146ead780f7f8cb1de3f46b2e47548dcc1c0816), I still need to use my CMakeLists.txt and the manual install you can see in the installPhase part.

peterhoeg avatar Aug 29 '19 05:08 peterhoeg

How does the hidapi.h header get found with your changes? The cmake edits you make don't make that clear to me. Is it in /usr/include?

jlquinn avatar Sep 01 '19 18:09 jlquinn

I'm not a cmake guru at all, but I guess that find_library uses pkgconfig to locate the include files.

peterhoeg avatar Sep 02 '19 02:09 peterhoeg