Skip to content

Instantly share code, notes, and snippets.

@lpenz lpenz/nix-enter
Last active Mar 26, 2017

Embed
What would you like to do?
Enter a shell with ~/nix privately mounted in /nix, using mount namespaces. sudo required
#!/bin/bash
set -e -x
TMP=$(mktemp)
trap 'rm -f $TMP' EXIT
chmod u+x "$TMP"
cat > "$TMP" <<END
sudo mkdir /nix
sudo mount -n -o bind $HOME/nix /nix
if [ -f "$HOME/.nix-profile/etc/profile.d/nix.sh" ]; then
. "$HOME/.nix-profile/etc/profile.d/nix.sh"
fi
END
if [ "$#" = 0 ]; then
echo "$@" >> "$TMP"
else
echo "$SHELL -i" >> "$TMP"
fi
sudo unshare -m -- sudo -u "$USER" "$TMP"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.