Skip to the text
KDOS
Menu
kdos.dev KDOS from Scratch KDOS 0.2 · 4dd4a10 · 2026-11-30 Contents Index

91.4. direnv-2.37.1

Loads and unloads environment variables per directory

Version 2.37.1, release 1
Shelf shells — Interactive shells and their add-ons, terminal multiplexers, and terminal emulators
Phase 41_system (System), 949 of 1047 in build order
Licence MIT
Homepage https://direnv.net/
Build time 0.2 SBU
Installed size 9.6 MiB in 7 files
Recipe ports/core/shells/direnv/kpkgbuild

About

direnv loads and unloads environment variables as the shell enters and leaves a directory: a .envrc in a project directory is run by bash, once it has been allowed with direnv allow, and the variables it exports are removed again when the shell leaves the directory. The port installs the direnv binary, its manual pages and upstream’s fish hook in /usr/share/fish/vendor_conf.d/direnv.fish, which turns it on in every fish shell. The system bash.bashrc does not hook it, so a bash user adds eval "$(direnv hook bash)" to their own ~/.bashrc.

Sources

Dependencies

Depends on: go.

Required by: no port names it.

Installation

From the repository root, inside the build container, this is the line kdosbuild runs for the port:

script/chroot/exec.sh bash -c 'source script/phases/41_system/phase.env && kpkg install direnv'

What kpkg does

kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/shells/direnv.

1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.

cd /ports/core/shells/direnv
echo '4142fbb661f3218913fac08d327c415e87b3e66bd0953185294ff8f3228ead24  direnv-2.37.1.tar.gz' | sha256sum -c -
echo 'cc67cc3618e147be55a87625c69626e0c78535e173881d495547c410f6756b59  direnv-vendor-2.37.1.tar.xz' | sha256sum -c -

2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.

SRC_ROOT=/var/cache/kpkg/work/direnv
SRC=$SRC_ROOT/direnv-2.37.1
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf direnv-2.37.1.tar.gz -C "$SRC" --strip-components=1

Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.

3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:

tar xf $PORT_SRC/${name}-vendor-${version}.tar.xz

export CGO_ENABLED=0
make GO_LDFLAGS="-s -w"
make GO_LDFLAGS="-s -w" DESTDIR=$PKG PREFIX=/usr install

The switches, and why each is set:

The common switches of each build system are explained in the Flag glossary.

4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/direnv, prunes what the image does not ship, lints the tree and rolls it reproducibly:

tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
    --mtime=@$SOURCE_DATE_EPOCH \
    --use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
    -cf direnv-2.37.1-1.tar.xz -C "$PKG" .

5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/direnv, and runs the triggers its paths call for.

Contents

Installed programs: direnv.

Installed directories: /usr/share/fish/vendor_conf.d, /usr/share/licenses/direnv.

Short descriptions

direnv unclutter your .profile

Notes

The Go modules come from the vendor bundle, direnv-vendor-<version>.tar.xz, which ports/fetch makes with go mod vendor and which build.sh unpacks into the top of the source tree (see Vendoring). The makefile’s go build names no -mod=vendor: with vendor/modules.txt present and a go.mod that asks for Go 1.14 or later, the go command builds from vendor/ by default, and the build has no network to reach a module proxy in any case.