#!/bin/bash set -e echo "Installing Nix package manager..." # Check if running as root if [ "$EUID" -ne 0 ]; then echo "Error: This script must be run as root" >&2 exit 1 fi # Install xz-utils if not present (required for decompressing Nix tarball) if ! command -v xz &> /dev/null; then echo "Installing xz-utils..." if command -v apt-get &> /dev/null; then sudo apt-get update && sudo apt-get install -y xz-utils elif command -v dnf &> /dev/null; then sudo dnf install -y xz elif command -v yum &> /dev/null; then sudo yum install -y xz elif command -v pacman &> /dev/null; then sudo pacman -S --noconfirm xz else echo "Please install xz-utils manually for your distribution" exit 1 fi fi # Download and run the Nix installer (multi-user mode with daemon) curl --proto '=https' --tlsv1.2 -L https://nixos.org/nix/install | sh -s -- --daemon # Source Nix profile if [ -f /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh ]; then . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh fi echo "Nix installation complete!" echo "Restart your shell or run: source /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh"