Local Gentoo repository

Gentoo already contains many packages, but not all. Installing packages that are not (yet/anymore) part of the official Gentoo repositories can of course be done outside of the Gentoo package manager portage, but that might mess up things. Luckily, Gentoo allows for local repositories that can work in the same manner as the standard Gentoo repos.

This blog post describes how to create a local repo, and how to host the own Gentoo repositiory on Gitlab, so that it can also be shared with others, or between other own computers.

Approach

There is a Gentoo wiki article about creating local repositories. It describes how to set this up as root in a target directory, e.g. /var/db/repos/localrepo. That works of course, and that's how I have been using local repos. However, if I want to share this repo between computers, or make it available to others, then I end up copying stuff around, duplicating, etc.

Using a public git repository resolves this issue, and allows me to:

  • creating an ebuild as normal user and pushing it to a public git repository
  • pulling it as root from the public repository on one or more computers, or by others.

Creating the source

All my source files are under ~/src/, so:

$ mkdir ~/src/gentoo-repo-hf

Create or copy the neccessary ebuilds, with metadata and manifests there, e.g.

$ cd ~/src/gentoo-repo-hf
$ mkdir -p ~/src/gentoo-repo-hf/net-wireless/iwdgui
$ cd ~/src/gentoo-repo-hf/net-wireless/iwdgui 
$ cp /var/db/localrepo/net-wireless/iwdgui*.ebuild .
$ cp /var/db/localrepo/net-wireless/metadata.xml .
$ pkgdev manifest
$ pkgcheck scan

Fix any errors.

In this case I used the ebuilds that were already in my original local repo. Do this for all the packages.

Create a public git repository

This can be done with Gitlab, or Github, or any other public git repository. In my case I use Gitlab. Create a new project, in my case hfernh/gentoo-repo-hf. Make it public so that no one needs to login to use it.

Push the source to the git repo

Any public git repo should have at least have a README.md:

# Gentoo-repo-hf

This Gentoo repository contains some of my own developments, and some ebuilds
that are not part of the offical Gentoo repos.

## Own developments

- app-admin/krapplet (KeyRing applet): a password manager based on Gnome keyring
- net-wireless/iwdgui: a graphical user interface for Intel's IWD, for wifi management

## Other ebuilds

- app-text/pelican_injector: a plugin for the Pelican static website configurator

Then initialize the source folder for use with git, and push overything:

$ git init --initial-branch=main
$ git remote add origin git@gitlab.com:hfernh/gentoo-repo-hf.git
$ git add .
$ git commit -m "Initial commit"
$ git push --set-upstream origin main

Configure Gentoo to use the repo

The command:

# eselect repository create gentoo-repo-hf

creates a directory /var/db/repos/gentoo-repo-hf, and configures this directory as a local repo.

The entry in /etc/portage/repos.conf/eselect-repo.conf needs to updated with the upstream source on Gitlab:

# created by eselect-repo

[gentoo]
location = /var/db/repos/gentoo
sync-type = git
sync-uri = https://github.com/gentoo-mirror/gentoo.git

[gentoo-repo-hf]
location = /var/db/repos/gentoo-repo-hf
sync-type = git
sync-uri  = https://gitlab.com/hfernh/gentoo-repo-hf.git

Trying to emerge --sync now yields errors:

>>> Syncing repository 'gentoo-repo-hf' into '/var/db/repos/gentoo-repo-hf'...
/usr/bin/git clone --depth 1 https://gitlab.com/hfernh/gentoo-repo-hf.git .
fatal: destination path '.' already exists and is not an empty directory.
!!! git clone error in /var/db/repos/gentoo-repo-hf
fatal: not a git repository (or any of the parent directories): .git

Cleaning out the target directory will resolve this issue:

# rm -rf /var/db/repos/gentoo-repo-hf/*
# emerge --sync
>>> Syncing repository 'gentoo' into '/var/db/repos/gentoo'...
/usr/bin/git fetch origin --depth 1
remote: Total 0 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
/usr/bin/git reset --merge refs/remotes/origin/stable
=== Sync completed for gentoo
>>> Syncing repository 'gentoo-repo-hf' into '/var/db/repos/gentoo-repo-hf'...
/usr/bin/git clone --depth 1 https://gitlab.com/hfernh/gentoo-repo-hf.git .
Cloning into '.'...
remote: Enumerating objects: 35, done.
remote: Counting objects: 100% (35/35), done.
remote: Compressing objects: 100% (29/29), done.
remote: Total 35 (delta 8), reused 0 (delta 0), pack-reused 0 (from 0)
Receiving objects: 100% (35/35), 6.64 KiB | 6.64 MiB/s, done.
Resolving deltas: 100% (8/8), done.
=== Sync completed for gentoo-repo-hf

Success.

Pages