about summary refs log tree commit diff
path: root/pkgs/by-name/ca/cameractrls/package.nix
blob: 2b715397150c55303605dd5a6ed299fa85d5ee61 (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
{
  lib,
  python3Packages,
  fetchFromGitHub,
  glibc,
  SDL2,
  libjpeg_turbo,
  alsa-lib,
  libspnav,
  desktop-file-utils,
  gobject-introspection,
  wrapGAppsHook3,
  wrapGAppsHook4,
  cameractrls-gtk3,
  cameractrls-gtk4,
  withGtk ? null,
}:

assert lib.assertOneOf "'withGtk' in cameractrls" withGtk [
  3
  4
  null
];

let
  mainExecutable =
    "cameractrls" + lib.optionalString (withGtk != null) "gtk" + lib.optionalString (withGtk == 4) "4";

  modulePath = "${placeholder "out"}/${python3Packages.python.sitePackages}/CameraCtrls";

  installExecutables = [
    "cameractrls"
    "cameractrlsd"
    "cameraptzgame"
    "cameraptzmidi"
    "cameraptzspnav"
    "cameraview"
  ] ++ lib.optionals (withGtk != null) [ mainExecutable ];
in
python3Packages.buildPythonApplication rec {
  pname = "cameractrls";
  version = "0.6.6";
  pyproject = false;

  src = fetchFromGitHub {
    owner = "soyersoyer";
    repo = "cameractrls";
    rev = "v${version}";
    hash = "sha256-QjjLd5L+8Slxc3ywurhsWp1pZ2E1Y7NOdnCV2ZYBlqU=";
  };

  postPatch = ''
    substituteInPlace cameractrlsd.py \
      --replace-fail "ctypes.util.find_library('c')" '"${lib.getLib glibc}/lib/libc.so.6"'
    substituteInPlace cameraptzgame.py cameraview.py \
      --replace-fail "ctypes.util.find_library('SDL2-2.0')" '"${lib.getLib SDL2}/lib/libSDL2-2.0.so.0"'
    substituteInPlace cameraview.py \
      --replace-fail "ctypes.util.find_library('turbojpeg')" '"${lib.getLib libjpeg_turbo}/lib/libturbojpeg.so"'
    substituteInPlace cameraptzmidi.py \
      --replace-fail "ctypes.util.find_library('asound')" '"${lib.getLib alsa-lib}/lib/libasound.so"'
    substituteInPlace cameraptzspnav.py \
      --replace-fail "ctypes.util.find_library('spnav')" '"${lib.getLib libspnav}/lib/libspnav.so"'
  '';

  nativeBuildInputs =
    lib.optionals (withGtk != null) [
      desktop-file-utils
      gobject-introspection
    ]
    ++ lib.optionals (withGtk == 3) [ wrapGAppsHook3 ]
    ++ lib.optionals (withGtk == 4) [ wrapGAppsHook4 ];

  # Only used when withGtk != null
  dependencies = with python3Packages; [ pygobject3 ];

  installPhase =
    ''
      runHook preInstall

      mkdir -p $out/bin

      for file in ${lib.concatStringsSep " " installExecutables}; do
        install -Dm755 $file.py -t ${modulePath}
        ln -s ${modulePath}/$file.py $out/bin/$file
      done
    ''
    + lib.optionalString (withGtk != null) ''
      install -Dm644 pkg/hu.irl.cameractrls.svg -t $out/share/icons/hicolor/scalable/apps
      install -Dm644 pkg/hu.irl.cameractrls.metainfo.xml -t $out/share/metainfo
      mkdir -p $out/share/applications
      desktop-file-install \
        --dir="$out/share/applications" \
        --set-key=Exec --set-value="${mainExecutable}" \
        pkg/hu.irl.cameractrls.desktop
    ''
    + ''
      runHook postInstall
    '';

  dontWrapGApps = true;
  dontWrapPythonPrograms = true;

  postFixup = lib.optionalString (withGtk != null) ''
    wrapPythonPrograms
    patchPythonScript ${modulePath}/${mainExecutable}.py
    wrapProgram $out/bin/${mainExecutable} ''${makeWrapperArgs[@]} ''${gappsWrapperArgs[@]}
  '';

  passthru.tests = {
    # Also build these packages in ofBorg (defined in top-level/all-packages.nix)
    inherit cameractrls-gtk3 cameractrls-gtk4;
  };

  meta = {
    description = "Camera controls for Linux";
    longDescription = ''
      It's a standalone Python CLI and GUI (GTK3, GTK4) and
      camera Viewer (SDL) to set the camera controls in Linux.
      It can set the V4L2 controls and it is extendable with
      the non standard controls. Currently it has a Logitech
      extension (LED mode, LED frequency, BRIO FoV, Relative
      Pan/Tilt, PTZ presets), Kiyo Pro extension (HDR, HDR
      mode, FoV, AF mode, Save), Preset extension (Save and
      restore controls), Control Restore Daemon (to restore
      presets at device connection).
    '';
    homepage = "https://github.com/soyersoyer/cameractrls";
    license = lib.licenses.gpl3Plus;
    mainProgram = mainExecutable;
    maintainers = with lib.maintainers; [ aleksana ];
    platforms = lib.platforms.linux;
  };
}