1
0
Fork 0
nixos/load-asuna-vm

48 lines
1.7 KiB
Bash
Executable File

#! /usr/bin/env bash
set -e
# Download with curl or wget.
function download () {
if command -v curl >/dev/null; then
curl -L "$1"
elif command -v wget >/dev/null; then
wget -qO- "$1"
else
exit 1
fi
}
if [ -e /nix ]
then
# Enable nix commands.
if ! command -v nix >/dev/null; then
if ! [ -e ~/.nix-profile/etc/profile.d/nix.sh ]; then
download https://nixos.org/nix/install | sh -s
fi
# shellcheck disable=SC1090
. ~/.nix-profile/etc/profile.d/nix.sh
fi
# Don't lock the host display on a GNOME host (for lab machines).
if command -v gsettings >/dev/null; then
gsettings set org.gnome.desktop.screensaver lock-enabled false
gsettings set org.gnome.settings-daemon.plugins.power idle-dim false
fi
# Set max open FDs to host hard limit.
ulimit -n "$(ulimit -H -n)"
# Build and boot asuna.
exec "$(nix build "path:$(realpath "$(dirname "$0")")#nixosConfigurations.asuna.config.system.build.vm" --no-write-lock-file --recreate-lock-file --no-link --print-out-paths)"/bin/run-asuna-vm "$@"
else
git -C "$(realpath "$(dirname "$0")")" pull
# Enable flakes and nix command.
mkdir -p ~/.nix/etc/nix
echo -e "experimental-features = nix-command flakes\nmax-jobs = auto" > ~/.nix/etc/nix/nix.conf
# Ensure nix-user-chroot is present.
if ! [ -e "$HOME/nix-user-chroot-bin-1.2.2-x86_64-unknown-linux-musl" ]; then
download "https://github.com/nix-community/nix-user-chroot/releases/download/1.2.2/nix-user-chroot-bin-1.2.2-x86_64-unknown-linux-musl" > "$HOME/nix-user-chroot-bin-1.2.2-x86_64-unknown-linux-musl"
chmod +x "$HOME/nix-user-chroot-bin-1.2.2-x86_64-unknown-linux-musl"
fi
# Enter nix environment.
exec "$HOME/nix-user-chroot-bin-1.2.2-x86_64-unknown-linux-musl" ~/.nix "$0" "$@"
fi