summaryrefslogtreecommitdiffstats
path: root/tv/5pkgs/rpi/WiringPi/default.nix
blob: 61c43556d435fc97713652643d9129cf2baef943 (plain)
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
{ fetchFromGitHub, runCommand, stdenv }:

let
  generic = name: extraAttrs:
    stdenv.mkDerivation ({
      pname = "WiringPi-${name}";
      version = "2020-09-14";

      src = fetchFromGitHub (stdenv.lib.importJSON ./src.json);

      buildPhase = ''
        runHook postBuild

        make -C ${name} all

        runHook preBuild
      '';

      installPhase = ''
        runHook preInstall

        export DESTDIR=$out
        export PREFIX=
        export LDCONFIG=true

        make -C ${name} install

        runHook postInstall
      '';
    } // extraAttrs);

  fakeutils = runCommand "fakeutils-1.0" {} /* sh */ ''
    mkdir -p $out/bin
    for name in chown chmod; do
      touch $out/bin/$name
      chmod +x $out/bin/$name
    done
  '';
in

rec {
  wiringPi = generic "wiringPi" {};
  wiringPiDev = generic "devLib" {
    buildInputs = [
      wiringPi
    ];
  };
  gpio = generic "gpio" {
    preInstall = ''
      # fakeutils cannot be buildInputs because they have to override existing
      # executables and therefore need to be prepended to the search path.
      PATH=${fakeutils}/bin:$PATH

      mkdir -p $out/bin
    '';
    buildInputs = [
      wiringPi
      wiringPiDev
    ];
  };
}