From 36311e831550ef565d42aaf8a80247f0f727ef4e Mon Sep 17 00:00:00 2001 From: phone Date: Fri, 26 Jan 2024 03:06:39 +0300 Subject: [PATCH] Nix : Allow specifying hostname for update. --- .config/bash/module/Nix.sh | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/.config/bash/module/Nix.sh b/.config/bash/module/Nix.sh index f1d1b5a..63ed31f 100644 --- a/.config/bash/module/Nix.sh +++ b/.config/bash/module/Nix.sh @@ -38,13 +38,23 @@ function nix_channel() { } # Update system (rebuild). +# Optionally force the hostname. +# Usage: nix_update [HOSTNAME] function nix_update() { - nixos-rebuild switch -I nixos-config=/root/.config/linux/system/${HOSTNAME}/Configuration.nix + local target="${1}" + [[ "${target}" = "" ]] && target="${HOSTNAME}" + + nixos-rebuild switch -I nixos-config=/root/.config/linux/system/${target}/Configuration.nix } # Upgrade system. +# Optionally force the hostname. +# Usage: nix_upgrade [HOSTNAME] function nix_upgrade() { - nixos-rebuild switch --upgrade -I nixos-config=/root/.config/linux/system/${HOSTNAME}/Configuration.nix + local target="${1}" + [[ "${target}" = "" ]] && target="${HOSTNAME}" + + nixos-rebuild switch --upgrade -I nixos-config=/root/.config/linux/system/${target}/Configuration.nix } # Free up root space. @@ -62,3 +72,13 @@ function nix_shell() { function shell() { nix-shell -p "${@}" } + +# Autocomplete with available hosts. +function _comp_hosts() { + local IFS=$'\n' + local targets=($(ls --classify ~/.config/linux/system/ | grep /$ | sed -e "s/\/$//")) + + _autocomplete_first ${targets[@]} +} + +complete -F _comp_hosts nix_update nix_upgrade