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

View file

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

View file

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

View file

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

View file

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

View file

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