Skip to content

Instantly share code, notes, and snippets.

@DavidArsene
Last active October 1, 2025 06:43
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
}
booted=$(readlink /run/booted-system)
current=$(readlink /run/current-system)
gens=(echo system-*-link)
for gen in "${gens[@]}"; do
target=$(readlink -f "$gen")
[ "$target" = "$booted" ] && boot=$(gen-to-num "$gen")
[ "$target" = "$current" ] && curr=$(gen-to-num "$gen")
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[-1]}")
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