Created
September 15, 2024 20:31
-
-
Save benjamingwynn/73e17cc1ac15b3b51b8c53b112cc9e91 to your computer and use it in GitHub Desktop.
Gets the currently booted nixos generation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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