Appimage/zh: Difference between revisions
Appearance
Created page with "[https://appimage.org/ AppImage] 是一种 Linux 应用程序的单体打包格式。它将所有依赖项都包含在一个文件中,该文件由一个可执行文件和一个附加的文件系统组成。" Tags: Mobile edit Mobile web edit |
No edit summary Tags: Mobile edit Mobile web edit |
||
| (14 intermediate revisions by 2 users not shown) | |||
| Line 8: | Line 8: | ||
=== 运行 === | === 运行 === | ||
在大多数发行版中,只需下载 <code>.AppImage</code> 文件,使用 <code>chmod +x $AppImage</code> 使其可执行,然后执行即可。但这在 NixOS 中无法直接使用,因为 AppImage 文件通常(即使并非总是)依赖于硬编码路径中的某些系统库。 | |||
<syntaxhighlight lang="shell"> | <syntaxhighlight lang="shell"> | ||
$ nix-shell -p appimage-run | $ nix-shell -p appimage-run | ||
$ appimage-run | $ appimage-run path/to/application.AppImage | ||
</syntaxhighlight> | </syntaxhighlight> | ||
< | <span id="Additional_Packages"></span> | ||
===== 额外软件包 ===== | |||
部分 AppImage 包仍存在问题,因此您可以用额外软件包进行覆盖,例如 | |||
<syntaxhighlight lang="nix">programs.appimage.enable = true; | |||
programs.appimage.binfmt = true; | |||
programs.appimage.package = pkgs.appimage-run.override | |||
{ | |||
extraPkgs = pkgs: | |||
[ | |||
pkgs.icu | |||
pkgs.libxcrypt-legacy | |||
pkgs.python312 | |||
pkgs.python312Packages.torch | |||
]; | |||
}; | |||
</syntaxhighlight> | |||
<span id="Packaging"></span> | |||
=== 打包 === | |||
请参阅 [https://nixos.org/manual/nixpkgs/stable/#sec-pkgs-appimageTools nixpkgs 手册中包装 AppImage 软件的部分]。简而言之,提取 AppImage,并将所有依赖项添加为 Nix 构建依赖项。 | |||
以下示例是 Quba 程序的 Derivation,它以 AppImage 的形式分发。 | |||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
| Line 35: | Line 50: | ||
version = "1.4.0"; | version = "1.4.0"; | ||
pname = "quba"; | pname = "quba"; | ||
src = fetchurl { | src = fetchurl { | ||
url = "https://github.com/ZUGFeRD/quba-viewer/releases/download/v${version}/Quba-${version}.AppImage"; | url = "https://github.com/ZUGFeRD/quba-viewer/releases/download/v${version}/Quba-${version}.AppImage"; | ||
hash = "sha256-EsTF7W1np5qbQQh3pdqsFe32olvGK3AowGWjqHPEfoM="; | hash = "sha256-EsTF7W1np5qbQQh3pdqsFe32olvGK3AowGWjqHPEfoM="; | ||
}; | }; | ||
appimageContents = appimageTools.extractType1 { inherit name src; }; | appimageContents = appimageTools.extractType1 { inherit name src; }; | ||
in | in | ||
appimageTools. | appimageTools.wrapType2 rec { | ||
inherit | inherit pname version src; | ||
extraInstallCommands = '' | extraInstallCommands = '' | ||
substituteInPlace $out/share/applications/${pname}.desktop \ | substituteInPlace $out/share/applications/${pname}.desktop \ | ||
--replace-fail 'Exec=AppRun' 'Exec=${ | --replace-fail 'Exec=AppRun' 'Exec=${meta.mainProgram}' | ||
''; | ''; | ||
meta = { | meta = { | ||
description = "Viewer for electronic invoices"; | description = "Viewer for electronic invoices"; | ||
homepage = "https://github.com/ZUGFeRD/quba-viewer"; | homepage = "https://github.com/ZUGFeRD/quba-viewer"; | ||
| Line 67: | Line 78: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
< | <span id="Configuration"></span> | ||
== | == 配置 == | ||
< | <span id="Register_AppImage_files_as_a_binary_type_to_binfmt_misc"></span> | ||
=== 将 AppImage 文件作为二进制类型注册到 binfmt_misc === | |||
您可以通过 [https://en.wikipedia.org/wiki/Binfmt_misc#External_links binfmt_misc] 来告诉 [[Special:MyLanguage/Linux kernel|Linux 内核]]在执行某些二进制文件时使用哪个解释器(例如 <code>appimage-run</code>),具体方式可以通过文件扩展名或魔数匹配来实现。下面的 NixOS 配置会注册 AppImage 文件(魔数为“AI”+ 0x02 的 ELF 文件),并使用 <code>appimage-run</code> 作为解释器运行: | |||
</ | |||
<syntaxhighlight lang="nixos"> | <syntaxhighlight lang="nixos"> | ||
| Line 90: | Line 94: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
这样 AppImage 文件就可以像普通程序一样直接调用。 | |||
[[Category:Software | [[Category:Software]] | ||
Latest revision as of 18:25, 2 August 2026
AppImage 是一种 Linux 应用程序的单体打包格式。它将所有依赖项都包含在一个文件中,该文件由一个可执行文件和一个附加的文件系统组成。
用法
运行
在大多数发行版中,只需下载 .AppImage 文件,使用 chmod +x $AppImage 使其可执行,然后执行即可。但这在 NixOS 中无法直接使用,因为 AppImage 文件通常(即使并非总是)依赖于硬编码路径中的某些系统库。
$ nix-shell -p appimage-run
$ appimage-run path/to/application.AppImage
额外软件包
部分 AppImage 包仍存在问题,因此您可以用额外软件包进行覆盖,例如
programs.appimage.enable = true;
programs.appimage.binfmt = true;
programs.appimage.package = pkgs.appimage-run.override
{
extraPkgs = pkgs:
[
pkgs.icu
pkgs.libxcrypt-legacy
pkgs.python312
pkgs.python312Packages.torch
];
};
打包
请参阅 nixpkgs 手册中包装 AppImage 软件的部分。简而言之,提取 AppImage,并将所有依赖项添加为 Nix 构建依赖项。 以下示例是 Quba 程序的 Derivation,它以 AppImage 的形式分发。
{
lib,
appimageTools,
fetchurl,
}:
let
version = "1.4.0";
pname = "quba";
src = fetchurl {
url = "https://github.com/ZUGFeRD/quba-viewer/releases/download/v${version}/Quba-${version}.AppImage";
hash = "sha256-EsTF7W1np5qbQQh3pdqsFe32olvGK3AowGWjqHPEfoM=";
};
appimageContents = appimageTools.extractType1 { inherit name src; };
in
appimageTools.wrapType2 rec {
inherit pname version src;
extraInstallCommands = ''
substituteInPlace $out/share/applications/${pname}.desktop \
--replace-fail 'Exec=AppRun' 'Exec=${meta.mainProgram}'
'';
meta = {
description = "Viewer for electronic invoices";
homepage = "https://github.com/ZUGFeRD/quba-viewer";
downloadPage = "https://github.com/ZUGFeRD/quba-viewer/releases";
license = lib.licenses.asl20;
sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
maintainers = with lib.maintainers; [ onny ];
platforms = [ "x86_64-linux" ];
};
}
配置
将 AppImage 文件作为二进制类型注册到 binfmt_misc
您可以通过 binfmt_misc 来告诉 Linux 内核在执行某些二进制文件时使用哪个解释器(例如 appimage-run),具体方式可以通过文件扩展名或魔数匹配来实现。下面的 NixOS 配置会注册 AppImage 文件(魔数为“AI”+ 0x02 的 ELF 文件),并使用 appimage-run 作为解释器运行:
programs.appimage = {
enable = true;
binfmt = true;
};
这样 AppImage 文件就可以像普通程序一样直接调用。