Appimage/zh: Difference between revisions

Ardenet (talk | contribs)
Created page with "这样 AppImage 文件就可以像普通程序一样直接调用"
FuzzyBot (talk | contribs)
Updating to match new version of source page
Line 17: Line 17:
=== 打包 ===
=== 打包 ===


<div class="mw-translate-fuzzy">
请参阅 [https://nixos.org/manual/nixpkgs/stable/#sec-pkgs-appimageTools nixpkgs 手册中包装 AppImage 软件的部分]。简而言之,提取 AppImage,并将所有依赖项添加为 nix 构建依赖项。
请参阅 [https://nixos.org/manual/nixpkgs/stable/#sec-pkgs-appimageTools nixpkgs 手册中包装 AppImage 软件的部分]。简而言之,提取 AppImage,并将所有依赖项添加为 nix 构建依赖项。
以下示例是 Quba 程序的 Derivation,它以 AppImage 的形式分发。
以下示例是 Quba 程序的 Derivation,它以 AppImage 的形式分发。
</div>


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
Line 30: Line 32:
   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 61: Line 59:
}
}
</syntaxhighlight>
</syntaxhighlight>


<span id="Configuration"></span>
<span id="Configuration"></span>
Line 68: Line 67:
=== 将 AppImage 文件作为二进制类型注册到 binfmt_misc ===
=== 将 AppImage 文件作为二进制类型注册到 binfmt_misc ===


<div class="mw-translate-fuzzy">
您可以通过 [https://en.wikipedia.org/wiki/Binfmt_misc#External_links binfmt_misc] 来告诉 Linux 内核在执行某些二进制文件时使用哪个解释器(例如 <code>appimage-run</code>),具体方式可以通过文件扩展名或魔数匹配来实现。下面的 NixOS 配置会注册 AppImage 文件(魔数为“AI”+ 0x02 的 ELF 文件),并使用 <code>appimage-run</code> 作为解释器运行。
您可以通过 [https://en.wikipedia.org/wiki/Binfmt_misc#External_links binfmt_misc] 来告诉 Linux 内核在执行某些二进制文件时使用哪个解释器(例如 <code>appimage-run</code>),具体方式可以通过文件扩展名或魔数匹配来实现。下面的 NixOS 配置会注册 AppImage 文件(魔数为“AI”+ 0x02 的 ELF 文件),并使用 <code>appimage-run</code> 作为解释器运行。
 
</div>
从 [https://nixos.org/manual/nixos/stable/release-notes#sec-release-24.05-new-services NixOS 24.05] 开始,有一个 binfmt 选项:
 
<syntaxhighlight lang="nixos">
<syntaxhighlight lang="nixos">
programs.appimage = {
programs.appimage = {
Line 81: Line 79:
这样 AppImage 文件就可以像普通程序一样直接调用
这样 AppImage 文件就可以像普通程序一样直接调用


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