about summary refs log tree commit diff
path: root/nixpkgs/pkgs/tools/package-management/appimagekit/default.nix
blob: 151566ba8e8e22f91f2509bae4be6a091d2f1892 (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
{ lib, stdenv, fetchFromGitHub
, pkg-config, cmake, autoconf, automake, libtool, makeWrapper
, wget, xxd, desktop-file-utils, file
, gnupg, glib, zlib, cairo, openssl, fuse, xz, squashfuse, inotify-tools, libarchive
, squashfsTools
, gtest
}:

let

  appimagekit_src = fetchFromGitHub {
    owner = "AppImage";
    repo = "AppImageKit";
    rev = "8bbf694455d00f48d835f56afaa1dabcd9178ba6";
    sha256 = "sha256-pqg+joomC5CI9WdKP/h/XKPsruMgZEaIOjPLOqnNPZw=";
    fetchSubmodules = true;
  };

  # squashfuse adapted to nix from cmake experession in "${appimagekit_src}/lib/libappimage/cmake/dependencies.cmake"
  appimagekit_squashfuse = squashfuse.overrideAttrs (attrs: rec {
    pname = "squashfuse";
    version = "unstable-2016-10-09";

    src = fetchFromGitHub {
      owner = "vasi";
      repo  = pname;
      rev = "1f980303b89c779eabfd0a0fdd36d6a7a311bf92";
      sha256 = "sha256-BZd1+7sRYZHthULKk3RlgMIy4uCUei45GbSEiZxLPFM=";
    };

    patches = [
      "${appimagekit_src}/lib/libappimage/src/patches/squashfuse.patch"
      "${appimagekit_src}/lib/libappimage/src/patches/squashfuse_dlopen.patch"
    ];

    postPatch = ''
      cp -v ${appimagekit_src}/lib/libappimage/src/patches/squashfuse_dlopen.[hc] .
    '';

    # Workaround build failure on -fno-common toolchains:
    #   ld: libsquashfuse_ll.a(libfuseprivate_la-fuseprivate.o):(.bss+0x8):
    #     multiple definition of `have_libloaded'; runtime.4.o:(.bss.have_libloaded+0x0): first defined here
    NIX_CFLAGS_COMPILE = "-fcommon";

    preConfigure = ''
      sed -i "/PKG_CHECK_MODULES.*/,/,:./d" configure
      sed -i "s/typedef off_t sqfs_off_t/typedef int64_t sqfs_off_t/g" common.h
    '';

    configureFlags = [
      "--disable-demo" "--disable-high-level" "--without-lzo" "--without-lz4"
    ];

    postConfigure = ''
      sed -i "s|XZ_LIBS = -llzma |XZ_LIBS = -Bstatic -llzma/|g" Makefile
    '';

    # only static libs and header files
    installPhase = ''
      mkdir -p $out/lib $out/include
      cp -v ./.libs/*.a $out/lib
      cp -v ./*.h $out/include
    '';
  });

in stdenv.mkDerivation rec {
  pname = "appimagekit";
  version = "unstable-2020-12-31";

  src = appimagekit_src;

  patches = [ ./nix.patch ];

  postPatch = ''
    patchShebangs src/embed-magic-bytes-in-file.sh
  '';

  nativeBuildInputs = [
    pkg-config cmake autoconf automake libtool wget xxd
    desktop-file-utils makeWrapper
  ];

  buildInputs = [
    glib zlib cairo openssl fuse xz inotify-tools
    libarchive squashfsTools appimagekit_squashfuse
  ];

  preConfigure = ''
    export HOME=$(pwd)
  '';

  cmakeFlags = [
    "-DUSE_SYSTEM_XZ=ON"
    "-DUSE_SYSTEM_SQUASHFUSE=ON"
    "-DSQUASHFUSE=${appimagekit_squashfuse}"
    "-DUSE_SYSTEM_LIBARCHIVE=ON"
    "-DUSE_SYSTEM_GTEST=ON"
    "-DUSE_SYSTEM_MKSQUASHFS=ON"
    "-DTOOLS_PREFIX=${stdenv.cc.targetPrefix}"
  ];

  postInstall = ''
    mkdir -p $out/lib/appimagekit
    cp "${squashfsTools}/bin/mksquashfs" "$out/lib/appimagekit/"
    cp "${desktop-file-utils}/bin/desktop-file-validate" "$out/bin"

    wrapProgram "$out/bin/appimagetool" \
      --prefix PATH : "${lib.makeBinPath [ file gnupg ]}" \
      --unset SOURCE_DATE_EPOCH
  '';

  checkInputs = [ gtest ];

  # for debugging
  passthru = {
    squashfuse = appimagekit_squashfuse;
  };

  meta = with lib; {
    description = "A tool to package desktop applications as AppImages";
    longDescription = ''
      AppImageKit is an implementation of the AppImage format that
      provides tools such as appimagetool and appimaged for handling
      AppImages.
    '';
    license = licenses.mit;
    maintainers = with maintainers; [ taeer ];
    homepage = src.meta.homepage;
    platforms = platforms.linux;
  };
}