#!/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 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 hostname="$1" action="$2" shift shift # shellcheck disable=SC2046 nixos-rebuild "$action" $(mk-nixos-cmd-args "$hostname") "$@" --no-reexec ;; install) if [ $# -lt 1 ]; then help exit 1 fi hostname="$1" shift # shellcheck disable=SC2046 echo nixos-install $(mk-nixos-cmd-args "$hostname") "$@" ;; help | *) help ;; esac