Simple steps to create Gentoo custom repository and add a package

Creating a custom repository would give you a chance to fast edit (ebuild) files of existing packages and drop better versions to the custom repository, which then will be used to install in the system. Here is the simplest way to create a Gentoo custom repository without installing any mandatory software. You may check the two Gentoo articles on the subject – https://wiki.gentoo.org/wiki/Custom_repository, which uses repoman (and additional software to install) and https://wiki.gentoo.org/wiki/Handbook:AMD64/Portage/CustomTree#Defining_a_custom_repository, which is part of a bigger article and without a clear example with a package as we are going to show.
Our custom repository name is “my-local-portage”.

STEP 1) Create the directories and basic configuration files for the new custom repository

Just two mandatory directories.

mkdir -p /var/db/repos/my-local-portage/{metadata,profiles}

The minimal configuration in two files:

cat  << 'EOF' > /var/db/repos/my-local-portage/metadata/layout.conf
masters = gentoo
auto-sync = false
EOF
cat  << 'EOF' > /var/db/repos/my-local-portage/profiles/repo_name
my-local-portage
EOF

Fix the permissions

chown -R portage:portage /var/db/repos/my-local-portage

The custom repository is set up. Now only the emerge should get the configuration to check for it in the next step.

STEP 2) Portage global configuration.

Add a file pointing for your custom repository in the Portage global configuration directory “/etc/portage”:

cat  << 'EOF' > /etc/portage/repos.conf/my-local-portage.conf
[my-local-portage]
location = /var/db/repos/my-local-portage
EOF

STEP 3) Add a package in the new custom repository.

The package version may be the same version as in the official Gentoo repository, but the package form the custom repository will be used if no repository is included in the “emerge” command.
For simplicity, we are going not to modify the ebuild file of a copied official package, but the idea is to copy an existing ebuild file and then change it for the user’s needs and the steps are the same as follow.
Just copy the file (and edit it). The package “app-text/calibre” was randomly selected for the example.

mkdir /var/db/repos/my-local-portage/app-text/calibre
cp /usr/portage/app-text/calibre/calibre-4.9.1-r1.ebuild /var/db/repos/my-local-portage/app-text/calibre/

Create the manifest files and you are ready:

cd /var/db/repos/my-local-portage/app-text/calibre/
ebuild calibre-4.9.1-r1.ebuild manifest
>>> Downloading 'ftp://ftp.free.fr/mirrors/ftp.gentoo.org/distfiles/2e/calibre-4.9.1.tar.xz'
--2020-02-06 18:04:59--  ftp://ftp.free.fr/mirrors/ftp.gentoo.org/distfiles/2e/calibre-4.9.1.tar.xz
           => '/usr/portage/distfiles/calibre-4.9.1.tar.xz.__download__'
Resolving ftp.free.fr... 212.27.60.27, 2a01:e0c:1:1598::1
Connecting to ftp.free.fr|212.27.60.27|:21... connected.
Logging in as anonymous ... Logged in!
==> SYST ... done.    ==> PWD ... done.
==> TYPE I ... done.  ==> CWD (1) /mirrors/ftp.gentoo.org/distfiles/2e ... done.
==> SIZE calibre-4.9.1.tar.xz ... 37529656
==> PASV ... done.    ==> RETR calibre-4.9.1.tar.xz ... done.
Length: 37529656 (36M) (unauthoritative)

calibre-4.9.1.tar.xz                       100%[========================================================================================>]  35.79M  5.53MB/s    in 8.0s    

2020-02-06 18:05:08 (4.48 MB/s) - '/usr/portage/distfiles/calibre-4.9.1.tar.xz.__download__' saved [37529656]

>>> Creating Manifest for /var/db/repos/my-local-portage/app-text/calibre

Fix the permissions with

chown -R portage:portage /var/db/repos/my-local-portage

The manifest file contains the hash of the ebuild file and all the additional files if any (for this package there are no additional files). All file needed for the operation will be downloaded so they must be network accessed in the time of executing the command (except in the cases when they have already existed in the distfiles directory and/or the subdirectories of the /var/db/repos/my-local-portage/app-text/calibre)

cat Manifest 
DIST calibre-4.9.1.tar.xz 37529656 BLAKE2B 5d703ca0c398b43cc26a54e0628d0fe938c6a5027a4fd0c9cac83944e5143eb08439bf79b2098182be7727eaa042748f17866788b02c7744178dce131f6b1d1e SHA512 bf06aa3cbc8d255934f3f7f3ce20b4798edf107ed9f822943d2b4ae7d95473842928ed79f8ba7571f7e0ebdc267c441916d543d5b7630aae5cb151bcc3184b71
EBUILD calibre-4.9.1-r1.ebuild 8287 BLAKE2B b101adb4af4b9afa4b65acb34c131a1cb41d5d6079e5457ba3402ead5d3e7c5fd0caac101ae75367e4b658702f534d1aa8672e632c97950cbcde8e504cc7c54c SHA512 fa945bf73f846dc8b72e0e76a818289502745bfac6dc7ce42e31e5f58a04b3ee2bfc6c6b4e39bdb1b773cc9a61d455eb652c317e73ee542e9bcfeae573030a96

STEP 4) Install package from your custom repository

In this example, we even did not change the version of the package but the custom repository was used when no repository was added to the “emerge” command explicitly:

root@desktop ~ # emerge -va calibre

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild   R    ] app-text/calibre-4.9.1-r1::my-local-portage [4.9.1-r1::gentoo] USE="udisks -ios" PYTHON_SINGLE_TARGET="python3_6 -python2_7 -python3_7" PYTHON_TARGETS="python2_7 python3_6 -python3_7" 0 KiB

Total: 1 package (1 reinstall), Size of downloads: 0 KiB

Would you like to merge these packages? [Yes/No]

You see the “app-text/calibre-4.9.1-r1::my-local-portage“.

Note 1) If the version number is a lower number, the official repository will be used.

For example, if you rename the copied file from the official repository from calibre-4.9.1-r1.ebuild to calibre-4.8.1-r1.ebuild (and regenerate the manifest file) the official version will be used as the latest:

root@desktop ~ # emerge -va calibre

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild   R    ] app-text/calibre-4.9.1-r1::gentoo  USE="udisks -ios" PYTHON_SINGLE_TARGET="python3_6 -python2_7 -python3_7" PYTHON_TARGETS="python2_7 python3_6 -python3_7" 0 KiB

Total: 1 package (1 reinstall), Size of downloads: 0 KiB

Would you like to merge these packages? [Yes/No]

Note 2) Always regenerate the menifest files after changes, because you won’t be able to install it and en error is reported.

root@desktop ~ # emerge -va calibre

These are the packages that would be merged, in order:

Calculating dependencies / * Digest verification failed:
 * /var/db/repos/my-local-portage/app-text/calibre/calibre-4.9.1-r1.ebuild
 * Reason: Filesize does not match recorded size
 * Got: 8288
 * Expected: 8287                                                                                                                                                         ... done!
[ebuild   R    ] app-text/calibre-4.9.1-r1::gentoo  USE="udisks -ios" PYTHON_SINGLE_TARGET="python3_6 -python2_7 -python3_7" PYTHON_TARGETS="python2_7 python3_6 -python3_7" 0 KiB

Total: 1 package (1 reinstall), Size of downloads: 0 KiB

Would you like to merge these packages? [Yes/No]

One thought on “Simple steps to create Gentoo custom repository and add a package”

Leave a Reply

Your email address will not be published. Required fields are marked *