#!/bin/sh

# If we're not on a Guix system then we need to initialise our Guix profile
# and our user profile, and set some other environment variables.
if [ ! -e /run/current-system/profile/etc/profile ]; then
    export LANG=en_AU.UTF-8

    # XDG_DATA_DIRS often starts off empty, but an empty value is
    # interpreted as this value. Loading a profile can set it, though,
    # which effectively ignores the default value. We want it to
    # instead add to the default, so we set it here to the default
    # value.
    if [ -z "$XDG_DATA_DIRS" ]; then
        export XDG_DATA_DIRS="/usr/local/share/:/usr/share/"
    fi

    # We need to set a few environment variables so that Guix can do
    # some things (SSL and locale information).
    export SSL_CERT_DIR="$HOME/.guix-profile/etc/ssl/certs"
    export SSL_CERT_FILE="$HOME/.guix-profile/etc/ssl/certs/ca-certificates.crt"
    export GUIX_LOCPATH="$HOME/.guix-profile/lib/locale"

    # Load the profiles that we want.
    for profile in "$HOME/.config/guix/current" "$HOME/.guix-profile" "$HOME/.guix-home/profile"
    do
        export INFOPATH="$profile/share/info${INFOPATH:+:}$INFOPATH"
        if [ -f "$profile/etc/profile" ]
        then
            # Load the user profile's settings.
            GUIX_PROFILE="$profile";
            . "$profile/etc/profile"
            unset GUIX_PROFILE
        else
            # At least define this one so that basic things just work
            # when the user installs their first package.
            export PATH="$profile/bin:$PATH"
        fi
    done
fi
