Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix root shell (Fixes #51) #53

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ in
extraGroups = [ "root" ];
};

security.sudo.wheelNeedsPassword = false;
security.sudo = {
extraConfig = ''
Defaults env_keep+=INSIDE_NAMESPACE
'';
wheelNeedsPassword = false;
};

# Disable systemd units that don't make sense on WSL
systemd.services."serial-getty@ttyS0".enable = false;
Expand Down
16 changes: 10 additions & 6 deletions syschdemd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -e

sw="/nix/var/nix/profiles/system/sw/bin"
systemPath=`${sw}/readlink -f /nix/var/nix/profiles/system`
systemPath=$(${sw}/readlink -f /nix/var/nix/profiles/system)

# Needs root to work
if [[ $EUID -ne 0 ]]; then
Expand All @@ -19,16 +19,16 @@ 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
/run/current-system/sw/bin/pgrep -xf systemd >/run/systemd.pid

# Wait for systemd to start
status=1
while [[ $status -gt 0 ]]; do
$sw/sleep 1
status=0
$sw/nsenter -t $(< /run/systemd.pid) -p -m -- \
$sw/systemctl is-system-running -q --wait 2>/dev/null \
|| status=$?
$sw/nsenter -t $(</run/systemd.pid) -p -m -- \
$sw/systemctl is-system-running -q --wait 2>/dev/null ||
status=$?
done
fi

Expand All @@ -40,4 +40,8 @@ if [[ $# -gt 0 ]]; then
else
cmd="$userShell"
fi
exec $sw/nsenter -t $(< /run/systemd.pid) -p -m -- $sw/machinectl -q --uid=@defaultUser@ shell .host /bin/sh -c "cd \"$PWD\"; exec $cmd"
if [ -z "${INSIDE_NAMESPACE:-}" ]; then
exec $sw/nsenter -t $(< /run/systemd.pid) -p -m -- $sw/machinectl -q --uid=@defaultUser@ shell .host /bin/sh -c "export INSIDE_NAMESPACE=true; cd \"$PWD\"; exec $cmd"
else
exec $cmd
fi