Skip to content

Instantly share code, notes, and snippets.

@DavidArsene
Last active January 5, 2026 20:20
Show Gist options
  • Select an option

  • Save DavidArsene/64676e5e1eb5c005d34307a14c38b0d9 to your computer and use it in GitHub Desktop.

Select an option

Save DavidArsene/64676e5e1eb5c005d34307a14c38b0d9 to your computer and use it in GitHub Desktop.
{ "type": "command", "text": "~/.config/fastfetch/fastfetch-nixos-generation.sh", "key": "Generation" },
#!/usr/bin/env bash
pushd "/nix/var/nix/profiles" > /dev/null
function gen-to-num() {
if [[ "$1" =~ system-([0-9]+)-link ]]; then
echo "${BASH_REMATCH[1]}"
fi
}
# These point to the closure,
# without being a link to here first.
booted=$(readlink /run/booted-system)
current=$(readlink /run/current-system)
# gens=(echo system-*-link)
gens=($(ls -t | grep link))
for gen in "${gens[@]}"; do
target=$(readlink -f "$gen")
[ $target = $booted ] && boot=$(gen-to-num "$gen")
[ $target = $current ] && curr=$(gen-to-num "$gen")
[[ ! -z $boot && ! -z $curr ]] && break
done
system=$(gen-to-num $(readlink system))
default=$([ $curr != $system ] && echo " (default: $system)")
booted_from=$([ $curr != $boot ] && echo " (booted from: $boot)")
first=$(gen-to-num "${gens[-1]}")
last=$(gen-to-num "${gens[0]}")
echo "Generation $curr$booted_from$default, available: $first..$last"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment