Enable virt-manager and streamline shell init

This commit is contained in:
randogoth 2026-02-03 18:36:21 +02:00
parent 27ce70ebfd
commit b6e2e95371
6 changed files with 82 additions and 101 deletions

View file

@ -49,7 +49,10 @@
services.openssh.enable = true;
networking.useDHCP = lib.mkDefault true;
networking = {
useDHCP = lib.mkDefault true;
firewall.trustedInterfaces = [ "virbr0" ];
}
nixpkgs.config.allowUnfree = true;
@ -59,6 +62,7 @@
enableBashIntegration = lib.mkDefault true;
};
nix-index-database.comma.enable = lib.mkDefault true;
virt-manager.enable = true;
};
# Optimise the Nix store once a day
@ -85,6 +89,7 @@
# Required for containers under podman-compose to be able to talk to each other.
defaultNetwork.settings.dns_enabled = true;
};
libvirtd.enable = true;
};
security.sudo = {

View file

@ -20,7 +20,6 @@
packages = [
"com.github.tchx84.Flatseal"
"io.github.kolunmi.Bazaar"
# "io.missioncenter.MissionCenter"
];
};
}

View file

@ -5,6 +5,7 @@
config.environment.systemPackages = lib.mkAfter [
pkgs.distrobox
pkgs.distroshelf
pkgs.dnsmasq
pkgs.fastfetch
pkgs.flatpak
pkgs.ghostty

View file

@ -13,6 +13,7 @@
"networkmanager"
"podman"
"docker"
"libvirtd"
];
hashedPassword = "$6$HrwFoHtYRwiTZsYo$gKNOvkQhjalczOLgoTXvVu1MaihYP4BdBnVpWkdoAf.5MAiV2mMPRibYyGv9ti1Q63AhGK7n4wOPjAU0O74mK0";
subGidRanges = [

View file

@ -1,146 +1,121 @@
# ---- logging ---------------------------------------------------------------
log_shell_init() {
printf '%s\n' "shell-init: $*" >>/tmp/shell-init.log 2>/dev/null
printf '%s\n' "shell-init: $*" >>/tmp/shell-init.log 2>/dev/null || true
}
ensure_bash_preexec() {
# Load bash-preexec to wire preexec/precmd hooks for Atuin.
if [ -n "${BASH_VERSION:-}" ] && [ -z "${bash_preexec_imported:-}" ] && [ -r "@BASHPREEXEC@" ]; then
# shellcheck disable=SC1090
. "@BASHPREEXEC@"
log_shell_init "bash-preexec sourced"
fi
# ---- helpers ---------------------------------------------------------------
have() { command -v "$1" >/dev/null 2>&1; }
is_interactive() {
[[ -t 1 || -n ${PS1:-} ]]
}
append_prompt_command() {
local cmd="$1"
case ";${PROMPT_COMMAND:-};" in
*";$cmd;"*) log_shell_init "PROMPT_COMMAND already has $cmd" ;;
"")
PROMPT_COMMAND="$cmd"
log_shell_init "PROMPT_COMMAND set to $cmd"
;;
*)
PROMPT_COMMAND="${PROMPT_COMMAND%;};$cmd"
log_shell_init "PROMPT_COMMAND appended $cmd -> ${PROMPT_COMMAND}"
;;
esac
append_unique() {
local var="$1" val="$2"
[[ ";${!var:-};" == *";$val;"* ]] && return
printf -v "$var" '%s' "${!var:+${!var%;};}$val"
}
# Consider shells with a TTY interactive even if PS1 is empty.
interactive=0
if [ -t 1 ]; then
interactive=1
elif [ -n "$PS1" ]; then
interactive=1
fi
prepend_unique_array() {
local name="$1" val="$2"
local -n arr="$name"
local out=("$val")
for f in "${arr[@]}"; do [[ $f != "$val" ]] && out+=("$f"); done
arr=("${out[@]}")
}
# Ensure a sane TERM for prompt tools.
if [ -z "${TERM:-}" ] || [ "$TERM" = "dumb" ]; then
# ---- environment sanity ----------------------------------------------------
if [[ -z ${TERM:-} || $TERM == dumb ]]; then
export TERM=xterm-256color
fi
log_shell_init "TERM=$TERM PS1=${PS1:-<empty>} SHELL=$SHELL interactive=$interactive"
INTERACTIVE=0
is_interactive && INTERACTIVE=1
# Ensure PS1 is set so Atuin/Starship init blocks run consistently.
if [ $interactive -eq 1 ] && [ -z "${PS1:-}" ]; then
log_shell_init "TERM=$TERM PS1=${PS1:-<empty>} SHELL=$SHELL interactive=$INTERACTIVE"
# Ensure PS1 exists so downstream init blocks run
if (( INTERACTIVE )) && [[ -z ${PS1:-} ]]; then
PS1='\\s-\\v\\$ '
fi
# Load bash-preexec early (needed by Atuin).
if [ $interactive -eq 1 ]; then
ensure_bash_preexec
if command -v __bp_install >/dev/null 2>&1; then
__bp_install
fi
(( INTERACTIVE )) || return 0
# ---- bash-preexec ----------------------------------------------------------
if [[ -n ${BASH_VERSION:-} && -z ${bash_preexec_imported:-} && -r "@BASHPREEXEC@" ]]; then
# shellcheck disable=SC1090
. "@BASHPREEXEC@"
have __bp_install && __bp_install
log_shell_init "bash-preexec loaded"
fi
# Prompt via Starship (manual init to avoid PROMPT_COMMAND being lost).
if [ $interactive -eq 1 ] && command -v @STARSHIP@ >/dev/null 2>&1; then
# ---- starship --------------------------------------------------------------
if have @STARSHIP@; then
log_shell_init "starship init"
case "$SHELL" in
case $SHELL in
*/bash) eval "$(@STARSHIP@ init bash)" ;;
*/zsh) eval "$(@STARSHIP@ init zsh)" ;;
esac
append_prompt_command starship_precmd
append_unique PROMPT_COMMAND starship_precmd
else
log_shell_init "starship skipped (not interactive or missing)"
log_shell_init "starship skipped"
fi
# Enable Atuin history integration after Starship so preexec/precmd arrays keep Atuin.
if [ $interactive -eq 1 ] && command -v @ATUIN@ >/dev/null 2>&1; then
# Ensure session is established even if init script fails to export.
if [ -z "${ATUIN_SESSION:-}" ]; then
ATUIN_SESSION=$(@ATUIN@ uuid)
export ATUIN_SESSION
# ---- atuin -----------------------------------------------------------------
if have @ATUIN@; then
log_shell_init "atuin init"
if [[ -z ${ATUIN_SESSION:-} ]]; then
export ATUIN_SESSION="$(@ATUIN@ uuid)"
ATUIN_HISTORY_ID=""
fi
log_shell_init "atuin init"
case "$SHELL" in
case $SHELL in
*/bash) eval "$(@ATUIN@ init bash)" ;;
*/zsh) eval "$(@ATUIN@ init zsh)" ;;
esac
# Ensure Atuin hooks stay present.
if [ -n "${preexec_functions[*]:-}" ]; then
# Remove existing duplicates then prepend Atuin.
tmp=()
for f in "${preexec_functions[@]}"; do
[ "$f" = "__atuin_preexec" ] && continue
tmp+=("$f")
done
preexec_functions=(__atuin_preexec "${tmp[@]}")
unset tmp
else
preexec_functions=(__atuin_preexec)
fi
if [ -n "${precmd_functions[*]:-}" ]; then
tmp=()
for f in "${precmd_functions[@]}"; do
[ "$f" = "__atuin_precmd" ] && continue
tmp+=("$f")
done
precmd_functions=(__atuin_precmd "${tmp[@]}")
unset tmp
else
precmd_functions=(__atuin_precmd)
fi
declare -a preexec_functions precmd_functions
prepend_unique_array preexec_functions __atuin_preexec
prepend_unique_array precmd_functions __atuin_precmd
else
log_shell_init "atuin skipped"
fi
# Directory jumping via zoxide.
if [ $interactive -eq 1 ] && command -v zoxide >/dev/null 2>&1; then
# ---- zoxide ---------------------------------------------------------------
if have zoxide; then
log_shell_init "zoxide init"
case "$SHELL" in
case $SHELL in
*/bash) eval "$(zoxide init bash)" ;;
*/zsh) eval "$(zoxide init zsh)" ;;
esac
have __zoxide_hook && append_unique PROMPT_COMMAND __zoxide_hook
else
log_shell_init "zoxide skipped"
fi
# Ensure zoxide hook stays in PROMPT_COMMAND even if starship overwrote it.
if [ $interactive -eq 1 ] && command -v __zoxide_hook >/dev/null 2>&1; then
append_prompt_command __zoxide_hook
fi
# ---- bash-preexec PROMPT_COMMAND safety -----------------------------------
# Ensure bash-preexec precmd is present even if other init overwrote PROMPT_COMMAND.
if [ $interactive -eq 1 ] && command -v __bp_precmd_invoke_cmd >/dev/null 2>&1; then
append_prompt_command __bp_precmd_invoke_cmd
fi
if [ $interactive -eq 1 ] && command -v __bp_interactive_mode >/dev/null 2>&1; then
append_prompt_command __bp_interactive_mode
fi
have __bp_precmd_invoke_cmd && append_unique PROMPT_COMMAND __bp_precmd_invoke_cmd
have __bp_interactive_mode && append_unique PROMPT_COMMAND __bp_interactive_mode
# ls aliases via eza.
if command -v eza >/dev/null 2>&1; then
alias ll='eza -l --icons=auto --group-directories-first'
alias l.='eza -d .*'
# ---- aliases --------------------------------------------------------------
if have eza; then
alias ls='eza'
alias ll='eza -l --icons=auto --group-directories-first'
alias l1='eza -1'
alias l.='eza -d .*'
fi
# grep aliases via ugrep.
if command -v ug >/dev/null 2>&1; then
if have ug; then
alias grep='ug'
alias egrep='ug -E'
alias fgrep='ug -F'
@ -149,7 +124,6 @@ if command -v ug >/dev/null 2>&1; then
alias xzfgrep='ug -zF'
fi
# bat for cat.
if command -v bat >/dev/null 2>&1; then
if have bat; then
alias cat='bat --style=plain --pager=never' 2>/dev/null
fi
fi

View file

@ -115,6 +115,7 @@
DEFAULT_TERMINAL = "${pkgs.ghostty}/bin/ghostty";
EDITOR = "${pkgs.micro}/bin/micro";
DBX_CONTAINER_HOME_PREFIX = "$HOME/distrobox";
GDK_BACKEND = "x11 virt-manager"
};
}