Added automatic Nix install if not present on system.

This commit is contained in:
ajasibley 2023-05-25 01:47:57 -07:00
parent 0f4c13fc43
commit 5bd0c41792
2 changed files with 41 additions and 1 deletions

View file

@ -1,5 +1,9 @@
scripts_dir := "scripts"
# Check if Nix is installed, if not install it based on the platform
install-nix: {{scripts_dir}}/install_nix.sh
@bash {{scripts_dir}}/install_nix.sh
# Check if Rust is installed, if not install it
install-rust:
@if ! command -v rustc &> /dev/null; then \
@ -28,4 +32,4 @@ install-cosmo:
. {{scripts_dir}}/update_path.sh; \
fi
all: install-rust install-wasm-target install-openssl install-cosmo
all: install-nix install-rust install-wasm-target install-openssl install-cosmo

36
scripts/install_nix.sh Normal file
View file

@ -0,0 +1,36 @@
#!/bin/bash
# Check if Nix is installed
if ! command -v nix --help >/dev/null 2>&1; then
# Delete problematic backup files for bash and zsh if they exist
if [ -f "/etc/bash.bashrc.backup-before-nix" ]; then
sudo rm -f /etc/bash.bashrc.backup-before-nix
fi
if [ -f "/etc/bashrc.backup-before-nix" ]; then
sudo rm -f /etc/bashrc.backup-before-nix
fi
if [ -f "/etc/zshrc.backup-before-nix" ]; then
sudo rm -f /etc/zshrc.backup-before-nix
fi
# Determine the platform (Linux or macOS)
case `uname` in
Linux*)
echo "Error: Nix package manager is not installed. Installing Nix for Linux..."
sh <(curl -L https://nixos.org/nix/install) --daemon
;;
Darwin*)
echo "Error: Nix package manager is not installed. Installing Nix for macOS..."
sh <(curl -L https://nixos.org/nix/install) --darwin-use-unencrypted-nix-store-volume
;;
*)
echo "Unsupported platform for Nix installation"
exit 1;
;;
esac
else
echo "Nix package manager is already installed."
fi