Skip to content

Commit

Permalink
improvement(distrobox): expose Nix profiles to distrobox-init
Browse files Browse the repository at this point in the history
This results in faster provisioning of new Distrobox containers because
the commands Distrobox needs would be more likely to be available,
eliminating the need to download additional packages.
  • Loading branch information
midchildan committed Jul 12, 2023
1 parent 9559f12 commit 4cb49a1
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions files/.local/libexec/distrobox/nix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,31 @@

case "$1" in
preinit)
if [ -d /run/host/run/current-system ]; then
mount_bind /run/host/run/current-system /run/current-system ro
fi
if [ -d /run/host/etc/nix ]; then
mount_bind /run/host/etc/nix /etc/nix ro
fi

# Expose commands in Nix profiles to Distrobox so that it can find whatever
# command it needs that's missing from the container image. This greatly
# improves the initial startup time because it can then skip installing
# missing packages.
PATH="$PATH:$HOME/.nix-profile/bin:/run/current-system/sw/bin"

# make sure it's initialized before the init hook references it
dot_shell=''

case "$(realpath "$SHELL" 2> /dev/null || :)" in
/nix/store/*|/gnu/store/*) ;;
*) return ;;
/nix/store/*|/gnu/store/*)
if ! [ -x "$SHELL" ]; then
return
fi
;;
*)
return
;;
esac

# Backup SHELL because distrobox changes it.
Expand All @@ -19,10 +39,6 @@ case "$1" in
;;

init)
if [ -d /run/host/etc/nix ]; then
mount_bind /run/host/etc/nix /etc/nix ro
fi

if [ -z "$dot_shell" ] || [ "$SHELL" = "$dot_shell" ]; then
return
fi
Expand Down

0 comments on commit 4cb49a1

Please sign in to comment.