Garuda-Config-Agent: The way Garuda Linux default configurations are handled is changing!

The Problem

A lot of us forum people probably know of this scenario:

  1. User is unfamiliar with .pacnew files
  2. User follows distro instructions and merges /etc/pacnew.conf.pacnew into /etc/pacman.conf
  3. But there’s a twist! The user merged the files incorrectly or just copied the pacnew file to the pacman configuration file without merging.
  4. Their system breaks because the garuda, multilib and chaotic-aur repos are no longer enabled.

Over the time, we’ve shipped tools like garuda-health that can automatically recover systems from such a state, but it’s not ideal.

The core problem comes down to this: Garuda Linux applies configuration changes on top of configuration files that Arch Linux ships. When a package is then updated, a .pacnew file is created without any of the custom Garuda Linux configuration changes.

The average user in many cases simply also does not have the knowledge about why certain config settings have been set by the Garuda Linux team/community and might therefore not know if any individual change should be merged or kept.

The Solution

The solution comes down to this: Intercept any new .pacnew files and apply Garuda Linux configurations to them automatically. Then, when merging, the user does not have to worry about preserving the Garuda Linux specific configs and instead only has to worry about their own configuration changes (which they will be much more familiar with and therefore less likely to make mistakes).

In addition, we are also able to detect when configuration files have remained unchanged by the user and automatically merge the pacnew file for them (but this will not take effect retroactively, the benefit of this will only be seen on new systems).

It’s a little more complicated than that, but that’s the basic gist.

Regex knows no limits

All this is implemented using a Python-based regex replacement system that allows for very dynamic and pretty bulletproof changes to the config files. Using a sqlite3 database, the agent is aware of changes that were previously made and will not apply those same changes again, preventing the agent from accidentally setting a setting that the user explicitly disabled earlier, for example.

Here is what the configuration files ingested by garuda-config-agent look like:

# Which file is being edited?
targetFile: "/etc/pacman.conf"
# A system that was grandfathered in from before garuda-config-agent
# existed will receive this "order" by default.
legacyPatchLevel: 4

pipeline:
  # The order signals first of all which order the operations are called in,
  # but also prevents an operation from being executed twice.
  - order: 0
    # operation or revert. Operations are always performed,
    # Reverts are only performed on "not new" files to undo a previous operation
    type: operation
    # The regex pattern
    pattern: "^#Color"
    # What to replace it with
    substitution: "Color"

  - order: 1
    type: operation
    pattern: "^#VerbosePkgLists"
    substitution: |-
      VerbosePkgLists
      ILoveCandy

  # Add garuda repo
  - order: 2
    type: operation
    # More complicated regex patterns allow making sure only one single
    # Garuda repo exists, for example.
    pattern: '(\[options\](?:(?!\n\[garuda\])[\s\S])*?)(^\[(?!options\]|garuda\]).*?\])'
    substitution: |-
      \1
      [garuda]
      Include = /etc/pacman.d/chaotic-mirrorlist
      
      \2

  # Enable multilib
  - order: 3
    type: operation
    # Multiline patterns are supported natively
    pattern: |-
      ^#\[multilib\]
      #Include = /etc/pacman.d/mirrorlist
    substitution: |-
      [multilib]
      Include = /etc/pacman.d/mirrorlist

  # Add chaotic-aur
  - order: 4
    type: operation
    # Only add new chaotic-aur repo if no other chaotic-aur repo exists
    # in the rest of the file.
    pattern: |-
      (\[multilib\]\s+Include = /etc/pacman.d/mirrorlist)(?!\s*\[chaotic-aur\])
    substitution: |-
      \1
      
      [chaotic-aur]
      Include = /etc/pacman.d/chaotic-mirrorlist

I need YOU to help test

garuda-config-agent will be shipping in the next ISO refresh (and also the next distro release) as well as being automatically installed on existing systems.

You can install garuda-config-agent like so:

garuda-update -- garuda-config-agent

Then you could for example force the creation of a pacnew file as a test:

sudo touch /etc/pacman.conf.pacnew
sudo pacman -S pacman

Which should show some output along the lines of

( 1/11) Updating configurations with garuda-config-agent...
Pacnew file detected for /etc/pacman.conf. Applying pipeline...
[0] Applying operation...
[1] Applying operation...
[2] Applying operation...
[3] Applying operation...
[4] Applying operation...
Updated /etc/pacman.conf.pacnew

Afterward, the /etc/pacman.conf.pacnew file should contain the default Garuda Linux configuration changes.

You can see which configuration files are currently supported here:

That should be all non-edition specific files, I believe, but there are probably some more I have missed.

Go wild

I need you all to find things I have not thought of! Thanks!

16 Likes

Amazing work again. :blue_heart:

3 Likes

Pushed an update. Whenever you overwrite the config file with the pacnew version of the config file (not merge, just straight move the pacnew to main), garuda-config-agent will detect this and re-enable auto merge.

6 Likes

I literally just now figured out how to merge with meld successfully. But if the process can be somewhat automated I wouldn’t say no to this.

2 Likes

Naaah you’re right. Let’s be elitist and laugh at people who have not yet figured it out. (this will encourage them to learn, obviously)

6 Likes

garuda-config-agent now properly works when built into ISOs

Here’s a test ISO where the config stuff is done using garuda-config-agent:

I’ve also added the ability to disable auto merging to the yaml files for cases where auto merging might not be productive like /etc/default/grub.

4 Likes

garuda-config-agent is now officially rolling out to existing systems! :tada:

12 Likes

Looks right? No idea what it did, but it did it. I seem to have a mental block about pacnew, etc so this is great if it increases efficiency and makes EVE Online run smoother lol

Is there something I should look for, or is this one and done?

:: Processing package changes…
(1/1) reinstalling pacman [---------------------------------------------] 100%
:: Running post-transaction hooks…
( 1/11) Updating configurations with garuda-config-agent…
[/etc/pacman.conf.pacnew] Applying full pipeline…
→ [0] Applying operation…
→ [1] Applying operation…
→ [2] Applying operation…
→ [3] Applying operation…
→ [4] Applying operation…
[/etc/pacman.conf.pacnew] Pipeline applied successfully.
( 2/11) Creating system user accounts…

webmin + squid + apache

First off, THANK YOU for this brilliant upgrade to an already amazing distro.
I ran your 2 commands after updating and was surprised it found pacman dependency issues. Is all this (below) normal and expected?

**󰛓** ❯ paru garuda-config-agent 
1 **garuda**/**garuda-config-agent** **1.0.0-1** \[**0 B 13.77 KiB**\] **\[Installed\]** 
Applies and manages system configuration changes 
**::** **Packages to install (eg: 1 2 3, 1-3):** 
**::** ^C⏎                                                                                                                         
 
**dma**@**HP-AIO** in **\~** took **41s989ms** 
**\[󰟾\]** **󰛓**  sudo touch /etc/pacman.conf.pacnew 
sudo pacman -S pacman 
\[sudo\] password for dma: 
**warning:** pacman-7.1.0.r7.gb9f7d4a-1 is up to date -- reinstalling 
resolving dependencies... 
looking for conflicting packages... 
 
**Package (1)**  **Old Version**          **New Version**          **Net Change**  **Download Size** 
 
core/pacman  7.1.0.r7.gb9f7d4a-1  7.1.0.r7.gb9f7d4a-1    0.00 MiB       0.94 MiB 
 
**Total Download Size:**   0.94 MiB 
**Total Installed Size:**  5.01 MiB 
**Net Upgrade Size:**      0.00 MiB