about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/libraries/lirc/default.nix
blob: 8d5a7d9aebd2a6decf88a22228f905d45a619dff (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
{ lib
, stdenv
, fetchurl
, fetchpatch
, autoreconfHook
, pkg-config
, help2man
, python3

, alsa-lib
, libxslt
, systemd
, libusb-compat-0_1
, libftdi1
, libICE
, libSM
, libX11
}:

let
  pythonEnv = python3.pythonOnBuildForHost.withPackages (p: with p; [ pyyaml setuptools ]);
in
stdenv.mkDerivation rec {
  pname = "lirc";
  version = "0.10.2";

  src = fetchurl {
    url = "mirror://sourceforge/lirc/${pname}-${version}.tar.bz2";
    sha256 = "sha256-PUTsgnSIHPJi8WCAVkHwgn/8wgreDYXn5vO5Dg09Iio=";
  };

  patches = [
    # Fix installation of Python bindings
    (fetchpatch {
      url = "https://sourceforge.net/p/lirc/tickets/339/attachment/0001-Fix-Python-bindings.patch";
      sha256 = "088a39x8c1qd81qwvbiqd6crb2lk777wmrs8rdh1ga06lglyvbly";
    })

    # Add a workaround for linux-headers-5.18 until upstream adapts:
    #   https://sourceforge.net/p/lirc/git/merge-requests/45/
    ./linux-headers-5.18.patch
  ];

  postPatch = ''
    patchShebangs .

    # fix overriding PYTHONPATH
    sed -i 's,^PYTHONPATH *= *,PYTHONPATH := $(PYTHONPATH):,' \
      Makefile.in
    sed -i 's,PYTHONPATH=,PYTHONPATH=$(PYTHONPATH):,' \
      doc/Makefile.in

    # Pull fix for new pyyaml pending upstream inclusion
    #   https://sourceforge.net/p/lirc/git/merge-requests/39/
    substituteInPlace python-pkg/lirc/database.py --replace 'yaml.load(' 'yaml.safe_load('

    # cant import '/build/lirc-0.10.1/python-pkg/lirc/_client.so' while cross-compiling to check the version
    substituteInPlace python-pkg/setup.py \
      --replace "VERSION='0.0.0'" "VERSION='${version}'"
  '';

  preConfigure = ''
    # use empty inc file instead of a from linux kernel generated one
    touch lib/lirc/input_map.inc

    export PKGCONFIG="$PKG_CONFIG"
  '';

  strictDeps = true;

  nativeBuildInputs = [ autoreconfHook help2man libxslt pythonEnv pkg-config ];

  buildInputs = [ alsa-lib systemd libusb-compat-0_1 libftdi1 libICE libSM libX11 ];

  DEVINPUT_HEADER = "include/linux/input-event-codes.h";

  configureFlags = [
    "--sysconfdir=/etc"
    "--localstatedir=/var"
    "--with-systemdsystemunitdir=$(out)/lib/systemd/system"
    "--enable-uinput" # explicit activation because build env has no uinput
    "--enable-devinput" # explicit activation because build env has no /dev/input
    "--with-lockdir=/run/lirc/lock" # /run/lock is not writable for 'lirc' user
    "PYTHON=${pythonEnv.interpreter}"
  ];

  installFlags = [
    "sysconfdir=$out/etc"
    "localstatedir=$TMPDIR"
  ];

  meta = with lib; {
    description = "Allows to receive and send infrared signals";
    homepage = "https://www.lirc.org/";
    license = licenses.gpl2;
    platforms = platforms.linux;
    maintainers = with maintainers; [ pSub ];
  };
}