Appimage/zh: Difference between revisions

Ardenet (talk | contribs)
Created page with "[https://appimage.org/ AppImage] 是一种 Linux 应用程序的单体打包格式。它将所有依赖项都包含在一个文件中,该文件由一个可执行文件和一个附加的文件系统组成。"
Tags: Mobile edit Mobile web edit
Ardenet (talk | contribs)
No edit summary
Tags: Mobile edit Mobile web edit
 
(7 intermediate revisions by 2 users not shown)
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 35: Line 30:
   version = "1.4.0";
   version = "1.4.0";
   pname = "quba";
   pname = "quba";
  name = "${pname}-${version}";


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.wrapType1 {
appimageTools.wrapType2 rec {
   inherit name src;
   inherit pname version src;


extraInstallCommands = ''
  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 \
     substituteInPlace $out/share/applications/${pname}.desktop \
       --replace-fail 'Exec=AppRun' 'Exec=${pname}'
       --replace-fail 'Exec=AppRun' 'Exec=${meta.mainProgram}'
    cp -r ${appimageContents}/usr/share/icons $out/share
   '';
   '';


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 58:
</syntaxhighlight>
</syntaxhighlight>


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


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Configuration"></span>
=== Register AppImage files as a binary type to binfmt_misc ===
== 配置 ==
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Register_AppImage_files_as_a_binary_type_to_binfmt_misc"></span>
You can tell the Linux kernel to use an interpreter (e.g. <code>appimage-run</code>) when executing certain binary files through the use of [https://en.wikipedia.org/wiki/Binfmt_misc#External_links 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 <code>appimage-run</code> as interpreter.
=== 将 AppImage 文件作为二进制类型注册到 binfmt_misc ===
</div>
 
<div lang="en" dir="ltr" class="mw-content-ltr">
Since [https://nixos.org/manual/nixos/stable/release-notes#sec-release-24.05-new-services NixOS 24.05], there is a binfmt option:
</div>


您可以通过 [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">
programs.appimage = {
programs.appimage = {
Line 90: Line 73:
</syntaxhighlight>
</syntaxhighlight>


<div lang="en" dir="ltr" class="mw-content-ltr">
这样 AppImage 文件就可以像普通程序一样直接调用
This way AppImage files can be invoked directly as if they were normal programs
</div>


[[Category:Software{{#translation:}}]]
[[Category:Software]]