summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2015-06-06 11:08:11 +0200
committerMatthias Beyer <mail@beyermatthias.de>2015-06-06 11:08:11 +0200
commitc16b3350c7ea4920e44567d4b67bc8614a956f39 (patch)
treeeac9811ec777d98e2782c458d8e6b948af73643e
parentb69dffe00dd8d598c988267fe3117c2a5031304b (diff)
parent17ba0524409a4a1cc2a6ecbe990bbecd3fdb949e (diff)
Merge pull request #16 from matthiasbeyer/add-show-generation
Add show generation
-rwxr-xr-xnix-script-show-generation.sh49
-rw-r--r--nix-utils.sh12
2 files changed, 61 insertions, 0 deletions
diff --git a/nix-script-show-generation.sh b/nix-script-show-generation.sh
new file mode 100755
index 0000000..b08ba83
--- /dev/null
+++ b/nix-script-show-generation.sh
@@ -0,0 +1,49 @@
+#!/usr/bin/env bash
+
+source $(dirname ${BASH_SOURCE[0]})/nix-utils.sh
+
+usage() {
+ cat <<EOS
+ $(help_synopsis "${BASH_SOURCE[0]}" "[-s | -u] [-h]")
+
+ -s Show system generation
+ -u Show user generation (default)
+ -h Show this help and exit
+
+$(help_end)
+EOS
+}
+
+SYSTEM=0
+USER=1
+
+while getopts "suh" OPTION
+do
+ case $OPTION in
+ s)
+ SYSTEM=1
+ USER=0
+ stdout "Showing system generation"
+ ;;
+ u)
+ SYSTEM=0
+ USER=1
+ stdout "Showing user generation"
+ ;;
+ h)
+ stdout "Showing usage"
+ usage
+ exit 0
+ ;;
+ esac
+done
+
+if [[ $SYSTEM -eq 1 ]]
+then
+ current_system_generation
+else
+ current_user_generation
+fi
+
+stdout "Ready"
+
diff --git a/nix-utils.sh b/nix-utils.sh
index b58d86a..49b7b29 100644
--- a/nix-utils.sh
+++ b/nix-utils.sh
@@ -29,3 +29,15 @@ help_end() {
echo ""
}
+grep_generation() {
+ $* | grep current | cut -d " " -f 2
+}
+
+current_system_generation() {
+ grep_generation "sudo nix-env -p /nix/var/nix/profiles/system --list-generations"
+}
+
+current_user_generation() {
+ grep_generation "nix-env --list-generations"
+}
+