nixos-build-vms: pass --option to nix-build

Also simplified the argument parsing to write all currently supported
CLI options into a bash array and pass this to `nix-build`.

Also documented `--option` usage in the corresponding manpage.
This commit is contained in:
Maximilian Bosch 2019-02-03 12:48:40 +01:00
parent 230d55edc8
commit e998f5140f
No known key found for this signature in database
GPG Key ID: 091DBF4D1FC46B8E
2 changed files with 48 additions and 35 deletions

View File

@ -24,8 +24,14 @@
<arg>
<option>--help</option>
</arg>
</arg>
<arg>
<option>--option</option>
<replaceable>name</replaceable>
<replaceable>value</replaceable>
</arg>
<arg choice="plain">
<replaceable>network.nix</replaceable>
</arg>
@ -115,6 +121,18 @@
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>--option</option> <replaceable>name</replaceable> <replaceable>value</replaceable>
</term>
<listitem>
<para>Set the Nix configuration option
<replaceable>name</replaceable> to <replaceable>value</replaceable>.
This overrides settings in the Nix configuration file (see
<citerefentry><refentrytitle>nix.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>).
</para>
</listitem>
</varlistentry>
</variablelist>
</refsection>
</refentry>

View File

@ -9,49 +9,44 @@ showUsage() {
# Parse valid argument options
PARAMS=`getopt -n $0 -o h -l no-out-link,show-trace,help -- "$@"`
nixBuildArgs=()
networkExpr=
if [ $? != 0 ]
then
showUsage
exit 1
fi
eval set -- "$PARAMS"
# Evaluate valid options
while [ "$1" != "--" ]
do
while [ $# -gt 0 ]; do
case "$1" in
--no-out-link)
noOutLinkArg="--no-out-link"
;;
--show-trace)
showTraceArg="--show-trace"
;;
-h|--help)
showUsage
exit 0
;;
--no-out-link)
nixBuildArgs+=("--no-out-link")
;;
--show-trace)
nixBuildArgs+=("--show-trace")
;;
-h|--help)
showUsage
exit 0
;;
--option)
shift
nixBuildArgs+=("--option" "$1" "$2"); shift
;;
*)
if [ ! -z "$networkExpr" ]; then
echo "Network expression already set!"
showUsage
exit 1
fi
networkExpr="$(readlink -f $1)"
;;
esac
shift
done
shift
# Validate the given options
if [ "$1" = "" ]
if [ -z "$networkExpr" ]
then
echo "ERROR: A network expression must be specified!" >&2
exit 1
else
networkExpr=$(readlink -f $1)
fi
# Build a network of VMs
nix-build '<nixpkgs/nixos/modules/installer/tools/nixos-build-vms/build-vms.nix>' \
--argstr networkExpr $networkExpr $noOutLinkArg $showTraceArg
--argstr networkExpr $networkExpr "${nixBuildArgs[@]}"