Jump to content

Appimage/zh: Difference between revisions

From NixOS Wiki
Ardenet (talk | contribs)
Created page with "[https://appimage.org/ AppImage] 是一种 Linux 应用程序的单体打包格式。它将所有依赖项都包含在一个文件中,该文件由一个可执行文件和一个附加的文件系统组成。"
Tags: Mobile edit Mobile web edit
Ardenet (talk | contribs)
Created page with "== 配置 =="
Line 8: Line 8:
=== 运行 ===
=== 运行 ===


<div lang="en" dir="ltr" class="mw-content-ltr">
在大多数发行版中,只需下载 <code>.AppImage</code> 文件,使用 <code>chmod +x $AppImage</code> 使其可执行,然后执行即可。但这在 NixOS 中无法直接使用,因为 AppImage 文件通常(即使并非总是)依赖于硬编码路径中的某些系统库。
On most distros, all one has to do is download the <code>.AppImage</code> file, make it executable <code>chmod +x $AppImage</code>, and execute it. This doesn't work in NixOS out of the box though, as AppImage files usually (if not always) depend on certain system libraries in hardcoded paths.
</div>


<syntaxhighlight lang="shell">
<syntaxhighlight lang="shell">
Line 16: Line 14:
$ appimage-run $AppImageFile
$ appimage-run $AppImageFile
</syntaxhighlight>
</syntaxhighlight>
<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Packaging"></span>
=== Packaging ===
=== 打包 ===
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
请参阅 [https://nixos.org/manual/nixpkgs/stable/#sec-pkgs-appimageTools nixpkgs 手册中包装 AppImage 软件的部分]。简而言之,提取 AppImage,并将所有依赖项添加为 nix 构建依赖项。
See the [https://nixos.org/manual/nixpkgs/stable/#sec-pkgs-appimageTools nixpkgs manual on wrapping AppImage packages]. In short, the AppImage is extracted and any dependencies are added as nix build dependencies.
以下示例是 Quba 程序的 Derivation,它以 AppImage 的形式分发。
Following example is a derivation for the program Quba, which is also distributed as AppImage.
</div>


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
Line 67: Line 62:
</syntaxhighlight>
</syntaxhighlight>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Configuration"></span>
== Configuration ==
== 配置 ==
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">

Revision as of 16:46, 7 October 2025

AppImage 是一种 Linux 应用程序的单体打包格式。它将所有依赖项都包含在一个文件中,该文件由一个可执行文件和一个附加的文件系统组成。

用法

运行

在大多数发行版中,只需下载 .AppImage 文件,使用 chmod +x $AppImage 使其可执行,然后执行即可。但这在 NixOS 中无法直接使用,因为 AppImage 文件通常(即使并非总是)依赖于硬编码路径中的某些系统库。

$ nix-shell -p appimage-run
$ appimage-run $AppImageFile

打包

请参阅 nixpkgs 手册中包装 AppImage 软件的部分。简而言之,提取 AppImage,并将所有依赖项添加为 nix 构建依赖项。 以下示例是 Quba 程序的 Derivation,它以 AppImage 的形式分发。

{
  lib,
  appimageTools,
  fetchurl,
}:

let
  version = "1.4.0";
  pname = "quba";
  name = "${pname}-${version}";

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.wrapType1 {
  inherit name src;

extraInstallCommands = ''
    mv $out/bin/${name} $out/bin/${pname}
    install -m 444 -D ${appimageContents}/${pname}.desktop -t $out/share/applications
    substituteInPlace $out/share/applications/${pname}.desktop \
      --replace-fail 'Exec=AppRun' 'Exec=${pname}'
    cp -r ${appimageContents}/usr/share/icons $out/share
  '';

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" ];
  };
}

配置

Register AppImage files as a binary type to binfmt_misc

You can tell the Linux kernel to use an interpreter (e.g. appimage-run) when executing certain binary files through the use of binfmt_misc, either by filename extension or magic number matching. Below NixOS configuration registers AppImage files (ELF files with magic number "AI" + 0x02) to be run with appimage-run as interpreter.

Since NixOS 24.05, there is a binfmt option:

programs.appimage = {
  enable = true;
  binfmt = true;
};

This way AppImage files can be invoked directly as if they were normal programs