about summary refs log tree commit diff
path: root/nixpkgs/pkgs/applications/graphics/imv/default.nix
blob: 30a8a24e3bc2791a2f49cdf59de054448e732053 (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
{ stdenv
, lib
, fetchFromSourcehut
, asciidoc
, cmocka
, docbook_xsl
, libxslt
, meson
, ninja
, pkg-config
, icu
, pango
, inih
, withWindowSystem ? null
, xorg
, libxkbcommon
, libGLU
, wayland
, withBackends ? [ "freeimage" "libtiff" "libjpeg" "libpng" "librsvg" "libnsgif" "libheif" ]
, freeimage
, libtiff
, libjpeg_turbo
, libpng
, librsvg
, netsurf
, libheif
}:

let
  # default value of withWindowSystem
  withWindowSystem' =
         if withWindowSystem != null then withWindowSystem
    else if stdenv.isLinux then "all"
    else "x11";

  windowSystems = {
    all = windowSystems.x11 ++ windowSystems.wayland;
    x11 = [ libGLU xorg.libxcb xorg.libX11 ];
    wayland = [ wayland ];
  };

  backends = {
    inherit freeimage libtiff libpng librsvg libheif;
    libjpeg = libjpeg_turbo;
    inherit (netsurf) libnsgif;
  };

  backendFlags = builtins.map
    (b: if builtins.elem b withBackends
        then "-D${b}=enabled"
        else "-D${b}=disabled")
    (builtins.attrNames backends);
in

# check that given window system is valid
assert lib.assertOneOf "withWindowSystem" withWindowSystem'
  (builtins.attrNames windowSystems);
# check that every given backend is valid
assert builtins.all
  (b: lib.assertOneOf "each backend" b (builtins.attrNames backends))
  withBackends;

stdenv.mkDerivation rec {
  pname = "imv";
  version = "4.4.0";
  outputs = [ "out" "man" ];

  src = fetchFromSourcehut {
    owner = "~exec64";
    repo = "imv";
    rev = "v${version}";
    sha256 = "sha256-LLEEbriHzZhAOQivqHqdr6g7lh4uj++ytlme8AfRjf4=";
  };

  mesonFlags = [
    "-Dwindows=${withWindowSystem'}"
    "-Dtest=enabled"
    "-Dman=enabled"
  ] ++ backendFlags;

  nativeBuildInputs = [
    asciidoc
    cmocka
    docbook_xsl
    libxslt
    meson
    ninja
    pkg-config
  ];

  buildInputs = [
    icu
    libxkbcommon
    pango
    inih
  ] ++ windowSystems."${withWindowSystem'}"
    ++ builtins.map (b: backends."${b}") withBackends;

  postInstall = ''
    # fix the executable path and install the desktop item
    substituteInPlace ../files/imv.desktop --replace "imv %F" "$out/bin/imv %F"
    install -Dm644 ../files/imv.desktop $out/share/applications/
  '';

  postFixup = lib.optionalString (withWindowSystem' == "all") ''
    # The `bin/imv` script assumes imv-wayland or imv-x11 in PATH,
    # so we have to fix those to the binaries we installed into the /nix/store

    substituteInPlace "$out/bin/imv" \
      --replace "imv-wayland" "$out/bin/imv-wayland" \
      --replace "imv-x11" "$out/bin/imv-x11"
  '';

  doCheck = true;

  meta = with lib; {
    description = "A command line image viewer for tiling window managers";
    homepage = "https://sr.ht/~exec64/imv/";
    license = licenses.mit;
    maintainers = with maintainers; [ rnhmjoj markus1189 ];
    platforms = platforms.all;
    badPlatforms = platforms.darwin;
  };
}