Skip to content

Instantly share code, notes, and snippets.

@benjamingwynn
Created September 15, 2024 20:31
Show Gist options
  • Save benjamingwynn/73e17cc1ac15b3b51b8c53b112cc9e91 to your computer and use it in GitHub Desktop.
Save benjamingwynn/73e17cc1ac15b3b51b8c53b112cc9e91 to your computer and use it in GitHub Desktop.
Gets the currently booted nixos generation
#!/usr/bin/env bash
# based on https://github.com/NixOS/nixpkgs/issues/163936#issuecomment-1069797072
resolvesTo=`cat /proc/cmdline | sed -n 's/^.*init=\(.*\)\/init.*$/\1/p'`
directory="/nix/var/nix/profiles/"
for symlink in "$directory"/*; do
if [ -L "$symlink" ]; then
resolved_path=$(readlink -f "$symlink")
if [ "$resolved_path" == "$resolvesTo" ]; then
echo "Current booted generation:" `basename $symlink`
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment