about summary refs log tree commit diff
path: root/pkgs/applications/misc/cobang/default.nix
blob: 336b4d7c1a507d88814b8c75f29c0de22b448493 (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
{ lib
, buildPythonApplication
, fetchFromGitHub
, brotlicffi
, gst-python
, kiss-headers
, logbook
, pillow
, pygobject3
, python-zbar
, requests
, single-version
, gobject-introspection
, gst-plugins-good
, gtk3
, libhandy
, librsvg
, networkmanager
, setuptools
, python
, pytestCheckHook
, wrapGAppsHook
}:

buildPythonApplication rec {
  pname = "cobang";
  version = "0.10.9";
  pyproject = true;

  src = fetchFromGitHub {
    owner = "hongquan";
    repo = "CoBang";
    rev = "refs/tags/v${version}";
    hash = "sha256-xOP2XkmHOGMe50dn4StX/9veTdloLHq76ENWEUK4Keo=";
  };

  postPatch = ''
    # Fixes "Multiple top-level packages discovered in a flat-layout"
    sed -i '$ a\[tool.setuptools]' pyproject.toml
    sed -i '$ a\packages = ["cobang"]' pyproject.toml
  '';

  nativeBuildInputs = [
    # Needed to recognize gobject namespaces
    gobject-introspection
    wrapGAppsHook
    setuptools
  ];

  buildInputs = [
    # Requires v4l2src
    gst-plugins-good
    # For gobject namespaces
    libhandy
    networkmanager
  ];

  propagatedBuildInputs = [
    brotlicffi
    kiss-headers
    logbook
    pillow
    requests
    single-version
    # Unlisted dependencies
    pygobject3
    python-zbar
    # Needed as a gobject namespace and to fix 'Caps' object is not subscriptable
    gst-python
  ];

  nativeCheckInputs = [
    pytestCheckHook
  ];

  # Wrapping this manually for SVG recognition
  dontWrapGApps = true;

  postInstall = ''
    # Needed by the application
    cp -R data $out/${python.sitePackages}/

    # Icons and applications
    install -Dm 644 $out/${python.sitePackages}/data/vn.hoabinh.quan.CoBang.svg -t $out/share/pixmaps/
    install -Dm 644 $out/${python.sitePackages}/data/vn.hoabinh.quan.CoBang.desktop.in -t $out/share/applications/
    mv $out/${python.sitePackages}/data/vn.hoabinh.quan.CoBang.desktop{.in,}
  '';

  preFixup = ''
    wrapProgram $out/bin/cobang \
      ''${gappsWrapperArgs[@]} \
      --prefix XDG_DATA_DIRS : "${gtk3}/share/gsettings-schemas/${gtk3.name}/" \
      --set GDK_PIXBUF_MODULE_FILE "${librsvg.out}/lib/gdk-pixbuf-2.0/2.10.0/loaders.cache"
  '';

  meta = with lib; {
    description = "A QR code scanner desktop app for Linux";
    homepage = "https://github.com/hongquan/CoBang";
    license = licenses.gpl3Only;
    maintainers = with maintainers; [ wolfangaukang ];
    mainProgram = "cobang";
    platforms = [ "x86_64-linux" ];
  };
}