deploy: change script to install or update
Depending on user (root = install, user = update)
This commit is contained in:
parent
b8aa62fd32
commit
7948519620
33
deploy
33
deploy
|
@ -1,21 +1,27 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
set -e
|
||||||
|
|
||||||
DOTFILES="$(cd $(dirname "${BASH_SOURCE:-${(%):-%x}}") && pwd -P)"
|
DOTFILES="$(cd $(dirname "${BASH_SOURCE:-${(%):-%x}}") && pwd -P)"
|
||||||
PREFIX="${PREFIX:-/mnt}"
|
PREFIX="${PREFIX:-/mnt}"
|
||||||
NIXOSPREFIX="${PREFIX}/etc/nixos"
|
NIXOSPREFIX="${PREFIX}/etc/nixos"
|
||||||
|
NIXOSFLAGS="-I 'config=$DOTFILES/config' -I 'packages=$DOTFILES/packages'"
|
||||||
HOST=${1:-${HOST:-kuro}}
|
HOST=${1:-${HOST:-kuro}}
|
||||||
|
|
||||||
set -e
|
if [ $EUID -nq 0 ]; then
|
||||||
if [[ ! -f "$DOTFILES/configuration.$HOST.nix" ]]; 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'"
|
>&2 echo "No configuration exists for host '$HOST'"
|
||||||
exit 1
|
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 "No hardware-configuration.nix file exists in $NIXOSPREFIX"
|
||||||
>&2 echo "Did you forget to set up your partitions?"
|
>&2 echo "Did you forget to set up your partitions?"
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mkdir -p "$NIXOSPREFIX"
|
mkdir -p "$NIXOSPREFIX"
|
||||||
cat << EOF > "$NIXOSPREFIX/configuration.nix"
|
cat << EOF > "$NIXOSPREFIX/configuration.nix"
|
||||||
{ config, ... }:
|
{ config, ... }:
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
|
@ -25,12 +31,11 @@ cat << EOF > "$NIXOSPREFIX/configuration.nix"
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
nix-channel --add https://nixos.org/channels/nixos-19.09 nixos
|
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://github.com/rycee/home-manager/archive/master.tar.gz home-manager
|
||||||
nix-channel --add https://nixos.org/channels/nixpkgs-unstable nixpkgs-unstable
|
nix-channel --add https://nixos.org/channels/nixpkgs-unstable nixpkgs-unstable
|
||||||
nix-channel --update
|
nix-channel --update
|
||||||
|
|
||||||
nixos-generate-config --root "$PREFIX"
|
nixos-generate-config --root "$PREFIX"
|
||||||
nixos-install --root "$PREFIX" \
|
nixos-install --root "$PREFIX" $NIXOSFLAGS
|
||||||
-I "config=$DOTFILES/config" \
|
fi
|
||||||
-I "packages=$DOTFILES/packages"
|
|
||||||
|
|
Loading…
Reference in a new issue