summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2015-09-12 20:02:58 +0200
committerMatthias Beyer <mail@beyermatthias.de>2015-09-12 20:02:58 +0200
commit4701a8aa55b1923a3b49bc6f892338208f7f68fa (patch)
tree043649b3caacf74ec9634f37fbf2652dc957a128
parentb0d8860dc9f78180f3f3e210bec9e955e4143bf6 (diff)
parent9757a93263496d71a9e37b4191743dddee2b18fb (diff)
Merge pull request #84 from matthiasbeyer/download-sources
Add command to download sources of a package and its deps
-rwxr-xr-xnix-script-download-sources.sh52
1 files changed, 52 insertions, 0 deletions
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)
+