summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xnix-script-channel-update.sh69
-rwxr-xr-xnix-script-download-sources.sh52
-rwxr-xr-xnix-script-show-commit.sh2
-rwxr-xr-xnix-script-show-generation.sh28
-rw-r--r--nix-utils.sh7
5 files changed, 151 insertions, 7 deletions
diff --git a/nix-script-channel-update.sh b/nix-script-channel-update.sh
new file mode 100755
index 0000000..505e4b0
--- /dev/null
+++ b/nix-script-channel-update.sh
@@ -0,0 +1,69 @@
+#!/usr/bin/env bash
+
+source $(dirname ${BASH_SOURCE[0]})/nix-utils.sh
+
+usage() {
+ cat <<EOS
+ $(help_synopsis "channel" "update [-h] [-t <name>] [-w <cfgdir>] [-n]")
+
+ -t <name> | Name for the new tag, instead of nixos-<host>-channel-<num>
+ -w <cfgdir> | Alternative config dir, default: $RC_CONFIG
+ -n | DON'T include hostname in tag name
+ -h | Show this help and exit
+
+$(help_end)
+EOS
+}
+
+TAG_NAME=""
+CONFIG=$RC_CONFIG
+HOST="$(hostname)"
+
+while getopts "t:w:nh" OPTION
+do
+ case $OPTION in
+ t)
+ TAG_NAME=$OPTARG
+ dbg "TAG_NAME = $TAG_NAME"
+ ;;
+
+ w)
+ CONFIG=$OPTARG
+ dbg "CONFIG = $CONFIG"
+ ;;
+
+ n)
+ HOST=""
+ dbg "HOST = $HOST"
+ ;;
+
+ h)
+ usage
+ exit 0
+ ;;
+
+ *)
+ ;;
+ esac
+done
+
+[[ -z "$CONFIG" ]] && \
+ stderr "No configuration git directory." && \
+ stderr "Won't do anything" && exit 1
+
+stdout "Updating nix-channel"
+explain sudo nix-channel --update
+stdout "Ready with updating"
+
+if [[ -z "$NAME" ]]
+then
+ TAG_NAME="nixos-$([[ ! -z "$HOST" ]] && echo "$HOST-")channel-$(current_channel_generation)"
+ stdout "Tag name: '$TAG_NAME'"
+fi
+
+stdout "Resetting sudo password"
+sudo -k
+
+stdout "Tagging '$CONFIG' repo with tag name '$TAG_NAME'"
+__git "$CONFIG" tag $TAG_NAME
+
diff --git a/nix-script-download-sources.sh b/nix-script-download-sources.sh
new file mode 100755
index 0000000..061f312
--- /dev/null
+++ b/nix-script-download-sources.sh
@@ -0,0 +1,52 @@
+#!/usr/bin/env bash
+
+source $(dirname ${BASH_SOURCE[0]})/nix-utils.sh
+
+usage() {
+ cat <<EOS
+ $(help_synopsis "${BASH_SOURCE[0]}" "[-h] -p <pkg>")
+
+ -p <pkg> | Package to download source and deps for
+ -Q | No build output
+ -h | Show this help and exit
+
+ Download sources for the package <pkg>, so we can disconnect
+ from the internet before building it.
+
+$(help_end)
+EOS
+}
+
+PACKAGE=""
+
+while getopts "p:Qh" OPTION
+do
+ case $OPTION in
+ p)
+ PACKAGE=$OPTARG
+ dbg "PACKAGE = $PACKAGE"
+ ;;
+
+ Q)
+ NO_BUILD_OUTPUT=1
+ dbg "NO_BUILD_OUTPUT = $NO_BUILD_OUTPUT"
+ ;;
+
+ h)
+ usage
+ exit 1
+ ;;
+ esac
+done
+
+[[ -z "$PACKAGE" ]] && stderr "No package passed" && usage && exit 1
+
+continue_question "Install sources for package '$PACKAGE'"
+
+drvs=$(nix-store -qR $(nix-instantiate '<nixpkgs>' -A $PACKAGE) | grep '.drv$')
+
+ARGS=""
+[[ $NO_BUILD_OUTPUT -eq 1 ]] && ARGS="-Q"
+
+nix-store $ARGS -r $(grep -l outputHash $drv)
+
diff --git a/nix-script-show-commit.sh b/nix-script-show-commit.sh
index d415288..36d60cf 100755
--- a/nix-script-show-commit.sh
+++ b/nix-script-show-commit.sh
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
-nixos-version | cut -d . -f 3 | cut -d " " -f 1
+nixos-version | awk -F. '{print $3}' | awk '{print $1}'
diff --git a/nix-script-show-generation.sh b/nix-script-show-generation.sh
index 27320ad..60216c6 100755
--- a/nix-script-show-generation.sh
+++ b/nix-script-show-generation.sh
@@ -4,11 +4,12 @@ source $(dirname ${BASH_SOURCE[0]})/nix-utils.sh
usage() {
cat <<EOS
- $(help_synopsis "${BASH_SOURCE[0]}" "[-s | -u] [-h]")
+ $(help_synopsis "${BASH_SOURCE[0]}" "[-s | -u | -p <profile>] [-h]")
- -s Show system generation
- -u Show user generation (default)
- -h Show this help and exit
+ -s | Show system generation
+ -u | Show user generation (default)
+ -p <profile> | Show <profile> generation
+ -h | Show this help and exit
Show the number of the current generations. Defaults to user
profile, but system profile can be checked as well.
@@ -25,8 +26,9 @@ EOS
SYSTEM=0
USER=1
+PROFILE=""
-while getopts "suh" OPTION
+while getopts "sup:h" OPTION
do
case $OPTION in
s)
@@ -39,6 +41,13 @@ do
USER=1
stdout "Showing user generation"
;;
+ p)
+ SYSTEM=0
+ USER=0
+ PROFILE=$OPTARG
+ dbg "PROFILE = $PROFILE"
+ ;;
+
h)
stdout "Showing usage"
usage
@@ -47,7 +56,14 @@ do
esac
done
-([[ $SYSTEM -eq 1 ]] && current_system_generation) || current_user_generation
+if [[ ! -z "$PROFILE" ]]
+then
+ grep_generation "sudo nix-env -p /nix/var/nix/profiles/$PROFILE --list-generations"
+else
+ ([[ $SYSTEM -eq 1 ]] && current_system_generation) || \
+ current_user_generation
+fi
+
stdout "Ready"
diff --git a/nix-utils.sh b/nix-utils.sh
index 4c59d0e..a289018 100644
--- a/nix-utils.sh
+++ b/nix-utils.sh
@@ -95,6 +95,13 @@ current_user_generation() {
}
#
+# get the current channel generation
+#
+current_channel_generation() {
+ grep_generation "sudo nix-env -p /nix/var/nix/profiles/per-user/root/channels --list-generations"
+}
+
+#
# Ask the user whether to continue or not
#
continue_question() {