#!/usr/bin/env bash
# Nix installation script for TemplateVM. Run as user.
set -ev # Print commands and exit on error

sudo dnf install -y xz

sh <(curl --proto '=https' --tlsv1.2 -L https://nixos.org/nix/install) --daemon --yes

sudo mkdir -p /etc/skel/.local/state/nix/
sudo ln -s /nix/var/nix/profiles/default /etc/skel/.local/state/nix/profile
# You might want to setup for TemplateVM user too
mkdir -p ~/.local/state/nix/
ln -s /nix/var/nix/profiles/default ~/.local/state/nix/profile

echo "test -f /home/user/.local/state/nix/profile/etc/profile.d/nix.sh && source /home/user/.local/state/nix/profile/etc/profile.d/nix.sh" | sudo tee -a /etc/skel/.bashrc
# You might want to setup for TemplateVM user too
echo "test -f /home/user/.local/state/nix/profile/etc/profile.d/nix.sh && source /home/user/.local/state/nix/profile/etc/profile.d/nix.sh" | tee -a ~/.bashrc

sudo dnf remove -y xz
