fixed imports and added scripts
This commit is contained in:
24
scripts/inspect.sh
Executable file
24
scripts/inspect.sh
Executable file
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
NIX_EVAL_CMD="nix eval --json --no-warn-dirty --apply builtins.attrNames"
|
||||
|
||||
list_flake_attr() {
|
||||
attr="$1"
|
||||
flake="${2:-.}"
|
||||
echo "${attr} [${flake}]:"
|
||||
$NIX_EVAL_CMD "${flake}#${attr}" | jq -r '" - " + .[]'
|
||||
echo
|
||||
}
|
||||
|
||||
list_home_modules() {
|
||||
list_flake_attr "homeModules" "$1"
|
||||
}
|
||||
|
||||
list_home_configurations() {
|
||||
list_flake_attr "homeConfigurations" "$1"
|
||||
}
|
||||
|
||||
current_dir=$(readlink -f .)
|
||||
flake="${1:-$current_dir}"
|
||||
list_home_modules "$flake"
|
||||
list_home_configurations "$flake"
|
||||
24
scripts/switch.sh
Executable file
24
scripts/switch.sh
Executable file
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
FLAKE_DIR="/home/john/.config/home-manager/jsl-dendritic"
|
||||
|
||||
is_in_array() {
|
||||
local needle="$1"
|
||||
shift
|
||||
local arr=("$@")
|
||||
[[ " ${arr[*]} " == *" ${needle} "* ]] && echo true || echo false
|
||||
}
|
||||
|
||||
hostname_exists() {
|
||||
NIX_EVAL_CMD="nix eval --json --no-warn-dirty --apply builtins.attrNames"
|
||||
mapfile -t HOME_CONFIGS < <(${NIX_EVAL_CMD} ${FLAKE_DIR}#homeConfigurations | jq -r '.[]')
|
||||
is_in_array "$(hostname)" "${HOME_CONFIGS[@]}"
|
||||
}
|
||||
|
||||
HOSTNAME=$(hostname)
|
||||
if [[ "$(hostname_exists)" == "true" ]]; then
|
||||
home-manager switch --flake "${FLAKE_DIR}#${HOSTNAME}"
|
||||
else
|
||||
echo "No homeConfiguration found for hostname '${HOSTNAME}'." >&2
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user