add -I key=value option

Allow to inject other NIX_PATH search values like nixpkgs.
This commit is contained in:
zimbatm 2019-08-19 16:06:29 +02:00
parent b050b7651b
commit e6578895b5
No known key found for this signature in database
GPG Key ID: 71BAF6D40C1D63D7

View File

@ -4,13 +4,17 @@ set -euo pipefail
## Configuration
libexec_dir="${0%/*}"
readonly libexec_dir="${0%/*}"
readonly format_dir=$libexec_dir/formats
configuration=${NIXOS_CONFIG:-$libexec_dir/configuration.nix}
format_path=
format_dir=$libexec_dir/formats
target_system=
cores=
run=
nix_args=(
"$libexec_dir/nixos-generate.nix"
)
## Functions
@ -30,6 +34,7 @@ Options:
only works for the "vm" and "vm-no-gui" formats
* --system: specify the target system (eg: x86_64-linux)
* --cores : to control the maximum amount of parallelism. (see nix-build documentation)
* -I KEY=VALUE: Add a key to the Nix expression search path.
USAGE
}
@ -83,6 +88,10 @@ while [[ $# -gt 0 ]]; do
target_system=$2
shift
;;
-I)
nix_args+=(-I "$2")
shift
;;
*)
abort "unknown option $1"
;;
@ -94,23 +103,22 @@ if [[ -z $format_path ]]; then
abort "missing format. use --help for more details"
fi
args=(
"$libexec_dir/nixos-generate.nix"
nix_args+=(
-I "nixos-config=$configuration"
-I "format-config=$format_path"
)
if [[ -n $target_system ]]; then
args+=(--argstr system "$target_system")
nix_args+=(--argstr system "$target_system")
fi
if [[ -n $cores ]]; then
args+=(--cores "$cores")
nix_args+=(--cores "$cores")
fi
formatAttr=$(nix-instantiate "${args[@]}" --eval --json -A config.formatAttr | jq -r .)
formatAttr=$(nix-instantiate "${nix_args[@]}" --eval --json -A config.formatAttr | jq -r .)
out=$(nix-build "${args[@]}" --no-out-link -A "config.system.build.$formatAttr")
out=$(nix-build "${nix_args[@]}" --no-out-link -A "config.system.build.$formatAttr")
if [[ -z $run ]]; then
# show the first file