Last active
March 26, 2017 18:53
-
-
Save lpenz/81e388590adfb20fcb26affae03c96b2 to your computer and use it in GitHub Desktop.
Enter a shell with ~/nix privately mounted in /nix, using mount namespaces. sudo required
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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