/nix-guix-gentoo

Gentoo overlay for nix and guix functional package managers.

Primary LanguageShell

Nix and Guix for Gentoo

Gentoo overlay for Nix and GNU Guix functional package managers.

Enabling the overlay

First, let's enable the overlay. We can either use the eselect-repository method:

# Install eselect-repository if you don't already have it
emerge app-eselect/eselect-repository
# Fetch and output the list of overlays
eselect repository list
eselect repository enable nix-guix

or we can use the layman method:

# Add important USE flags for layman to your package.use directory:
echo "app-portage/layman sync-plugin-portage git" >> /etc/portage/package.use/layman
# Install layman if you don't already have it
emerge app-portage/layman
# Rebuild layman's repos.conf file:
layman-updater -R
# Add the ::nix-guix overlay:
layman -a nix-guix

Finally, we need to unmask the overlay (this does not apply if your system is already running ~arch):

# Unmask ~testing versions for your arch:
echo "*/*::nix-guix" >> /etc/portage/package.accept_keywords

Setup

Nix

Installation

The installation follows typical process of installing a daemon in gentoo:

emerge nix
# on system systems:
systemctl enable nix-daemon && systemctl start nix-daemon
# on openrc systems:
rc-update add nix-daemon && /etc/init.d/nix-daemon start

Then relogin as your user to import profile variables and pull in package definitions:

nix-channel --add https://nixos.org/channels/nixpkgs-unstable
nix-channel --update

Next steps to try nix in action:

Guix

Installation

The installation follows typical process of installing a daemon in gentoo:

emerge guix
# on system systems:
systemctl enable guix-daemon && systemctl start guix-daemon
# on openrc systems:
rc-update add guix-daemon && /etc/init.d/guix-daemon start

First run

Upon first package installation Guix will create ~/.guix-profile symlink to /var/guix/profiles/per-user/${USER} (where ${USER} is your user account name in current shell).

In order to allow Guix to set all variables correctly execute those commands:

export GUIX_PROFILE="${HOME}/.guix-profile"
export GUIX_LOCPATH="${GUIX_PROFILE}/lib/locale"
source "${GUIX_PROFILE}/etc/profile"

The best way is to add the commands to your ${SHELL} profile file: ~/.profile / ~/.bash_profile / ~/.zprofile or equivalent.

To install a GNU hello package to test out Guix execute:

guix package -i hello

If you plan to use guix pull (and you probably are) you'll need to add it's PATH to your shell as well by following guix pull's suggestion:

export PATH="$HOME/.config/guix/current/bin:$PATH"
export INFOPATH="$HOME/.config/guix/current/share/info:$INFOPATH"

Next steps to try guix in action:

Known problems and workarounds

Ideally the above setup should Just Work. In practice sometimes bugs happen outside nix or guix environments. When they come up and are not yet fixed upstream we will list them here with possible workarounds.

Environment variables breaking emerge

The symptom

/usr/sbin/gtk-encode-symbolic-svg: symbol lookup error: /guix/...-glibc-2.33/lib/libpthread.so.0:
  undefined symbol: __libc_pthread_init, version GLIBC_PRIVATE

This usually means your current environment contains unhandled variables. You can look at env output to find which ones mention /nix/* or /gnu/* store paths. Those are primary suspects.

Known problematic variables:

  • none so far

Past examples:

The workaround

Once you figured out what variable causes problems you can add it to the list of ENV_UNSET variables in /etc/portage/make.conf. For example if it was a FOO_VARIABLE:

# /etc/portage/make.conf
#  can be removed once fix lands in ::gentoo:
#     https://bugs.gentoo.org/...
ENV_UNSET="${ENV_UNSET} FOO_VARIABLE"

Longer term fix

Longer term those variables should be reported in ::gentoo. See Past examples below for possible reports and fixes.

Pending fixes:

  • none so far.

Past examples:

Detailed description

Some nixpkgs and guix packages set various environment variables to redirect library loading from a default location to version-specific directory. Usually it is done via scripts wrapping binaries. For example firefox is a shell script that sets LD_LIBRARY_PATH, XDG_DATA_DIRS, GIO_EXTRA_MODULES, PATH and then calls .firefox-wrapped ELF executable.

Wrappers like that are usually contained to the wrapped program and don't normally cause problems to other packages. Unless such packages are able to spawn shells on their own. For example konsole exports QT_PLUGIN_PATH in it's wrapper. Another typical example is PATH variable.

The problem is not specific to nixpkgs or guix. Those are just most extensive environment variable users with many parallel incompatible environments available.

Normally emerge filters out problematic user variables by using profiles' defaults specificed in ENV_UNSET in ::gentoo repository. For example it's current value is:

gentoo $ git grep ENV_UNSET | tr ' ' $'\n'

profiles/base/make.defaults:ENV_UNSET="DBUS_SESSION_BUS_ADDRESS
DISPLAY
CARGO_HOME
GDK_PIXBUF_MODULE_FILE
XAUTHORITY
XDG_CACHE_HOME
XDG_CONFIG_HOME
XDG_DATA_HOME
XDG_STATE_HOME
XDG_RUNTIME_DIR
PERL_MM_OPT
PERL5LIB
PERL5OPT
PERL_MB_OPT
PERL_CORE
PERLPREFIX
GOBIN
GOPATH"

Some (many!) variables are not yet filtered by it. They are either handled by portage explicitly (like PATH variables) or not handled at all.