-
-
Save kalbasit/066183d05901e7aaf9a02cf956a42e97 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# NOTE: this script should not use nix-shell because it assumes nix is not installed! | |
set -euo pipefail | |
# source the asserts | |
source "$(dirname "${BASH_SOURCE[0]}")/init.sh" | |
function usage() { | |
>&2 echo "USAGE: kt setup" | |
>&2 echo "Install all of the external dependencies on your OS" | |
} | |
if [[ "${#}" -ge 1 ]] && [[ "${1}" = "--help" ]]; then | |
usage | |
exit 0 | |
fi | |
# install Nix if it's not yet installed | |
nix_installed=0 | |
if ! command -v nix &>/dev/null; then | |
# if the /nix folder was found but nix was still not found in PATH, try to | |
# source the initialization script which should provide the nix command. If | |
# the command is still not found, then exit with an error. | |
# Otherwise, install nix via the official script. | |
if [[ -d /nix ]]; then | |
# include nix in the current shell so we can install stuff | |
if [[ -r "/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh" ]]; then | |
source "/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh" | |
fi | |
if ! command -v nix &>/dev/null; then | |
>&2 echo -e "ERR: I found the folder /nix but I was not able to find the nix executable, did you reload your shell?" | |
>&2 echo -e " Please close your shell and open a new one before running kt setup again" | |
exit 1 | |
fi | |
else | |
>&2 echo -e ">>> Nix was not found running on your machine, installing it using the official installer." | |
sh <(curl https://nixos.org/nix/install) --daemon | |
nix_installed=1 | |
fi | |
# include nix in the current shell so we can install stuff | |
if [[ -r "/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh" ]]; then | |
source "/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh" | |
else | |
>&2 echo "ERR: unable to automatically enrich the shell with Nix, please restart your shell (or your computer) and run \`kt setup\` again" | |
exit 1 | |
fi | |
# make sure nix is now available | |
if ! nix-shell -p hello --run 'hello' &>/dev/null; then | |
>&2 echo "ERR: Nix was installed but we were not able to get it running in this script, please restart your shell (or your computer) and run \`kt setup\` again" | |
exit 1 | |
fi | |
fi | |
# install direnv for loading the shell | |
if ! command -v direnv &>/dev/null; then | |
>&2 echo "INFO: did not find direnv command, installing direnv" | |
nix-env -I nixpkgs=./lib/nix/nixpkgs.nix -f '<nixpkgs>' -iA direnv | |
fi | |
# install the dependencies globally, mostly for editors that do not support | |
# loading a shell through nix-shell | |
if ! command -v dlv &>/dev/null; then | |
>&2 echo "INFO: did not find dlv command, installing delve" | |
nix-env -I nixpkgs=./lib/nix/nixpkgs.nix -f '<nixpkgs>' -iA delve | |
fi | |
if ! command -v docker-credential-ecr-login &>/dev/null; then | |
>&2 echo "INFO: did not find docker-credential-ecr-login command, installing amazon-ecr-credential-helper" | |
nix-env -I nixpkgs=./lib/nix/nixpkgs.nix -f '<nixpkgs>' -iA amazon-ecr-credential-helper | |
fi | |
if ! command -v go &>/dev/null; then | |
>&2 echo "INFO: did not find go command, installing go" | |
nix-env -I nixpkgs=./lib/nix/nixpkgs.nix -f '<nixpkgs>' -iA go | |
fi | |
if [[ "${nix_installed}" == "1" ]]; then | |
>&2 echo "INFO: Nix was installed on your computer, congratulations!" | |
>&2 echo " Please restart your shell!" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment