38 lines
1 KiB
Bash
Executable file
38 lines
1 KiB
Bash
Executable file
#!/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}}
|
|
|
|
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
|
|
fi
|
|
|
|
mkdir -p "$NIXOSPREFIX"
|
|
cat << EOF > "$NIXOSPREFIX/configuration.nix"
|
|
{ config, ... }:
|
|
{
|
|
imports = [
|
|
../dotfiles/configuration.$HOST.nix
|
|
./hardware-configuration.nix
|
|
];
|
|
}
|
|
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
|