helm/deploy

42 lines
1.2 KiB
Plaintext
Raw Normal View History

2019-08-06 10:56:54 -07:00
#!/usr/bin/env bash
set -e
2019-08-06 10:56:54 -07:00
DOTFILES="$(cd $(dirname "${BASH_SOURCE:-${(%):-%x}}") && pwd -P)"
2019-08-26 10:18:53 -07:00
PREFIX="${PREFIX:-/mnt}"
NIXOSPREFIX="${PREFIX}/etc/nixos"
NIXOSFLAGS="-I 'config=$DOTFILES/config' -I 'packages=$DOTFILES/packages'"
2019-08-06 10:56:54 -07:00
HOST=${1:-${HOST:-kuro}}
if [ $EUID -nq 0 ]; then
sudo nix-channel --update
sudo nixos-rebuild $NIXOSFLAGS switch
else
if [ ! -f "$DOTFILES/configuration.$HOST.nix" ]; then
>&2 echo "No configuration exists for host '$HOST'"
exit 1
elif [ ! -f "$NIXOSPREFIX/hardware-configuration.nix" ]; then
>&2 echo "No hardware-configuration.nix file exists in $NIXOSPREFIX"
>&2 echo "Did you forget to set up your partitions?"
exit 2
fi
mkdir -p "$NIXOSPREFIX"
cat << EOF > "$NIXOSPREFIX/configuration.nix"
2019-08-26 10:18:53 -07:00
{ config, ... }:
{
imports = [
../dotfiles/configuration.$HOST.nix
./hardware-configuration.nix
];
2019-08-26 10:18:53 -07:00
}
EOF
nix-channel --add https://nixos.org/channels/nixos-19.09 nixos
nix-channel --add https://github.com/rycee/home-manager/archive/master.tar.gz home-manager
nix-channel --add https://nixos.org/channels/nixpkgs-unstable nixpkgs-unstable
nix-channel --update
nixos-generate-config --root "$PREFIX"
nixos-install --root "$PREFIX" $NIXOSFLAGS
fi