nroi / flexo

a central pacman cache
MIT License
172 stars 10 forks source link
arch-linux arch-linux-packages archlinux bandwidth cache http mirror pacman

Flexo Flexo logo

Flexo is a caching proxy for pacman, the package manager of Arch Linux.

Why should I use it?

Notice that if you start Flexo for the first time, it will run latency tests to select fast mirrors, which will take half a minute or so. During that time, Flexo is not available to serve any requests. Subsequent starts will be faster.

Features

Configuration

The AUR package will install the configuration file in /etc/flexo/flexo.toml. It includes many comments and should be self-explanatory (open an issue in case you disagree). If you use Docker, the settings can be modified with environment variables. Environment variables are prefixed with FLEXO_, for example, listen_ip_address corresponds to the FLEXO_LISTEN_IP_ADDRESS environment variable. More details about configuring Flexo are listed in the wiki.

In most cases, you will want to leave all settings unchanged, with the following exceptions:

  1. The setting low_speed_limit is commented by default, which means that Flexo will not attempt to switch to a faster mirror if a download is extremely slow. To make use of this feature, uncomment the setting and enter an appropriate value. If you use Docker, use the FLEXO_LOW_SPEED_LIMIT environment variable.

  2. The setting allowed_countries is set to the empty list by default, which means that at the first start and at regular intervals, Flexo will run latency tests on all official mirrors from all continents. Add the ISO code of your own country (and perhaps a few neighboring countries) to improve the startup time of Flexo. If you use Docker, use the FLEXO_MIRRORS_AUTO_ALLOWED_COUNTRIES environment variable. Multiple countries can be separated by comma, for example, FLEXO_MIRRORS_AUTO_ALLOWED_COUNTRIES=DE,AT,CZ

  3. If you have additional ArchLinux clients in your LAN, you probably want to change the listen_ip_address setting. It's set to 127.0.0.1 by default for security reasons, change it to 0.0.0.0 to make Flexo accessible to all clients in your LAN.

In addition, if you have a high-bandwidth connection, you may want to consider enabling Pacman's ParallelDownloads setting. With ParallelDownloads enabled, Flexo will receive multiple requests concurrently and therefore fetch the packages from multiple mirrors in parallel, thus making it more likely that your entire bandwidth is utilized.

Troubleshooting

If Flexo does not start at all or crashes, check the logs first:

journalctl --unit=flexo

If that does not help you, please open an issue. The following information may be helpful to troubleshoot your issue:

  1. An excerpt of that log, if Flexo has crashed or did not start.
  2. Your installation method (Docker or AUR).
  3. The version you are using (either the output of pacman -Qi flexo, or the tag if you are using Docker).
  4. Your settings, if you have changed them (either the /etc/flexo/flexo.toml file, or the environment variables if you use Docker).
  5. If the issue is related to the mirror selection, it might also help if you include the country you are located in and the /var/cache/flexo/state/latency_test_results.json file, if it exists.

For issues related to the mirror selection, also see this page for more details.

Cleaning the package cache

The default configuration of Flexo will keep 3 versions of a package in cache: After a 4th version of a package has been downloaded, the oldest version will be automatically removed. This setting can be changed with the num_versions_retain parameter. See the configuration example for more details.

If you use Docker, the default behavior can be changed with the FLEXO_NUM_VERSIONS_RETAIN environment variable.

If you want to disable this setting and never purge the cache, set the parameter to 0.

Using Unofficial User Repositories

If you are using unofficial user repositories and you want Flexo to cache packages from those repositories, both pacman.conf and flexo.toml need to include the custom repository. For example, suppose that Flexo is running on localhost, port 7878, and you want to add two custom repositories: archzfs and eschwartz. First, adapt your /etc/pacman.conf to include both repositories. Notice that the path must start with custom_repo/<repo-name>:

[archzfs]
Server = http://localhost:7878/custom_repo/archzfs/$repo/$arch

[eschwartz]
Server = http://localhost:7878/custom_repo/eschwartz/~eschwartz/repo/$arch

Next, add the corresponding entries to your /etc/flexo/flexo.toml before the [mirrors_auto] section:

[[custom_repo]]
name = "archzfs"
url = "https://archzfs.com"

[[custom_repo]]
name = "eschwartz"
url = "https://pkgbuild.com"

Notice that the names (in this case archzfs and eschwartz) must match the path component right after the /custom_repo in pacman.conf: So if your pacman.conf includes a repo with the path /custom_repo/foo, then your flexo.toml must include a matching [[custom_repo]] entry with name = "foo".

Alternatively, if you use Docker, set the environment variable instead of modifying the flexo.toml file:

FLEXO_CUSTOM_REPO="eschwartz@https://pkgbuild.com archzfs@https://archzfs.com"

ARM support

Running Flexo on ARM devices

Flexo can be built on various ARM platforms, including the Raspberry Pi. So far, no problems have been reported with building and running Flexo on ARM. If you run into problems, please open an issue.

Options to use Flexo on ARM devices include:

Serving packages for ARM clients

With its default configuration, Flexo only serves packages from the official ArchLinux mirrors, which means packages built for x86. However, we can configure an ARM mirror as a custom_repo in order to fetch ARM packages from Flexo.

First, visit https://archlinuxarm.org/about/mirrors and choose a mirror. Once you have decided for an ARM mirror, configure it as a custom_repo in your /etc/flexo.toml. In this example, we have chosen the mirror de3.mirror.archlinuxarm.org and we have given it the name arm:

[[custom_repo]]
name = "arm"
url = "https://de3.mirror.archlinuxarm.org"

Next, configure the mirrorlist on all clients that are going to fetch ARM packages from this server. For example, if the server that runs Flexo should fetch the package from Flexo, configure your /etc/pacman.d/mirrorlist as follows:

Server = http://localhost:7878/custom_repo/arm/$arch/$repo

Attributes & Design Goals

Contribute

If you know Rust, feel free to dive into the code base and send a PR. Smaller improvements to make the code base cleaner, more idiomatic or efficient are always welcome. Before submitting larger changes, including new features or design changes, you should first open an issue to see if that feature is desired and if it fits into the design goals of Flexo.

Other than code, you can contribute by submitting feedback. One aspect of Flexo where feedback is particularly valuable is the mirror selection process. If you notice that downloads are too slow because the selected mirrors are not fast, please open an issue. You can determine the primary mirror chosen by Flexo with the journal:

journalctl --since '7 days ago' --unit=flexo | grep 'Primary mirror'

Development

Details about design decisions, and the terminology used in the code, are described here.

Before submitting a PR, please run cargo test inside the flexo directory to make sure that all tests pass.