#!/usr/bin/env bash set -euo pipefail function mk-nixos-cmd-args() { hostname="$1" pkgs=$(nix-instantiate --eval -E "let sources = import ./npins; in sources.nixpkgs.outPath" | tr -d '"') args=( "-I" "nixpkgs=$pkgs" "-I" "nixos-config=./nix/configurations/$hostname.nix" "--file" "./default.nix" "--attr" "nixosConfigurations.$hostname" ) echo "${args[@]}" } function wrapped-nixos-rebuild() { hostname="$1" action="$2" # shellcheck disable=SC2046 nixos-rebuild "$action" $(mk-nixos-cmd-args "$hostname") --no-reexec } function wrapped-nixos-install() { hostname="$1" # shellcheck disable=SC2046 nixos-install $(mk-nixos-cmd-args "$hostname") } function help() { cat < : run perhost action with nixos-rebuild install : run perhost action with nixos-install --help: show this help menu EOF } if [ $# -lt 1 ]; then help exit 1 fi mode="$1" shift case $mode in os) if [ $# -lt 2 ]; then help exit 1 fi wrapped-nixos-rebuild "$1" "$2" ;; install) if [ $# -lt 1 ]; then help exit 1 fi wrapped-nixos-install "$1" ;; help | *) help ;; esac