about summary refs log tree commit diff
path: root/pkgs/by-name/lu/lunacy/package.nix
blob: 30b7090aded1190abdee1e9741bfb88d9e29159b (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
{ stdenv
, lib
, fetchurl
, dpkg
, autoPatchelfHook
, zlib
, libgcc
, fontconfig
, libX11
, lttng-ust
, icu
, libICE
, libSM
, libXcursor
, openssl
, imagemagick
}:

stdenv.mkDerivation (finalAttrs: {
  pname = "lunacy";
  version = "9.4.2.5022";

  src = fetchurl {
    url = "https://lcdn.icons8.com/setup/Lunacy_${finalAttrs.version}.deb";
    hash = "sha256-69CO1SPdO+JhAH/G/DihyHDueQOLaaJCf32MjBc77j4=";
  };

  unpackCmd = ''
    mkdir -p root
    dpkg-deb -x $src root
  '';

  buildInputs = [
    zlib
    libgcc
    stdenv.cc.cc
    lttng-ust
    fontconfig.lib

    # Runtime deps
    libICE
    libSM
    libX11
    libXcursor
  ];

  nativeBuildInputs = [
    dpkg
    autoPatchelfHook
  ];

  # adds to the RPATHS of all shared objects (exe and libs)
  appendRunpaths = map (pkg: (lib.getLib pkg) + "/lib") [
    icu
    openssl
    stdenv.cc.libc
    stdenv.cc.cc
  ] ++ [
    # technically, this should be in runtimeDependencies but will not work as
    # "lib" is appended to all elements in the array
    "${placeholder "out"}/lib/lunacy"
  ];

  # will add to the RPATH of executable only
  runtimeDependencies = [
    libICE
    libSM
    libX11
    libXcursor
  ];

  dontBuild = true;
  dontStrip = true;

  installPhase = ''
    runHook preInstall

    mkdir -p "$out/lib";
    cp -R "opt/icons8/lunacy" "$out/lib"
    cp -R "usr/share" "$out/share"

    # Prepare the desktop icon, the upstream icon is 200x200 but the hicolor theme does not
    # support this resolution. Nearest sizes are 192x192 and 256x256.
    ${imagemagick}/bin/convert "opt/icons8/lunacy/Assets/LunacyLogo.png" -resize 192x192 lunacy.png
    install -D lunacy.png "$out/share/icons/hicolor/192x192/apps/${finalAttrs.pname}.png"

    runHook postInstall
  '';

  postInstall = ''
    substituteInPlace $out/share/applications/lunacy.desktop \
      --replace "Exec=/opt/icons8/lunacy/Lunacy" "Exec=${finalAttrs.pname}" \
      --replace "Icon=/opt/icons8/lunacy/Assets/LunacyLogo.png" "Icon=${finalAttrs.pname}"
  '';

  postFixup = ''
    mkdir $out/bin

    # Fixes runtime error regarding missing libSkiaSharp.so (which is in the same directory as the binary).
    ln -s "$out/lib/lunacy/Lunacy" "$out/bin/${finalAttrs.pname}"
  '';

  meta = with lib; {
    description = "Free design software that keeps your flow with AI tools and built-in graphics";
    homepage = "https://icons8.com/lunacy";
    changelog = "https://lunacy.docs.icons8.com/release-notes/";
    license = licenses.unfree;
    maintainers = [ maintainers.eliandoran ];
    platforms = platforms.linux;
    sourceProvenance = [ sourceTypes.binaryBytecode ];
    mainProgram = "lunacy";
  };

})