-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnix.sh
44 lines (37 loc) · 870 Bytes
/
nix.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
set -e
# Function to check if a command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Install Nix
install_nix() {
echo "Installing Nix..."
if command_exists nix; then
echo "Nix is already installed."
else
sh <(curl -L https://nixos.org/nix/install) --daemon
# Source nix
. ~/.nix-profile/etc/profile.d/nix.sh
fi
}
# Install Ansible using Nix
install_ansible_with_nix() {
echo "Installing Ansible using Nix..."
nix-env -iA nixpkgs.ansible
}
# Main execution
main() {
install_nix
install_ansible_with_nix
# Verify installation
if command_exists ansible; then
echo "Ansible has been successfully installed using Nix."
ansible --version
else
echo "Ansible installation failed."
exit 1
fi
}
# Run the main function
main