summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2015-08-01 20:49:09 +0200
committerMatthias Beyer <mail@beyermatthias.de>2015-08-01 20:49:09 +0200
commit6eb0f216cf364386ac4f90ef48c6267d62d490ae (patch)
tree0aedad45fc4bf129d22cea1797de5f413bc2bff8
parentf1a4c31aaf91d8e54472568231027dc5ec774acd (diff)
parentcfc3f168f1a191fc3a940914f39c82916e6d8f7f (diff)
Merge pull request #68 from matthiasbeyer/add-rc_file
Add rc file
-rw-r--r--example.rc36
-rwxr-xr-xnix-script30
-rwxr-xr-xnix-script-switch.sh41
-rwxr-xr-xnix-script-update-package-def.sh4
-rw-r--r--nix-utils.sh11
5 files changed, 105 insertions, 17 deletions
diff --git a/example.rc b/example.rc
new file mode 100644
index 0000000..03776b7
--- /dev/null
+++ b/example.rc
@@ -0,0 +1,36 @@
+#!/usr/bin/env bash
+
+#
+# This is an example configuration file for nix-scripts. Copy this file to
+# ~/.nix-scripts.rc and change the values of the variables to match your setup.
+# Remember to update the configuration file whenever you update nix-scripts.
+#
+
+#
+# Path to your configuration directory, where a git lives.
+#
+RC_CONFIG=~/config
+
+#
+# Path to your nixpkgs clone
+#
+RC_NIXPKGS=~/nixpkgs
+
+
+#
+#
+# Command: switch
+#
+#
+
+#
+# default flags for git-tagging when doing nix-script switch
+#
+RC_SWITCH_DEFAULT_TAG_FLAGS="-a"
+
+
+#
+# default flags for git-tagging nixpkgs when doing nix-script switch
+#
+RC_SWITCH_DEFAULT_TAG_FLAGS_NIXPKGS=""
+
diff --git a/nix-script b/nix-script
index 2fec7da..596efda 100755
--- a/nix-script
+++ b/nix-script
@@ -4,15 +4,22 @@ usage() {
cat <<EOS >&2
$(help_synopsis "${BASE_SOURCE[0]}" "[options] <command> <commandoptions>")
+ --conf=<path> Path for alternative nix-script.rc file. Default: ~/.nix-script.rc
-l | --list-commands List all available commands
-v Be verbose
-d Debugging output (enables -v)
-h Show this help and exit
+$(help_rcvars \
+"RC_CONFIG - Path of your system configuration (git) directory" \
+"RC_NIXPKGS - Path of your nixpkgs clone"
+)
+
$(help_end)
EOS
}
+RC=~/.nix-script.rc
LIST_COMMANDS=0
VERBOSE=0
@@ -61,6 +68,13 @@ all_commands() {
for cmd
do
case $cmd in
+ --conf=*)
+ RC=$(echo $cmd | sed 's,^--conf\=,,')
+ dbg "RC = $RC"
+ [[ ! -e $RC ]] && stderr "RC file '$RC' does not exist" && exit 1
+ shift_one_more
+ ;;
+
"--list-commands" )
LIST_COMMANDS=1
shift_one_more
@@ -106,6 +120,22 @@ do
esac
done
+if [[ ! -f "$RC" ]]
+then
+ dbg "No configuration file, setting up (empty) default values"
+
+ RC_CONFIG=""
+ RC_NIXPKGS=""
+ RC_SWITCH_DEFAULT_TAG_FLAGS=""
+ RC_SWITCH_DEFAULT_TAG_FLAGS_NIXPKGS=""
+else
+ dbg "Configuration file found. Sourcing: '$RC'"
+ source $RC
+fi
+
+dbg "RC_CONFIG = '$RC_CONFIG'"
+dbg "RC_NIXPKGS = '$RC_NIXPKGS'"
+
if [ $LIST_COMMANDS -eq 1 ]
then
dbg "Listing commands"
diff --git a/nix-script-switch.sh b/nix-script-switch.sh
index 3359e32..572dac5 100755
--- a/nix-script-switch.sh
+++ b/nix-script-switch.sh
@@ -9,14 +9,14 @@ COMMAND="switch"
usage() {
cat <<EOS
- $(help_synopsis "${BASH_SOURCE[0]}" "[-h] [-c <command>] -w <working directory> [-- args...]")
+ $(help_synopsis "${BASH_SOURCE[0]}" "[-h] [-c <command>] [-w <working directory>] [-- args...]")
-c <command> Command for nixos-rebuild. See 'man nixos-rebuild' (default: switch)
- -w <path> Path to your configuration git directory
+ -w <path> Path to your configuration git directory (default: '$RC_CONFIG')
-n DON'T include hostname in tag name
-t <tagname> Custom tag name
- -p <pkgs> Generate the switch tag in the nixpkgs at <pkgs> as well.
- -f <tag-flags> Flags for git-tag (see 'git tag --help')
+ -p <pkgs> Generate the switch tag in the nixpkgs at <pkgs> as well. (default: '$RC_NIXPKGS')
+ -f <tag-flags> Flags for git-tag (see 'git tag --help') (default: '$RC_SWITCH_DEFAULT_TAG_FLAGS')
-b Do not call nixos-rebuild at all.
-h Show this help and exit
@@ -43,17 +43,25 @@ usage() {
can be used to use your local clone of the nixpkgs repository.
+$(help_rcvars \
+ "RC_CONFIG - Path of your system configuration (git) directory"\
+ "RC_NIXPKGS - Path of your nixpkgs clone" \
+ "RC_SWITCH_DEFAULT_TAG_FLAGS - Default git-tag flags for tagging in system configuration (git) directory"\
+ "RC_SWITCH_DEFAULT_TAG_FLAGS_NIXPKGS - Default git-tag flags for tagging in nixpkgs"
+)
+
$(help_end)
EOS
}
COMMAND=
ARGS=
-WD=
+WD=$RC_CONFIG
TAG_NAME=
HOSTNAME="$(hostname)"
-NIXPKGS=""
-TAG_FLAGS=""
+NIXPKGS=$RC_NIXPKGS
+TAG_FLAGS="$RC_SWITCH_DEFAULT_TAG_FLAGS"
+TAG_FLAGS_NIXPKGS="$RC_SWITCH_DEFAULT_TAG_FLAGS_NIXPKGS"
DONT_BUILD=
while getopts "c:w:t:nbp:f:h" OPTION
@@ -61,30 +69,26 @@ do
case $OPTION in
c)
COMMAND=$OPTARG
- dbg "COMMAND = $COMMAND"
;;
+
w)
WD=$OPTARG
- dbg "WD = $WD"
;;
+
t)
TAG_NAME=$OPTARG
- dbg "TAG_NAME = $TAG_NAME"
;;
n)
HOSTNAME=""
- dbg "HOSTNAME disabled"
;;
p)
NIXPKGS=$OPTARG
- dbg "NIXPKGS = $NIXPKGS"
;;
f)
TAG_FLAGS=$OPTARG
- dbg "TAG_FLAGS = $TAG_FLAGS"
;;
b)
@@ -114,12 +118,19 @@ tag_nixpkgs() {
c_txt="Trying to create tag '$TAG_NAME' at '$1' on commit '$commit'"
continue_question "$c_txt" || return
- __git "$1" tag -a "$TAG_NAME" $commit || \
+ __git "$1" tag $TAG_FLAGS_NIXPKGS "$TAG_NAME" $commit || \
stderr "Could not create tag in nixpkgs clone"
}
+
+dbg "COMMAND = $COMMAND"
+dbg "WD = $WD"
+dbg "TAG_NAME = $TAG_NAME"
+dbg "HOSTNAME = $HOSTNAME"
+dbg "NIXPKGS = $NIXPKGS"
+dbg "TAG_FLAGS = $TAG_FLAGS"
ARGS=$(echo $* | sed -r 's/(.*)(\-\-(.*)|$)/\2/')
-dbg "ARGS = $ARGS"
+dbg "ARGS = $ARGS"
[[ -z "$WD" ]] && \
stderr "No configuration git directory." && \
diff --git a/nix-script-update-package-def.sh b/nix-script-update-package-def.sh
index 0903798..6966741 100755
--- a/nix-script-update-package-def.sh
+++ b/nix-script-update-package-def.sh
@@ -17,7 +17,7 @@ usage() {
-y Don't ask before executing things (optional) (not implemented yet)
-b Also test-build the package (optional)
-u <url> Download and apply this url
- -g <path> Path of nixpkgs clone (defaults to ./)
+ -g <path> Path of nixpkgs clone (Default: '$RC_NIXPKGS')
-c Don't check out another branch for update
-d Don't checkout base branch after successfull run.
-h Show this help and exit
@@ -53,7 +53,7 @@ EOS
YES=0
TESTBUILD=0
-NIXPKGS=
+NIXPKGS=$RC_NIXPKGS
URL=
CHECKOUT=1
DONT_CHECKOUT_BASE=
diff --git a/nix-utils.sh b/nix-utils.sh
index 6dc426e..69dbf12 100644
--- a/nix-utils.sh
+++ b/nix-utils.sh
@@ -44,6 +44,17 @@ help_synopsis() {
}
#
+# Helper for section on variables from the RC file for the script
+#
+help_rcvars() {
+ echo -e "\tUsed nix-script.rc variables:"
+ echo -e "\t-----------------------------"
+ echo -e ""
+ for s; do echo -e "\t\t${s}"; done
+ echo -e ""
+}
+
+#
# generate a help text footnote
#
help_end() {