Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)

appimageTools: init

The appimageTools attrset contains utilities to prevent
the usage of appimage-run to package AppImages, like done/attempted
in #49370 and #53156.

This has the advantage of allowing for per-package environment changes,
and extracts into the store instead of the users home directory.

The package list was extracted into appimageTools to prevent
duplication.

tilpner 58443d8a eb965a4b

+306 -114
+1
doc/functions.xml
··· 14 14 <xi:include href="functions/fhs-environments.xml" /> 15 15 <xi:include href="functions/shell.xml" /> 16 16 <xi:include href="functions/dockertools.xml" /> 17 + <xi:include href="functions/appimagetools.xml" /> 17 18 <xi:include href="functions/prefer-remote-fetch.xml" /> 18 19 </chapter>
+121
doc/functions/appimagetools.xml
··· 1 + <section xmlns="http://docbook.org/ns/docbook" 2 + xmlns:xlink="http://www.w3.org/1999/xlink" 3 + xmlns:xi="http://www.w3.org/2001/XInclude" 4 + xml:id="sec-pkgs-appimageTools"> 5 + <title>pkgs.appimageTools</title> 6 + 7 + <para> 8 + <varname>pkgs.appimageTools</varname> is a set of functions for extracting and wrapping 9 + <link xlink:href="https://appimage.org/">AppImage</link> files. 10 + 11 + They are meant to be used if traditional packaging from source is infeasible, or it would take too long. 12 + To quickly run an AppImage file, <literal>pkgs.appimage-run</literal> can be used as well. 13 + </para> 14 + 15 + <warning> 16 + <para> 17 + The <varname>appimageTools</varname> API is unstable and may be subject to 18 + backwards-incompatible changes in the future. 19 + </para> 20 + </warning> 21 + 22 + 23 + <section xml:id="ssec-pkgs-appimageTools-formats"> 24 + <title>AppImage formats</title> 25 + 26 + <para> 27 + There are different formats for AppImages, see 28 + <link xlink:href="https://github.com/AppImage/AppImageSpec/blob/74ad9ca2f94bf864a4a0dac1f369dd4f00bd1c28/draft.md#image-format">the specification</link> for details. 29 + </para> 30 + 31 + <itemizedlist> 32 + <listitem> 33 + <para> 34 + Type 1 images are ISO 9660 files that are also ELF executables. 35 + </para> 36 + </listitem> 37 + 38 + <listitem> 39 + <para> 40 + Type 2 images are ELF executables with an appended filesystem. 41 + </para> 42 + </listitem> 43 + </itemizedlist> 44 + 45 + <para> 46 + They can be told apart with <command>file -k</command>: 47 + </para> 48 + 49 + <screen> 50 + <prompt>$ </prompt>file -k type1.AppImage 51 + type1.AppImage: ELF 64-bit LSB executable, x86-64, version 1 (SYSV) ISO 9660 CD-ROM filesystem data 'AppImage' (Lepton 3.x), scale 0-0, 52 + spot sensor temperature 0.000000, unit celsius, color scheme 0, calibration: offset 0.000000, slope 0.000000, dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.18, BuildID[sha1]=d629f6099d2344ad82818172add1d38c5e11bc6d, stripped\012- data 53 + 54 + <prompt>$ </prompt>file -k type2.AppImage 55 + type2.AppImage: ELF 64-bit LSB executable, x86-64, version 1 (SYSV) (Lepton 3.x), scale 232-60668, spot sensor temperature -4.187500, color scheme 15, show scale bar, calibration: offset -0.000000, slope 0.000000 (Lepton 2.x), scale 4111-45000, spot sensor temperature 412442.250000, color scheme 3, minimum point enabled, calibration: offset -75402534979642766821519867692934234112.000000, slope 5815371847733706829839455140374904832.000000, dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.18, BuildID[sha1]=79dcc4e55a61c293c5e19edbd8d65b202842579f, stripped\012- data 56 + </screen> 57 + 58 + <para> 59 + Note how the type 1 AppImage is described as an <literal>ISO 9660 CD-ROM filesystem</literal>, and the type 2 AppImage is not. 60 + </para> 61 + </section> 62 + 63 + <section xml:id="ssec-pkgs-appimageTools-wrapping"> 64 + <title>Wrapping</title> 65 + 66 + <para> 67 + Depending on the type of AppImage you're wrapping, you'll have to use 68 + <varname>wrapType1</varname> or <varname>wrapType2</varname>. 69 + </para> 70 + 71 + 72 + <programlisting> 73 + appimageTools.wrapType2 { # or wrapType1 74 + name = "patchwork"; <co xml:id='ex-appimageTools-wrapping-1' /> 75 + src = fetchurl { <co xml:id='ex-appimageTools-wrapping-2' /> 76 + url = https://github.com/ssbc/patchwork/releases/download/v3.11.4/Patchwork-3.11.4-linux-x86_64.AppImage; 77 + sha256 = "1blsprpkvm0ws9b96gb36f0rbf8f5jgmw4x6dsb1kswr4ysf591s"; 78 + }; 79 + extraPkgs = pkgs: with pkgs; [ ]; <co xml:id='ex-appimageTools-wrapping-3' /> 80 + }</programlisting> 81 + 82 + 83 + <calloutlist> 84 + <callout arearefs='ex-appimageTools-wrapping-1'> 85 + <para> 86 + <varname>name</varname> specifies the name of the resulting image. 87 + </para> 88 + </callout> 89 + <callout arearefs='ex-appimageTools-wrapping-2'> 90 + <para> 91 + <varname>src</varname> specifies the AppImage file to extract. 92 + </para> 93 + </callout> 94 + <callout arearefs='ex-appimageTools-wrapping-2'> 95 + <para> 96 + <varname>extraPkgs</varname> allows you to pass a function to include additional packages 97 + inside the FHS environment your AppImage is going to run in. 98 + 99 + There are a few ways to learn which dependencies an application needs: 100 + 101 + <itemizedlist> 102 + <listitem> 103 + <para> 104 + Looking through the extracted AppImage files, reading its scripts and running <command>patchelf</command> and <command>ldd</command> on its executables. 105 + This can also be done in <command>appimage-run</command>, by setting <command>APPIMAGE_DEBUG_EXEC=bash</command>. 106 + </para> 107 + </listitem> 108 + 109 + <listitem> 110 + <para> 111 + Running <command>strace -vfefile</command> on the wrapped executable, looking for libraries that can't be found. 112 + </para> 113 + </listitem> 114 + </itemizedlist> 115 + 116 + </para> 117 + </callout> 118 + </calloutlist> 119 + 120 + </section> 121 + </section>
+176
pkgs/build-support/appimage/default.nix
··· 1 + { pkgs, stdenv, libarchive, patchelf, zlib, buildFHSUserEnv, writeScript }: 2 + 3 + rec { 4 + # Both extraction functions could be unified, but then 5 + # it would depend on libmagic to correctly identify ISO 9660s 6 + 7 + extractType1 = { name, src }: stdenv.mkDerivation { 8 + name = "${name}-extracted"; 9 + inherit src; 10 + 11 + nativeBuildInputs = [ libarchive ]; 12 + buildCommand = '' 13 + mkdir $out 14 + bsdtar -x -C $out -f $src 15 + ''; 16 + }; 17 + 18 + extractType2 = { name, src }: stdenv.mkDerivation { 19 + name = "${name}-extracted"; 20 + inherit src; 21 + 22 + nativeBuildInputs = [ patchelf ]; 23 + buildCommand = '' 24 + install $src ./appimage 25 + patchelf \ 26 + --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \ 27 + --replace-needed libz.so.1 ${zlib}/lib/libz.so.1 \ 28 + ./appimage 29 + 30 + ./appimage --appimage-extract 31 + 32 + cp -rv squashfs-root $out 33 + ''; 34 + }; 35 + 36 + wrapAppImage = { name, src, extraPkgs }: buildFHSUserEnv (defaultFhsEnvArgs // { 37 + inherit name; 38 + 39 + targetPkgs = pkgs: defaultFhsEnvArgs.targetPkgs pkgs ++ extraPkgs pkgs; 40 + 41 + runScript = writeScript "run" '' 42 + #!${stdenv.shell} 43 + 44 + export APPDIR=${src} 45 + export APPIMAGE_SILENT_INSTALL=1 46 + cd $APPDIR 47 + exec ./AppRun "$@" 48 + ''; 49 + }); 50 + 51 + wrapType1 = args@{ name, src, extraPkgs ? pkgs: [] }: wrapAppImage { 52 + inherit name extraPkgs; 53 + src = extractType1 { inherit name src; }; 54 + }; 55 + 56 + wrapType2 = args@{ name, src, extraPkgs ? pkgs: [] }: wrapAppImage { 57 + inherit name extraPkgs; 58 + src = extractType2 { inherit name src; }; 59 + }; 60 + 61 + defaultFhsEnvArgs = { 62 + name = "appimage-env"; 63 + 64 + # Most of the packages were taken from the Steam chroot 65 + targetPkgs = pkgs: with pkgs; [ 66 + gtk3 67 + bashInteractive 68 + gnome3.zenity 69 + python2 70 + xorg.xrandr 71 + which 72 + perl 73 + xdg_utils 74 + iana-etc 75 + krb5 76 + ]; 77 + 78 + multiPkgs = pkgs: with pkgs; [ 79 + desktop-file-utils 80 + xorg.libXcomposite 81 + xorg.libXtst 82 + xorg.libXrandr 83 + xorg.libXext 84 + xorg.libX11 85 + xorg.libXfixes 86 + libGL 87 + 88 + gst_all_1.gstreamer 89 + gst_all_1.gst-plugins-ugly 90 + libdrm 91 + xorg.xkeyboardconfig 92 + xorg.libpciaccess 93 + 94 + glib 95 + gtk2 96 + bzip2 97 + zlib 98 + gdk_pixbuf 99 + 100 + xorg.libXinerama 101 + xorg.libXdamage 102 + xorg.libXcursor 103 + xorg.libXrender 104 + xorg.libXScrnSaver 105 + xorg.libXxf86vm 106 + xorg.libXi 107 + xorg.libSM 108 + xorg.libICE 109 + gnome2.GConf 110 + freetype 111 + (curl.override { gnutlsSupport = true; sslSupport = false; }) 112 + nspr 113 + nss 114 + fontconfig 115 + cairo 116 + pango 117 + expat 118 + dbus 119 + cups 120 + libcap 121 + SDL2 122 + libusb1 123 + udev 124 + dbus-glib 125 + libav 126 + atk 127 + at-spi2-atk 128 + libudev0-shim 129 + networkmanager098 130 + 131 + xorg.libXt 132 + xorg.libXmu 133 + xorg.libxcb 134 + libGLU 135 + libuuid 136 + libogg 137 + libvorbis 138 + SDL 139 + SDL2_image 140 + glew110 141 + openssl 142 + libidn 143 + tbb 144 + wayland 145 + mesa_noglu 146 + libxkbcommon 147 + 148 + flac 149 + freeglut 150 + libjpeg 151 + libpng12 152 + libsamplerate 153 + libmikmod 154 + libtheora 155 + libtiff 156 + pixman 157 + speex 158 + SDL_image 159 + SDL_ttf 160 + SDL_mixer 161 + SDL2_ttf 162 + SDL2_mixer 163 + gstreamer 164 + gst-plugins-base 165 + libappindicator-gtk2 166 + libcaca 167 + libcanberra 168 + libgcrypt 169 + libvpx 170 + librsvg 171 + xorg.libXft 172 + libvdpau 173 + alsaLib 174 + ]; 175 + }; 176 + }
+6 -114
pkgs/tools/package-management/appimage-run/default.nix
··· 1 1 { stdenv, writeScript, buildFHSUserEnv, coreutils, file, libarchive 2 - , extraPkgs ? pkgs: [] }: 2 + , extraPkgs ? pkgs: [], appimageTools }: 3 3 4 - buildFHSUserEnv { 4 + let 5 + fhsArgs = appimageTools.defaultFhsEnvArgs; 6 + in buildFHSUserEnv (fhsArgs // { 5 7 name = "appimage-run"; 6 8 7 - # Most of the packages were taken from the Steam chroot 8 - targetPkgs = pkgs: with pkgs; [ 9 - gtk3 10 - bashInteractive 11 - gnome3.zenity 12 - python2 13 - xorg.xrandr 14 - which 15 - perl 16 - xdg_utils 17 - iana-etc 18 - ] ++ extraPkgs pkgs; 19 - 20 - multiPkgs = pkgs: with pkgs; [ 21 - desktop-file-utils 22 - xorg.libXcomposite 23 - xorg.libXtst 24 - xorg.libXrandr 25 - xorg.libXext 26 - xorg.libX11 27 - xorg.libXfixes 28 - libGL 29 - 30 - gst_all_1.gstreamer 31 - gst_all_1.gst-plugins-ugly 32 - libdrm 33 - xorg.xkeyboardconfig 34 - xorg.libpciaccess 35 - 36 - glib 37 - gtk2 38 - bzip2 39 - zlib 40 - gdk_pixbuf 41 - 42 - xorg.libXinerama 43 - xorg.libXdamage 44 - xorg.libXcursor 45 - xorg.libXrender 46 - xorg.libXScrnSaver 47 - xorg.libXxf86vm 48 - xorg.libXi 49 - xorg.libSM 50 - xorg.libICE 51 - gnome2.GConf 52 - freetype 53 - (curl.override { gnutlsSupport = true; sslSupport = false; }) 54 - nspr 55 - nss 56 - fontconfig 57 - cairo 58 - pango 59 - expat 60 - dbus 61 - cups 62 - libcap 63 - SDL2 64 - libusb1 65 - udev 66 - dbus-glib 67 - libav 68 - atk 69 - at-spi2-atk 70 - libudev0-shim 71 - networkmanager098 72 - 73 - xorg.libXt 74 - xorg.libXmu 75 - xorg.libxcb 76 - libGLU 77 - libuuid 78 - libogg 79 - libvorbis 80 - SDL 81 - SDL2_image 82 - glew110 83 - openssl 84 - libidn 85 - tbb 86 - wayland 87 - mesa_noglu 88 - libxkbcommon 89 - 90 - flac 91 - freeglut 92 - libjpeg 93 - libpng12 94 - libsamplerate 95 - libmikmod 96 - libtheora 97 - libtiff 98 - pixman 99 - speex 100 - SDL_image 101 - SDL_ttf 102 - SDL_mixer 103 - SDL2_ttf 104 - SDL2_mixer 105 - gstreamer 106 - gst-plugins-base 107 - libappindicator-gtk2 108 - libcaca 109 - libcanberra 110 - libgcrypt 111 - libvpx 112 - librsvg 113 - xorg.libXft 114 - libvdpau 115 - alsaLib 116 - strace 117 - ]; 9 + targetPkgs = pkgs: fhsArgs.targetPkgs pkgs ++ extraPkgs pkgs; 118 10 119 11 runScript = writeScript "appimage-exec" '' 120 12 #!${stdenv.shell} ··· 153 45 154 46 exec ./AppRun 155 47 ''; 156 - } 48 + })
+2
pkgs/top-level/all-packages.nix
··· 105 105 autoPatchelfHook = makeSetupHook { name = "auto-patchelf-hook"; } 106 106 ../build-support/setup-hooks/auto-patchelf.sh; 107 107 108 + appimageTools = callPackage ../build-support/appimage { }; 109 + 108 110 ensureNewerSourcesHook = { year }: makeSetupHook {} 109 111 (writeScript "ensure-newer-sources-hook.sh" '' 110 112 postUnpackHooks+=(_ensureNewerSources)