27 lines
874 B
Bash
27 lines
874 B
Bash
#! @shell@
|
|
|
|
set -e
|
|
|
|
sw="/nix/var/nix/profiles/system/sw/bin"
|
|
systemPath=`${sw}/readlink -f /nix/var/nix/profiles/system`
|
|
|
|
# Needs root to work
|
|
if [[ $EUID -ne 0 ]]; then
|
|
echo "[ERROR] Requires root! :( Make sure the WSL default user is set to root"
|
|
exit 1
|
|
fi
|
|
|
|
if [ ! -e "/run/current-system" ]; then
|
|
/nix/var/nix/profiles/system/activate
|
|
fi
|
|
|
|
if [ ! -e "/run/systemd.pid" ]; then
|
|
PATH=/run/current-system/systemd/lib/systemd:@fsPackagesPath@ \
|
|
LOCALE_ARCHIVE=/run/current-system/sw/lib/locale/locale-archive \
|
|
@daemonize@/bin/daemonize /run/current-system/sw/bin/unshare -fp --mount-proc systemd
|
|
/run/current-system/sw/bin/pgrep -xf systemd > /run/systemd.pid
|
|
fi
|
|
|
|
userShell=$($sw/getent passwd @defaultUser@ | $sw/cut -d: -f7)
|
|
exec $sw/nsenter -t $(< /run/systemd.pid) -p -m --wd="$PWD" -- @wrapperDir@/su -s $userShell @defaultUser@ "$@"
|