flatpak-builder-tools

repository·master·Indexed 42 days ago

https://github.com/flatpak/flatpak-builder-tools

A collection of community-contributed scripts to help build applications without network access using flatpak-builder. Includes generators for creating source or module manifests from Cargo lockfiles (flatpak-cargo-generator), CPAN modules (flatpak-cpan-generator), Deno lockfiles (flatpak-deno-generator), and .NET Core .csproj files (flatpak-dotnet-generator).

Tokens
25.7K
Snippets
93
Records
107
Agent score
54%

What's inside flatpak-builder-tools

  1. Use Flatpak Builder Tools to generate manifests

    master

    Flatpak Builder Tools is a collection of community-contributed scripts used to assist in building applications without network access using flatpak-builder.

    The primary function of these tools is to generate Flatpak Builder source or module manifests. These generated manifests can then be included in your main Flatpak Builder manifest to facilitate offline builds.

  2. Workaround for Go modules generated by flatpak-go-mod

    master

    When using github.com/dennwc/flatpak-go-mod, you must include the generated modules.txt file in your Flatpak manifest to ensure the vendor directory is correctly structured. This is done by adding a file type source pointing to modules.txt and setting its destination to vendor.

        sources:
          - type: git
            url: https://github.com/golang/tools
            commit: e81af27852c63b9432c0b5bb49707a7f207ef21b
    
          # Workaround for Go modules generated by github.com/dennwc/flatpak-go-mod
          - type: file
            path: modules.txt
            dest: vendor
    
          - type: archive
            url: https://proxy.golang.org/github.com/yuin/goldmark/@v/v1.4.13.zip
            strip-components: 3
            dest: vendor/github.com/yuin/goldmark
            sha256: bb41a602b174345fda392c8ad83fcc93217c285c763699677630be90feb7a5e3
  3. Requirements and Limitations

    master

    The Flatpak Deno Generator currently has the following constraints:

    • Lockfile Version: Only supports lockfile V5 (introduced in Deno version 2.3).
    • Dependency Separation: Dependencies are split between deno_dir (npm) and vendor (jsr/http). This is due to Deno's internal metadata checks for JSR and HTTPS dependencies which prevent them from being treated purely as standard npm-style dependencies.
  4. Configure source selection and platform wheels

    master

    By default, the tool selects artifacts from PyPI with the following priority:

    1. Universal wheels (none-any.whl)
    2. Source distributions (sdist)

    Platform-specific wheels are ignored by default. To enable them, use the --prefer-wheels option followed by a comma-separated list of package names.

    Note: When using --prefer-wheels, you must provide a --runtime argument. The runtime must include Python, pip, and the python-packaging module so the tool can determine the correct platform tags (Python version, ABI, and architecture).

    # Example: Prefer platform wheels for cryptography and cffi for x86_64 and aarch64
    ./flatpak-pip-generator --runtime org.freedesktop.Sdk//25.08 --prefer-wheels=cryptography,cffi cryptography
  5. Install the Flatpak PIP Generator

    master

    The Flatpak PIP Generator requires the requirements-parser library to function. You can install it on your host system using pip3.

    pip3 install --user requirements-parser
  6. Use the deprecated flatpak-npm-generator

    master

    Deprecation Warning

    This tool is deprecated. You should use flatpak-node-generator instead.

    Purpose

    The flatpak-npm-generator.py tool processes npm5 package-lock.json files to generate flatpak-builder sources. This allows you to build npm-based applications within a flatpak-builder environment without requiring network access during the build process (by enabling npm install --offline).

    Usage

    To generate the required JSON file containing extra sources, run the script against your package-lock.json file:

    ./flatpak-npm-generator.py <path-to-package-lock.json> -o <output-filename>.json

    Example: Building the Electron QuickStart

    The repository includes a sample io.atom.electron.ElectronQuickStart.json. To build it, follow these steps:

    1. Generate the sources:

      ./flatpak-npm-generator.py electron-quick-start-package-lock.json -o generated-sources.json
    2. Build with flatpak-builder:

      flatpak-builder --force-clean --repo=repo app io.atom.electron.ElectronQuickStart.json

    Note: This example requires io.atom.electron.BaseApp to be installed on your system, which is available on Flathub.

    ./flatpak-npm-generator.py electron-quick-start-package-lock.json -o generated-sources.json
    flatpak-builder --force-clean --repo=repo app io.atom.electron.ElectronQuickStart.json
  7. Integrate rubygems.json into your main manifest

    master

    After generating rubygems.json, you must include it in the modules array of your main flatpak-builder manifest. Ensure that necessary dependencies like ruby and bundler are defined in the modules list before the rubygems.json entry.

    {
      "modules": [
        {
          "name": "ruby",
          "config-opts": [
            "--disable-install-doc"
          ],
          "sources": [
            {
              "type": "archive",
              "url": "https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.6.tar.gz",
              "sha256": "8322513279f9edfa612d445bc111a87894fac1128eaa539301cebfc0dd51571e"
            }
          ]
        },
        {
          "name": "bundler",
          "buildsystem": "simple",
          "build-commands": [
            "gem install --local bundler-1.16.2.gem"
          ],
          "sources": [
            {
              "type": "file",
              "url": "https://rubygems.org/downloads/bundler-1.16.2.gem",
              "sha256": "3bb53e03db0a8008161eb4c816ccd317120d3c415ba6fee6f90bbc7f7eec8690"
            }
          ]
        },
        "rubygems.json"
      ]
    }
  8. Install flatpak-node-generator

    master

    The recommended way to install flatpak-node-generator is via pipx. This tool is a modern successor to flatpak-npm-generator and flatpak-yarn-generator, supporting Node 10+ and package managers including npm, yarn, and pnpm.

    If you encounter a JSONDecodeError during installation, try deleting the local pipx virtualenv located in ~/.local/share/pipx on Linux.

    $ pipx install git+https://github.com/flatpak/flatpak-builder-tools.git#subdirectory=node
  9. Generate sources for an Electron project using flatpak-node-generator

    master

    To create the generated-sources.json file required for building an Electron-based Flatpak, use the flatpak-node-generator tool. You must provide the path to the package-lock.json file of the project you are targeting.

    Important: Ensure that your local clone of the project (e.g., electron-quick-start) is at the same commit as specified in your Flatpak manifest file to ensure consistency between the generated sources and the source code.

    flatpak-node-generator npm /path/to/electron-quick-start/package-lock.json
  10. Configure DENO_DIR for npm dependencies

    master

    If your Deno project uses npm dependencies, you must point the DENO_DIR environment variable to the deno_dir directory provided by the generator within your Flatpak build module configuration.

    - name: someModule
      buildsystem: simple
      build-options:
        env:
          DENO_DIR: deno_dir
  11. Use the Flatpak .NET Generator

    master

    The Flatpak .NET Generator is a tool that automatically generates a flatpak-builder sources file from a .NET Core .csproj file. This allows you to include NuGet dependencies as sources in your Flatpak build.

    To use the generated file in your flatpak-builder manifest, you must source the enable.sh script for the dotnet SDK and include the --source nuget-sources argument in your dotnet commands so that the build process can find the generated source files.

    modules:
      - name: my-module
        buildsystem: simple
        build-commands:
          - '. /usr/lib/sdk/dotnet/enable.sh; dotnet build -f netcoreapp2.1 -c Release --source nuget-sources my.input.Desktop.csproj'
        sources:
          - my-output-sources.json