A Flatpak repository mirroring tool for managing local Flatpak repositories, originally created for splashos.
usrpkg-builder is a Node.js tool that downloads and mirrors Flatpak applications from Flathub (or other remotes) to a local OSTree repository. It uses the libflatpak npm package for Flatpak integration and provides a configurable, automated way to create and maintain local Flatpak repositories.
- Full Flathub Mirroring: Download all available Flatpak applications from Flathub
- Configurable Architecture: Target specific architectures (x86_64, i386, etc.)
- Package Limiting: Optionally limit the number of packages mirrored for testing
- AppStream Metadata: Downloads and parses AppStream data for package information
- Repository Management: Creates, configures, and maintains OSTree repositories
- Batch Processing: Downloads packages in configurable batches for optimal performance
- Retry Logic: Automatic retries for failed downloads with exponential backoff
- Repository Optimization: Generates static deltas and repository summaries
- Node.js 18 or higher
- Flatpak installed on the system
- Flatpak development libraries (
flatpak-develon Fedora/RHEL,libflatpak-devon Debian/Ubuntu)
-
Clone the repository:
git clone <repository-url> cd usrpkg-builder
-
Install dependencies:
npm install
-
Ensure Flatpak is installed and configured:
flatpak --version
Configuration is managed through config.yaml:
# Repository configuration
repo_path: ./usrpkg-repo # Path where the OSTree repository will be created
appstream_url: https://dl.flathub.org/repo/appstream/x86_64/appstream.xml.gz # AppStream metadata URL
architecture: x86_64 # Target architecture
remote_name: flathub # Remote repository name
remote_url: https://dl.flathub.org/repo/ # Remote repository URL
max_packages: 0 # Maximum packages to mirror (0 = all packages)repo_path: Local filesystem path for the OSTree repositoryappstream_url: URL to download AppStream metadata (contains package descriptions)architecture: Target CPU architecture (e.g., x86_64, i386, aarch64)remote_name: Name of the remote Flatpak repository to mirrorremote_url: URL of the remote repositorymax_packages: Limit the number of packages mirrored (useful for testing)
To start mirroring packages from Flathub:
node index.jsThe tool will:
- Create or open the repository at the configured path
- Configure the Flathub remote (with GPG verification disabled for mirroring)
- Fetch the list of available packages
- Download AppStream metadata
- Mirror packages in batches
- Optimize the repository and generate summaries
To use a custom repository location, update config.yaml:
repo_path: /path/to/your/repositoryTo test with a limited number of packages:
max_packages: 10 # Only mirror 10 packagesOnce the repository is created, you can use it as a Flatpak remote:
# Add the local repository as a remote
flatpak remote-add --user --no-gpg-verify usrpkg file://$(pwd)/usrpkg-repo
# Install applications from the local repository
flatpak install --user usrpkg org.gnome.Calculatorusrpkg-builder consists of three main components:
- Configuration Management (
utils/config.js): Loads and validates configuration fromconfig.yaml - libflatpak Bindings: JavaScript bindings to libflatpak for native Flatpak integration (pure bindings approach for all operations)
- Mirroring Engine (
mirror/libflatpakMirror.js): Main mirroring logic using pure libflatpak bindings
- Repository Setup: Creates or opens an OSTree repository at the configured path using libflatpak bindings
- Remote Configuration: Adds and configures the remote repository (Flathub by default) using pure libflatpak bindings
- Package Discovery: Fetches the list of available packages using
libflatpakbindings - Metadata Download: Downloads and parses AppStream XML for package information
- Package Mirroring: Downloads packages in batches with retry logic using libflatpak transactions
- Repository Optimization: Generates static deltas and updates repository summary
- Pure Bindings Approach: Uses libflatpak bindings for all operations without CLI fallbacks
- Batch Processing: Packages are downloaded in configurable batches (default: 5) to balance performance and resource usage
- Retry Logic: Failed downloads are retried up to 3 times with exponential backoff
- Error Handling: Detailed error reporting with failed package tracking
- Progress Reporting: Real-time progress updates during mirroring
- Binding Fixes: All known binding issues have been resolved, enabling full functionality
After successful mirroring, the repository will have the following structure:
usrpkg-repo/
├── repo/ # OSTree repository
│ ├── config # Repository configuration
│ ├── objects/ # OSTree objects (packages, metadata)
│ ├── refs/ # References to objects
│ └── tmp/ # Temporary files
├── appstream/ # AppStream metadata
│ └── x86_64/ # Architecture-specific metadata
├── .changed # Change tracking file
└── README.md # Repository information
The libflatpak npm package bindings have been fully fixed and now provide complete functionality for Flatpak mirroring:
What works with libflatpak bindings:
- ✅ Reading system information (
getDefaultArch(),getSupportedArches()) - ✅ Listing system installations and remotes
- ✅ Fetching package lists and metadata
- ✅ Reading package properties (name, architecture, size, etc.)
- ✅ Creating remotes with
Remote.create() - ✅ Creating transactions with
Transaction.create() - ✅ Installation path access with proper string conversion
- ✅ Property accessors using correct camelCase method names
- ✅ Multiple constructor methods available
- ✅ GBytes parameter handling for flatpakref data
- ✅ Full package installation via transactions
Key binding fixes implemented:
- GObject Parameter Handling: Accepts both external objects and wrapper objects with
_nativeproperty - Multiple Constructor Support: All constructors properly exported (e.g.,
Remote.create(),Remote.createFromFile()) - Property Getter/Setter Fixes: Uses correct camelCase method names (e.g.,
getName()notget_name()) - GLib.Bytes Parameter Handling: Converts JavaScript Buffer objects to GBytes*
- Gio.File to String Conversion:
getPath()returns string instead of external object - Wrapper Object Support: All methods accept wrapper objects as parameters
Pure Binding Approach: The tool now uses 100% libflatpak bindings without CLI fallbacks, enabling a pure JavaScript solution for Flatpak repository mirroring.
-
GPG Verification Errors: The tool disables GPG verification by default. If you need verification, install Flathub's GPG key first.
-
Missing Flatpak Development Libraries: Ensure
flatpak-develorlibflatpak-devis installed. -
Permission Errors: The tool creates repositories in user space. Ensure you have write permissions to the target directory.
-
Network Issues: The tool requires network access to download packages. Check your connection and firewall settings.
Enable verbose output by adding debug logging to the code or running with DEBUG=* node index.js.
- Disk Space: Mirroring all Flathub packages requires significant disk space (hundreds of GBs)
- Network Bandwidth: Downloading all packages requires substantial bandwidth
- Memory Usage: Processing AppStream data requires sufficient RAM
- Time: Full mirroring can take many hours depending on network speed
usrpkg-builder/
├── index.js # Main entry point
├── config.yaml # Configuration file
├── package.json # Node.js dependencies
├── utils/ # Utility modules
│ ├── config.js # Configuration loader
│ ├── flatpakLib.js # libflatpak-based utilities
│ └── db.js # Database utilities (unused)
├── mirror/ # Mirroring functionality
│ ├── libflatpakMirror.js # Pure bindings mirroring logic
│ └── fetchAppstream.js # AppStream fetching
└── node_modules/ # Dependencies
- New Configuration Options: Add to
config.yamland updateutils/config.js - Additional Remotes: Extend the remote configuration logic in
mirror/libflatpakMirror.js - Custom Filters: Modify the package filtering logic in the mirroring functions
- Progress Reporting: Enhance the batch processing with more detailed progress
ISC License
Contributions are welcome! Please submit pull requests or open issues for bugs and feature requests.
- Built with the
libflatpaknpm package for Flatpak integration - Uses Flathub as the default remote repository
- Inspired by the needs of splashos for local Flatpak repositories