deploy: change script to install or update

Depending on user (root = install, user = update)
This commit is contained in:
Henrik Lissner 2019-12-07 17:20:36 -05:00
parent b8aa62fd32
commit 7948519620
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

17
deploy
View file

@ -1,14 +1,20 @@
#!/usr/bin/env bash
set -e
DOTFILES="$(cd $(dirname "${BASH_SOURCE:-${(%):-%x}}") && pwd -P)"
PREFIX="${PREFIX:-/mnt}"
NIXOSPREFIX="${PREFIX}/etc/nixos"
NIXOSFLAGS="-I 'config=$DOTFILES/config' -I 'packages=$DOTFILES/packages'"
HOST=${1:-${HOST:-kuro}}
set -e
if [[ ! -f "$DOTFILES/configuration.$HOST.nix" ]]; then
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
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
@ -31,6 +37,5 @@ nix-channel --add https://nixos.org/channels/nixpkgs-unstable nixpkgs-unstable
nix-channel --update
nixos-generate-config --root "$PREFIX"
nixos-install --root "$PREFIX" \
-I "config=$DOTFILES/config" \
-I "packages=$DOTFILES/packages"
nixos-install --root "$PREFIX" $NIXOSFLAGS
fi