From 6c71975bb6f254c3824c1a267b6e065040cd0687 Mon Sep 17 00:00:00 2001 From: maix Date: Fri, 16 Feb 2024 18:47:42 +0100 Subject: [PATCH] Add launch-nix --- launch-nix | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 launch-nix diff --git a/launch-nix b/launch-nix new file mode 100644 index 0000000..f91ef25 --- /dev/null +++ b/launch-nix @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +ADDITIONAL_BINDS= #"--bind $HOME /home/maix" +RUN_BWRAP="/usr/bin/bwrap --bind $(mktemp -d) / --dev-bind /dev /dev --bind /home/maiboyer/nix-location /nix --bind /usr/lib32 /lib32 --bind /usr/libx32 /libx32 --bind /osquery.flags /osquery.flags --bind /usr/lib64 /lib64 --bind /media /media --bind /root /root --bind /cdrom /cdrom --bind /sgoinfre /sgoinfre --bind /.cache /.cache --bind /var /var --bind /sys /sys --bind /usr/sbin /sbin --bind /boot /boot --bind /snap /snap --bind /usr/bin /bin --bind /.dumped /.dumped --bind /tmp /tmp --bind /opt /opt --bind /lost+found /lost+found --bind /usr /usr --bind /home /home --bind /usr/lib /lib --bind /run /run --bind /proc /proc --bind /mnt /mnt --bind /swap.img /swap.img --bind /etc /etc --bind /goinfre /goinfre --bind /srv /srv --bind /etc/host.conf /etc/host.conf --bind /etc/hosts /etc/hosts --bind /etc/networks /etc/networks --bind /etc/passwd /etc/passwd --bind /etc/group /etc/group --bind /etc/nsswitch.conf /etc/nsswitch.conf --bind /run/systemd/resolve/stub-resolv.conf /run/systemd/resolve/stub-resolv.conf --bind /usr/share/zoneinfo/Europe/Paris /usr/share/zoneinfo/Europe/Paris --bind $HOME $HOME $ADDITIONAL_BINDS --bind /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt" + +if [ -e '/nix' ]; then + echo "already in nix" >&2 + exit 0 +fi +if ! [ -e "$HOME/nix-location/store" ]; then + echo -n "installing nix..." >&2 + $RUN_BWRAP mkdir -p "/nix/var/nix/profiles/per-user/maiboyer/"; + $RUN_BWRAP -- /usr/bin/env /bin/sh -c 'curl -L https://nixos.org/nix/install | sh -s -- --no-daemon --no-modify-profile --yes' + echo "done" >&2 +fi + +if ! [ "$#" -eq 0 ]; then + CMD="$@" +else + CMD="$SHELL" +fi + + +exec $RUN_BWRAP -- /usr/bin/env $CMD \ No newline at end of file