#flatpak #desktop-applications #manifest #cargo #generate #package #build

app cargo-pak

Generate manifest and desktop files for flatpak

7 releases

0.1.7 Aug 30, 2024
0.1.6 Aug 30, 2024
0.1.3 Jun 25, 2024
0.1.2 Apr 3, 2024

#140 in Cargo plugins

30 downloads per month

GPL-3.0-only

21KB
359 lines

Cargo-pak

the easiest way to package flatpak files

How-to

Dependencies

You will need

  • Rust stable (as well as cargo and other tools)
  • cargo-pak
  • flatpak-builder
  • mold
rustup update
cargo install cargo-pak
apt-get install flatpak-builder mold

Create a rust application

cargo new hello
cd hello
fn main() {
    println!("hello world!");
}

Create an app config

The file must be named pak.toml!!

This config contains details for both the flatpak manifest and .Desktop file. the following example is for a graphical X11 based application.

app_id="xyz.toastxc.Hello"
app_name= "hello"
# defined in Cargo.toml (release is performant)
profile="release"

# cargo-pack will default to package name in Cargo.toml
# bin="hello-world"

# definitions: https://docs.flatpak.org/en/latest/sandbox-permissions.html
permissions = [
    "--share=network",
    "--socket=x11",
    "--device=dri"
]

# definitions: https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html
[desktopfile]
terminal= false

If you want to use a CLI, it's a bit more simple. Information such as the app name and version are derived from Cargo.toml

app_id="xyz.toastxc.Hello"

[desktopfile]
terminal= true

Icons

For the .desktop file icon to work you MUST leave a .png in the root of the directory, identical to the bin name. (e.g. hello-world.png) For example

[package]
name = "hello"
version = "0.1.0"
edition = "2021"
hello.png

Even if the file is NOT a png, rename it. This program can convert file types and sizes.

Commands

These commands act in a similar way to docker-compose; they are directory dependant. You must be at the root of your rust project file for this to work

Generate

This command generates a desktopfile and flatpak manifest file based on pak.toml

cargo-pak generate

Build

Builds a flatpak application based on the desktop & manifest file

cargo-pak build

Install

Installs (as root) the flatpak

cargo-pak install

Remove

Removes the flatpak from your system

cargo-pak remove

F.A.Q

Why is my icon not working?

cargo-pak automatically converts and resizes icons, it should work as long as the icon follows these conditions

  • square (exactly 1:1 ratio)
  • in root directory (./) Most file types are supported as well as sizes

Building isn't working!

If you have modified files you may need to run cargo-pak generate again.

Dependencies

~4MB
~77K SLoC