1# pkgs.appimageTools {#sec-pkgs-appimageTools}
2
3`pkgs.appimageTools` is a set of functions for extracting and wrapping [AppImage](https://appimage.org/) files.
4They are meant to be used if traditional packaging from source is infeasible, or if it would take too long.
5To quickly run an AppImage file, `pkgs.appimage-run` can be used as well.
6
7::: {.warning}
8The `appimageTools` API is unstable and may be subject to backwards-incompatible changes in the future.
9:::
10
11## Wrapping {#ssec-pkgs-appimageTools-wrapping}
12
13Use `wrapType2` to wrap any AppImage.
14This will create a FHS environment with many packages [expected to exist](https://github.com/AppImage/pkg2appimage/blob/master/excludelist) for the AppImage to work.
15`wrapType2` expects an argument with the `src` attribute, and either a `name` attribute or `pname` and `version` attributes.
16
17It will eventually call into [`buildFHSEnv`](#sec-fhs-environments), and any extra attributes in the argument to `wrapType2` will be passed through to it.
18This means that you can pass the `extraInstallCommands` attribute, for example, and it will have the same effect as described in [`buildFHSEnv`](#sec-fhs-environments).
19
20::: {.note}
21In the past, `appimageTools` provided both `wrapType1` and `wrapType2`, to be used depending on the type of AppImage that was being wrapped.
22However, [those were unified early 2020](https://github.com/NixOS/nixpkgs/pull/81833), meaning that both `wrapType1` and `wrapType2` have the same behaviour now.
23:::
24
25:::{.example #ex-wrapping-appimage-from-github}
26
27# Wrapping an AppImage from GitHub
28
29```nix
30{ appimageTools, fetchurl }:
31let
32 pname = "nuclear";
33 version = "0.6.30";
34
35 src = fetchurl {
36 url = "https://github.com/nukeop/nuclear/releases/download/v${version}/nuclear-v${version}.AppImage";
37 hash = "sha256-he1uGC1M/nFcKpMM9JKY4oeexJcnzV0ZRxhTjtJz6xw=";
38 };
39in
40appimageTools.wrapType2 {
41 inherit pname version src;
42}
43```
44
45:::
46
47The argument passed to `wrapType2` can also contain an `extraPkgs` attribute, which allows you to include additional packages inside the FHS environment your AppImage is going to run in.
48`extraPkgs` must be a function that returns a list of packages.
49There are a few ways to learn which dependencies an application needs:
50
51 - Looking through the extracted AppImage files, reading its scripts and running `patchelf` and `ldd` on its executables.
52 This can also be done in `appimage-run`, by setting `APPIMAGE_DEBUG_EXEC=bash`.
53 - Running `strace -vfefile` on the wrapped executable, looking for libraries that can't be found.
54
55:::{.example #ex-wrapping-appimage-with-extrapkgs}
56
57# Wrapping an AppImage with extra packages
58
59```nix
60{ appimageTools, fetchurl }:
61let
62 pname = "irccloud";
63 version = "0.16.0";
64
65 src = fetchurl {
66 url = "https://github.com/irccloud/irccloud-desktop/releases/download/v${version}/IRCCloud-${version}-linux-x86_64.AppImage";
67 hash = "sha256-/hMPvYdnVB1XjKgU2v47HnVvW4+uC3rhRjbucqin4iI=";
68 };
69in
70appimageTools.wrapType2 {
71 inherit pname version src;
72 extraPkgs = pkgs: [ pkgs.at-spi2-core ];
73}
74```
75
76:::
77
78## Extracting {#ssec-pkgs-appimageTools-extracting}
79
80Use `extract` if you need to extract the contents of an AppImage.
81This is usually used in Nixpkgs to install extra files in addition to [wrapping](#ssec-pkgs-appimageTools-wrapping) the AppImage.
82`extract` expects an argument with the `src` attribute, and either a `name` attribute or `pname` and `version` attributes.
83
84::: {.note}
85In the past, `appimageTools` provided both `extractType1` and `extractType2`, to be used depending on the type of AppImage that was being extracted.
86However, [those were unified early 2020](https://github.com/NixOS/nixpkgs/pull/81572), meaning that both `extractType1` and `extractType2` have the same behaviour as `extract` now.
87:::
88
89:::{.example #ex-extracting-appimage}
90
91# Extracting an AppImage to install extra files
92
93This example was adapted from a real package in Nixpkgs to show how `extract` is usually used in combination with `wrapType2`.
94Note how `appimageContents` is used in `extraInstallCommands` to install additional files that were extracted from the AppImage.
95
96```nix
97{ appimageTools, fetchurl }:
98let
99 pname = "irccloud";
100 version = "0.16.0";
101
102 src = fetchurl {
103 url = "https://github.com/irccloud/irccloud-desktop/releases/download/v${version}/IRCCloud-${version}-linux-x86_64.AppImage";
104 hash = "sha256-/hMPvYdnVB1XjKgU2v47HnVvW4+uC3rhRjbucqin4iI=";
105 };
106
107 appimageContents = appimageTools.extract {
108 inherit pname version src;
109 };
110in
111appimageTools.wrapType2 {
112 inherit pname version src;
113
114 extraPkgs = pkgs: [ pkgs.at-spi2-core ];
115
116 extraInstallCommands = ''
117 mv $out/bin/${pname}-${version} $out/bin/${pname}
118 install -m 444 -D ${appimageContents}/irccloud.desktop $out/share/applications/irccloud.desktop
119 install -m 444 -D ${appimageContents}/usr/share/icons/hicolor/512x512/apps/irccloud.png \
120 $out/share/icons/hicolor/512x512/apps/irccloud.png
121 substituteInPlace $out/share/applications/irccloud.desktop \
122 --replace-fail 'Exec=AppRun' 'Exec=${pname}'
123 '';
124}
125```
126
127:::
128
129The argument passed to `extract` can also contain a `postExtract` attribute, which allows you to execute additional commands after the files are extracted from the AppImage.
130`postExtract` must be a string with commands to run.
131
132:::{.example #ex-extracting-appimage-with-postextract}
133
134# Extracting an AppImage to install extra files, using `postExtract`
135
136This is a rewrite of [](#ex-extracting-appimage) to use `postExtract`.
137
138```nix
139{ appimageTools, fetchurl }:
140let
141 pname = "irccloud";
142 version = "0.16.0";
143
144 src = fetchurl {
145 url = "https://github.com/irccloud/irccloud-desktop/releases/download/v${version}/IRCCloud-${version}-linux-x86_64.AppImage";
146 hash = "sha256-/hMPvYdnVB1XjKgU2v47HnVvW4+uC3rhRjbucqin4iI=";
147 };
148
149 appimageContents = appimageTools.extract {
150 inherit pname version src;
151 postExtract = ''
152 substituteInPlace $out/irccloud.desktop --replace-fail 'Exec=AppRun' 'Exec=${pname}'
153 '';
154 };
155in
156appimageTools.wrapType2 {
157 inherit pname version src;
158
159 extraPkgs = pkgs: [ pkgs.at-spi2-core ];
160
161 extraInstallCommands = ''
162 mv $out/bin/${pname}-${version} $out/bin/${pname}
163 install -m 444 -D ${appimageContents}/irccloud.desktop $out/share/applications/irccloud.desktop
164 install -m 444 -D ${appimageContents}/usr/share/icons/hicolor/512x512/apps/irccloud.png \
165 $out/share/icons/hicolor/512x512/apps/irccloud.png
166 '';
167}
168```
169
170:::