1{ lib, stdenv, fetchFromGitHub
2, pkg-config, cmake, autoconf, automake, libtool, makeWrapper
3, wget, xxd, desktop-file-utils, file
4, gnupg, glib, zlib, cairo, openssl, fuse, xz, squashfuse, inotify-tools, libarchive
5, squashfsTools
6, gtest
7}:
8
9let
10
11 appimagekit_src = fetchFromGitHub {
12 owner = "AppImage";
13 repo = "AppImageKit";
14 rev = "8bbf694455d00f48d835f56afaa1dabcd9178ba6";
15 sha256 = "sha256-pqg+joomC5CI9WdKP/h/XKPsruMgZEaIOjPLOqnNPZw=";
16 fetchSubmodules = true;
17 };
18
19 # squashfuse adapted to nix from cmake experession in "${appimagekit_src}/lib/libappimage/cmake/dependencies.cmake"
20 appimagekit_squashfuse = squashfuse.overrideAttrs (attrs: rec {
21 pname = "squashfuse";
22 version = "unstable-2016-10-09";
23
24 src = fetchFromGitHub {
25 owner = "vasi";
26 repo = pname;
27 rev = "1f980303b89c779eabfd0a0fdd36d6a7a311bf92";
28 sha256 = "sha256-BZd1+7sRYZHthULKk3RlgMIy4uCUei45GbSEiZxLPFM=";
29 };
30
31 patches = [
32 "${appimagekit_src}/lib/libappimage/src/patches/squashfuse.patch"
33 "${appimagekit_src}/lib/libappimage/src/patches/squashfuse_dlopen.patch"
34 ];
35
36 postPatch = ''
37 cp -v ${appimagekit_src}/lib/libappimage/src/patches/squashfuse_dlopen.[hc] .
38 '';
39
40 # Workaround build failure on -fno-common toolchains:
41 # ld: libsquashfuse_ll.a(libfuseprivate_la-fuseprivate.o):(.bss+0x8):
42 # multiple definition of `have_libloaded'; runtime.4.o:(.bss.have_libloaded+0x0): first defined here
43 env.NIX_CFLAGS_COMPILE = "-fcommon";
44
45 preConfigure = ''
46 sed -i "/PKG_CHECK_MODULES.*/,/,:./d" configure
47 sed -i "s/typedef off_t sqfs_off_t/typedef int64_t sqfs_off_t/g" common.h
48 '';
49
50 configureFlags = [
51 "--disable-demo" "--disable-high-level" "--without-lzo" "--without-lz4"
52 ];
53
54 postConfigure = ''
55 sed -i "s|XZ_LIBS = -llzma |XZ_LIBS = -Bstatic -llzma/|g" Makefile
56 '';
57
58 # only static libs and header files
59 installPhase = ''
60 mkdir -p $out/lib $out/include
61 cp -v ./.libs/*.a $out/lib
62 cp -v ./*.h $out/include
63 '';
64 });
65
66in stdenv.mkDerivation rec {
67 pname = "appimagekit";
68 version = "unstable-2020-12-31";
69
70 src = appimagekit_src;
71
72 patches = [ ./nix.patch ];
73
74 postPatch = ''
75 patchShebangs src/embed-magic-bytes-in-file.sh
76 '';
77
78 nativeBuildInputs = [
79 pkg-config cmake autoconf automake libtool wget xxd
80 desktop-file-utils makeWrapper
81 ];
82
83 buildInputs = [
84 glib zlib cairo openssl fuse xz inotify-tools
85 libarchive squashfsTools appimagekit_squashfuse
86 ];
87
88 preConfigure = ''
89 export HOME=$(pwd)
90 '';
91
92 cmakeFlags = [
93 "-DUSE_SYSTEM_XZ=ON"
94 "-DUSE_SYSTEM_SQUASHFUSE=ON"
95 "-DSQUASHFUSE=${appimagekit_squashfuse}"
96 "-DUSE_SYSTEM_LIBARCHIVE=ON"
97 "-DUSE_SYSTEM_GTEST=ON"
98 "-DUSE_SYSTEM_MKSQUASHFS=ON"
99 "-DTOOLS_PREFIX=${stdenv.cc.targetPrefix}"
100 ];
101
102 postInstall = ''
103 mkdir -p $out/lib/appimagekit
104 cp "${squashfsTools}/bin/mksquashfs" "$out/lib/appimagekit/"
105 cp "${desktop-file-utils}/bin/desktop-file-validate" "$out/bin"
106
107 wrapProgram "$out/bin/appimagetool" \
108 --prefix PATH : "${lib.makeBinPath [ file gnupg ]}" \
109 --unset SOURCE_DATE_EPOCH
110 '';
111
112 nativeCheckInputs = [ gtest ];
113
114 # for debugging
115 passthru = {
116 squashfuse = appimagekit_squashfuse;
117 };
118
119 meta = with lib; {
120 description = "A tool to package desktop applications as AppImages";
121 longDescription = ''
122 AppImageKit is an implementation of the AppImage format that
123 provides tools such as appimagetool and appimaged for handling
124 AppImages.
125 '';
126 license = licenses.mit;
127 maintainers = with maintainers; [ taeer ];
128 homepage = src.meta.homepage;
129 platforms = platforms.linux;
130 };
131}