#!/usr/bin/env bash # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 set -euo pipefail display_usage() { cat <> ~/.config/nix/nix.conf' # This sidesteps the need to update PATH for every user. sudo ln -s /home/nix/.nix-profile/bin/nix /usr/local/bin echo "=== Setting up Nix configs for the root user ===" sudo -u root bash -c "ln -s /home/nix/.nix-profile ~/" sudo -u root bash -c "ln -s /home/nix/.config ~/" } setup_sudo() { echo "=== Setting up sudo for the nix user, needed for installation ===" # The nix installer refuses to install as root, so we need to set up sudo for the nix user. sudo bash -c "echo 'nix ALL=NOPASSWD: ALL' > /etc/sudoers.d/nix" } check_gnutls_config() { if [[ -f "/etc/gnutls/config" ]]; then echo "Turning off gnuTLS overrides" sudo rm -f /etc/gnutls/config fi } update_ubuntu_packages() { sudo apt update sudo apt upgrade -y } # main for arg in "$@"; do case $arg in -h|--help) display_usage exit 0 ;; esac done check_gnutls_config update_ubuntu_packages setup_sudo setup_nix