TOC

flatpak

flatpak 和 snap 是目前轻量级 Linux 应用程序虚拟化的两个主流方案。
PS: 还有一个存在很久的方案: AppImage,一直不温不火的存在着。

所谓 Application Virtualization,就是给应用程序弄一个标准的执行环境,屏蔽下面各种发行版的差异。他们采用的技术或许有相通的点,也可能完全不一样,我也没有深入研究。

我感觉这是大趋势,最后可能会出现一个像类似 Google Play、 Apple Store, Windows Store 这种东西,统一 Linux 应用分发市场。当然,这会涉及了很大的利益,谁都想能获得这个市场的主导权,所以这里面的斗争可能很难出最后结果。

flatpak 来自红帽,snap 来自 Ubuntu,两种方式目前都没有能够有足够的话语权(可能他们都不能走到最后,被别的新方案淘汰)。我比较看好 flatpak,毕竟红帽的技术实力在那里,大部分技术都是红帽在推动,相比较而言,Ubuntu 多次想把自己的技术推广出来都是失败。

可能是因为我用的 Ubuntu 的缘故(默认就有一些应用是 snap 安装),感觉好像 snap 出镜率比较高,但我有几次使用 snap 的经历,每次都不是很舒服,最后都是狼狈的回退(和我尝试过 homedrew 体验一样糟糕)。flatpak 我这还是第一次使用。因为今天看到新闻说 GNOME 推出了 , 里面都是一些精选的 Flatpak。

关于 Flatpak

2016 年刚退出的时候叫做 xdg-app(XDG 是 X Desktop Group, 代表 Linux 桌面),旋即改名为 flatpak。

概念

  • 运行时 Runtimes: 屏蔽不同发行版的差异
  • 库 Bundled libraries
  • 沙箱 Sandboxes: 需要访问外部资源必须显式申明并得到授权,对外暴露资源叫做 “导出”
  • 门户 Portals: 沙箱对外部资源访问的一种机制,可能类似浏览器向 JS 提供的 API
  • 仓库 Repositories: 与更新源的概念类似

每个 App 是运行在对应的 Runtime 基础之上,而 App 和 Runtime 都有捆绑其所需要的一堆库。

相比较之下,传统的 Linux 应用直接依赖底层操作系统环境(没有运行时概念),然后是和其他的应用共用依赖库的(不同应用容易有依赖冲突)。

使用

flatpak --help
Usage:
  flatpak [OPTION…] COMMAND

Builtin Commands:
 Manage installed applications and runtimes
  install                Install an application or runtime
  update                 Update an installed application or runtime
  uninstall              Uninstall an installed application or runtime
  mask                   Mask out updates and automatic installation
  pin                    Pin a runtime to prevent automatic removal
  list                   List installed apps and/or runtimes
  info                   Show info for installed app or runtime
  history                Show history
  config                 Configure flatpak
  repair                 Repair flatpak installation
  create-usb             Put applications or runtimes onto removable media

 Finding applications and runtimes
  search                 Search for remote apps/runtimes

 Running applications
  run                    Run an application
  override               Override permissions for an application
  make-current           Specify default version to run
  enter                  Enter the namespace of a running application
  ps                     Enumerate running applications
  kill                   Stop a running application

 Manage file access
  documents              List exported files
  document-export        Grant an application access to a specific file
  document-unexport      Revoke access to a specific file
  document-info          Show information about a specific file

 Manage dynamic permissions
  permissions            List permissions
  permission-remove      Remove item from permission store
  permission-set         Set permissions
  permission-show        Show app permissions
  permission-reset       Reset app permissions

 Manage remote repositories
  remotes                List all configured remotes
  remote-add             Add a new remote repository (by URL)
  remote-modify          Modify properties of a configured remote
  remote-delete          Delete a configured remote
  remote-ls              List contents of a configured remote
  remote-info            Show information about a remote app or runtime

 Build applications
  build-init             Initialize a directory for building
  build                  Run a build command inside the build dir
  build-finish           Finish a build dir for export
  build-export           Export a build dir to a repository
  build-bundle           Create a bundle file from a ref in a local repository
  build-import-bundle    Import a bundle file
  build-sign             Sign an application or runtime
  build-update-repo      Update the summary file in a repository
  build-commit-from      Create new commit based on existing ref
  repo                   Show information about a repo

Help Options:
  -h, --help              Show help options

Application Options:
  --version               Print version information and exit
  --default-arch          Print default arch and exit
  --supported-arches      Print supported arches and exit
  --gl-drivers            Print active gl drivers and exit
  --installations         Print paths for system installations and exit
  --print-updated-env     Print the updated environment needed to run flatpaks
  --print-system-only     Only include the system installation with --print-updated-env
  -v, --verbose           Show debug information, -vv for more detail
  --ostree-verbose        Show OSTree debug information

flatpak search wike
Name             Description                        Application ID                  Version          Branch        Remotes
Wike             Wikipedia Reader                   com.github.hugolabe.Wike        1.5.4            stable        flathub
Outwiker         Personal wiki and outliner.        net.jenyay.Outwiker             3.1.0.892        stable        flathub

flatpak install wike
Found similar ref(s) for ‘wike’ in remote ‘flathub’ (system).
Use this remote? [Y/n]: y
Similar refs found for ‘wike’ in remote ‘flathub’ (system):

   1) app/com.github.hugolabe.Wike/x86_64/stable
   2) app/net.jenyay.Outwiker/x86_64/stable

Which do you want to use (0 to abort)? [0-2]: 1
...

flatpak list
Name                                         Application ID                                      Version       Branch       Installation
Wike                                         com.github.hugolabe.Wike                            1.5.4         stable       system
Mesa                                         org.freedesktop.Platform.GL.default                 21.1.4        20.08        system
nvidia-470-57-02                             org.freedesktop.Platform.GL.nvidia-470-57-02                      1.4          system
Intel                                        org.freedesktop.Platform.VAAPI.Intel                              20.08        system
openh264                                     org.freedesktop.Platform.openh264                   2.1.0         2.0          system
GNOME Application Platform version 40        org.gnome.Platform                                                40           system
Yaru-dark Gtk Theme                          org.gtk.Gtk3theme.Yaru-dark                                       3.22         system

flatpak run com.github.hugolabe.Wike

参考资料与拓展阅读