bin: add bwrap script to run Nix unpriviledged
This commit is contained in:
parent
7a47e6d184
commit
5ea34e5676
1 changed files with 61 additions and 0 deletions
61
bin/bwrap.bash
Executable file
61
bin/bwrap.bash
Executable file
|
@ -0,0 +1,61 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
if [ -z ${NIXDIR+x} ]; then
|
||||||
|
echo "NIXDIR is unset! It needs to be set in the code. Edit this shell file and read the instructions."
|
||||||
|
echo "Executing bash without Bubblewrap…"
|
||||||
|
exec bash
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -e $NIXDIR ]; then
|
||||||
|
echo "NIXDIR doesn't point to a valid location! Falling back to Bash"
|
||||||
|
exec bash
|
||||||
|
fi
|
||||||
|
|
||||||
|
_bind() {
|
||||||
|
_bind_arg=$1
|
||||||
|
shift
|
||||||
|
for _path in "$@"; do
|
||||||
|
args+=("$_bind_arg" "$_path" "$_path")
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
bind() {
|
||||||
|
_bind --bind-try "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
robind() {
|
||||||
|
_bind --ro-bind-try "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
devbind() {
|
||||||
|
_bind --dev-bind-try "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
args=(
|
||||||
|
--bind $NIXDIR /nix
|
||||||
|
--chdir $HOME
|
||||||
|
)
|
||||||
|
|
||||||
|
bind \
|
||||||
|
$HOME
|
||||||
|
|
||||||
|
devbind \
|
||||||
|
/dev \
|
||||||
|
/proc \
|
||||||
|
/tmp \
|
||||||
|
/run \
|
||||||
|
/u \
|
||||||
|
/p \
|
||||||
|
/bin \
|
||||||
|
/boot \
|
||||||
|
/etc \
|
||||||
|
/home \
|
||||||
|
/lib \
|
||||||
|
/lib32 \
|
||||||
|
/lib64 \
|
||||||
|
/libx32 \
|
||||||
|
/media \
|
||||||
|
/usr \
|
||||||
|
/var
|
||||||
|
|
||||||
|
exec bwrap "${args[@]}" "$@"
|
Loading…
Add table
Add a link
Reference in a new issue