2018-02-05 19:41:54 +01:00
|
|
|
#! @shell@
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# Re-exec ourselves in a private mount namespace so that our bind
|
|
|
|
# mounts get cleaned up automatically.
|
2018-02-07 17:59:04 +01:00
|
|
|
if [ -z "$NIXOS_ENTER_REEXEC" ]; then
|
|
|
|
export NIXOS_ENTER_REEXEC=1
|
|
|
|
if [ "$(id -u)" != 0 ]; then
|
|
|
|
extraFlags="-r"
|
2018-02-05 19:41:54 +01:00
|
|
|
fi
|
2018-02-07 17:59:04 +01:00
|
|
|
exec unshare --fork --mount --uts --mount-proc --pid $extraFlags -- "$0" "$@"
|
|
|
|
else
|
|
|
|
mount --make-rprivate /
|
2018-02-05 19:41:54 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
mountPoint=/mnt
|
|
|
|
system=/nix/var/nix/profiles/system
|
2018-03-04 16:56:38 +01:00
|
|
|
command=($system/sw/bin/bash "--login")
|
2018-02-05 19:41:54 +01:00
|
|
|
|
|
|
|
while [ "$#" -gt 0 ]; do
|
|
|
|
i="$1"; shift 1
|
|
|
|
case "$i" in
|
|
|
|
--root)
|
|
|
|
mountPoint="$1"; shift 1
|
|
|
|
;;
|
|
|
|
--system)
|
|
|
|
system="$1"; shift 1
|
|
|
|
;;
|
|
|
|
--help)
|
|
|
|
exec man nixos-enter
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
--command|-c)
|
2018-03-04 16:56:38 +01:00
|
|
|
command=($system/sw/bin/bash "-c" "$1")
|
2018-02-05 19:41:54 +01:00
|
|
|
shift 1
|
|
|
|
;;
|
|
|
|
--)
|
|
|
|
command=("$@")
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "$0: unknown option \`$i'"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2018-02-07 17:23:05 +01:00
|
|
|
if [[ ! -e $mountPoint/etc/NIXOS ]]; then
|
|
|
|
echo "$0: '$mountPoint' is not a NixOS installation" >&2
|
|
|
|
exit 126
|
|
|
|
fi
|
|
|
|
|
2018-04-22 22:02:57 +02:00
|
|
|
mkdir -m 0755 -p "$mountPoint/dev" "$mountPoint/sys"
|
2018-02-05 19:41:54 +01:00
|
|
|
mount --rbind /dev "$mountPoint/dev"
|
2018-04-22 22:02:57 +02:00
|
|
|
mount --rbind /sys "$mountPoint/sys"
|
2018-02-05 19:41:54 +01:00
|
|
|
|
|
|
|
# Run the activation script. Set $LOCALE_ARCHIVE to supress some Perl locale warnings.
|
2018-02-07 17:59:04 +01:00
|
|
|
LOCALE_ARCHIVE=$system/sw/lib/locale/locale-archive chroot "$mountPoint" "$system/activate" >&2 || true
|
2018-02-05 19:41:54 +01:00
|
|
|
|
|
|
|
exec chroot "$mountPoint" "${command[@]}"
|