too much to mention
This commit is contained in:
79
setup.sh
79
setup.sh
@ -1,37 +1,64 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Check if nixos-version is available
|
||||
if [ -x "$(command -v nixos-version)" ]; then
|
||||
echo "Detected NixOS, skipping Nix setup."
|
||||
return
|
||||
else
|
||||
echo "NixOS not detected, installing Nix..."
|
||||
sh <(curl -L https://nixos.org/nix/install) --daemon
|
||||
fi
|
||||
NIXOS_RELEASE=24.05
|
||||
|
||||
# Check if home-manager is available
|
||||
if [ -x "$(command -v home-manager)" ]; then
|
||||
echo "Detected Home Manager, did you setup everything already!?"
|
||||
echo "You should only run ./setup.sh once, re-running this could do damage."
|
||||
# Check if $HOME/.dotfiles-setup exists, if so exit because setup has already been run
|
||||
if [ -f $HOME/.dotfiles-setup ]; then
|
||||
echo "Setup has already been run, exiting..."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Link .bashrc
|
||||
rm -rf $HOME/.bashrc
|
||||
ln -s $HOME/dotfiles/.bashrc $HOME/.bashrc
|
||||
# Check if nixos-version is available
|
||||
ensure_nixos() {
|
||||
if [ -x "$(command -v nixos-version)" ]; then
|
||||
echo "Detected NixOS, skipping Nix setup."
|
||||
return
|
||||
else
|
||||
echo "NixOS not detected, installing Nix..."
|
||||
sh <(curl -L https://nixos.org/nix/install) --daemon
|
||||
fi
|
||||
}
|
||||
|
||||
# Install home-manager
|
||||
sudo nix-channel --add https://github.com/nix-community/home-manager/archive/release-24.05.tar.gz home-manager
|
||||
sudo nix-channel --update
|
||||
sudo nix-shell '<home-manager>' -A install
|
||||
nix-shell '<home-manager>' -A install
|
||||
setup_symlinks() {
|
||||
# Link .bashrc
|
||||
rm -rf $HOME/.bashrc
|
||||
ln -s $HOME/dotfiles/.bashrc $HOME/.bashrc
|
||||
|
||||
# Link proper home-manager configs
|
||||
rm -rf ~/.config/home-manager
|
||||
ln -s $HOME/dotfiles/config/home-manager ~/.config/home-manager
|
||||
# Link proper home-manager configs
|
||||
rm -rf ~/.config/home-manager
|
||||
ln -s $HOME/dotfiles/config/home-manager ~/.config/home-manager
|
||||
|
||||
# Link proper nixos configs
|
||||
sudo ln -s $HOME/dotfiles/config/nixos/configuration.nix /etc/nixos/configuration.nix
|
||||
# Link proper nixos configs
|
||||
sudo ln -s $HOME/dotfiles/config/nixos/configuration.nix /etc/nixos/configuration.nix
|
||||
}
|
||||
|
||||
install_home_manager() {
|
||||
sudo nix-channel --add https://github.com/nix-community/home-manager/archive/release-$NIXOS_RELEASE.tar.gz home-manager
|
||||
sudo nix-channel --update
|
||||
sudo nix-shell '<home-manager>' -A install
|
||||
nix-shell '<home-manager>' -A install
|
||||
}
|
||||
|
||||
prepare_hostname() {
|
||||
# Ask the user what hostname this machine should have
|
||||
echo "Enter the hostname for this machine:"
|
||||
read hostname
|
||||
|
||||
# Validate hostname to ensure it's not empty, contains only alphanumeric characters, and is less than 64 characters
|
||||
while [[ -z $hostname || ! $hostname =~ ^[a-zA-Z0-9]+$ || ${#hostname} -gt 64 ]]; do
|
||||
echo "Invalid hostname. Please enter a valid hostname:"
|
||||
read hostname
|
||||
done
|
||||
|
||||
# Set the hostname by dumping it into $HOME/.hostname
|
||||
touch $HOME/.hostname
|
||||
echo $hostname > $HOME/.hostname
|
||||
}
|
||||
|
||||
prepare_hostname
|
||||
ensure_nixos
|
||||
install_home_manager
|
||||
setup_symlinks
|
||||
|
||||
# Rebuild NixOS
|
||||
sudo nixos-rebuild switch
|
||||
@ -39,6 +66,8 @@ sudo nixos-rebuild switch
|
||||
# Rebuild Home Manager
|
||||
cd $HOME/dotfiles/config/home-manager && NIXPKGS_ALLOW_UNFREE=1 home-manager switch
|
||||
|
||||
touch $HOME/.dotfiles-setup
|
||||
|
||||
echo "##############################################################"
|
||||
echo "# #"
|
||||
echo "# !!! LOGOUT & LOGIN OR RESTART BEFORE YOU CONTINUE !!! #"
|
||||
|
Reference in New Issue
Block a user