mirror of
https://github.com/nix-community/home-manager.git
synced 2025-11-08 19:46:05 +01:00
home-manager: fix option subcommand
- calls nix-instatiate instead of nixos-option (using nix-option's underlying nix script). - loops over options to display since nixos-option can only process a single option. - passes through the --recursive flag from nixos-option. and includes --help and man page for the flag. details: nixos-option was changed from a C++ command to a shell script that feeds a nix script (with arguments) to nix-instatiate. in the process, the --config_expr and --options_expr we once passed to nixos-option were removed. without changing the nixos-option shell script, we have no may to override the arguments to the nixos-option nix script. luckily, we can use our modulesExpr as a direct argument to the new nixos-option nix script. unluckily, the nix script does not accept multiple options per instantiation. so we are also looping through the given options ourselves and feeding them each to nixos-option's nix script. the nixos-option shell and nix scripts are in different places in the nix store, so we have to search the store for the nix script given the location of the shell script. also, the nixos-option nix script wants a 'recursive' flag, so we now honor that flag for the home-manager option subcommand.
This commit is contained in:
parent
c93684cd87
commit
64c49b1aa5
2 changed files with 60 additions and 9 deletions
|
|
@ -24,7 +24,7 @@
|
||||||
.Cm | generations
|
.Cm | generations
|
||||||
.Cm | help
|
.Cm | help
|
||||||
.Cm | news
|
.Cm | news
|
||||||
.Cm | option Ar option.name
|
.Cm | option Oo Fl -recursive Oc Ar option.name
|
||||||
.Cm | packages
|
.Cm | packages
|
||||||
.Cm | remove-generations Ar ID \&...
|
.Cm | remove-generations Ar ID \&...
|
||||||
.Cm | switch
|
.Cm | switch
|
||||||
|
|
@ -138,10 +138,14 @@ Show news entries in a pager.
|
||||||
.RE
|
.RE
|
||||||
.PP
|
.PP
|
||||||
|
|
||||||
.It Cm option Ar option.name
|
.It Cm option Oo Fl -recursive Oc Ar option.name
|
||||||
.RS 4
|
.RS 4
|
||||||
Inspect the given option name in the home configuration, like
|
Inspect the given option name in the home configuration, like
|
||||||
\fBnixos-option\fR(8)\&.
|
\fBnixos-option\fR(8)\&.
|
||||||
|
.sp
|
||||||
|
If the
|
||||||
|
.Fl -recursive
|
||||||
|
option is given, print all the values at or below the option name recursively\&.
|
||||||
.RE
|
.RE
|
||||||
.Pp
|
.Pp
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -232,7 +232,29 @@ function doInspectOption() {
|
||||||
fi
|
fi
|
||||||
setConfigFile
|
setConfigFile
|
||||||
|
|
||||||
local extraArgs=("$@")
|
local paths=()
|
||||||
|
local recursive=false
|
||||||
|
|
||||||
|
while (( $# > 0 )); do
|
||||||
|
local opt="$1"
|
||||||
|
shift
|
||||||
|
|
||||||
|
case $opt in
|
||||||
|
--recursive)
|
||||||
|
recursive=true;;
|
||||||
|
*)
|
||||||
|
# Remove trailing dot if exists, match the behavior of
|
||||||
|
# old nixos-option and make shell completions happy
|
||||||
|
paths+=("${opt%.}")
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ ${#paths[@]} -eq 0 ]]; then
|
||||||
|
paths=("")
|
||||||
|
fi
|
||||||
|
|
||||||
|
local extraArgs=()
|
||||||
|
|
||||||
for p in "${EXTRA_NIX_PATH[@]}"; do
|
for p in "${EXTRA_NIX_PATH[@]}"; do
|
||||||
extraArgs=("${extraArgs[@]}" "-I" "$p")
|
extraArgs=("${extraArgs[@]}" "-I" "$p")
|
||||||
|
|
@ -256,11 +278,24 @@ function doInspectOption() {
|
||||||
modulesExpr+=" configuration = if confAttr == \"\" then confPath else (import confPath).\${confAttr};"
|
modulesExpr+=" configuration = if confAttr == \"\" then confPath else (import confPath).\${confAttr};"
|
||||||
modulesExpr+=" pkgs = import <nixpkgs> {}; check = true; })"
|
modulesExpr+=" pkgs = import <nixpkgs> {}; check = true; })"
|
||||||
|
|
||||||
nixos-option \
|
local NIXOS_OPTION_CMD NIXOS_OPTION_REAL NIXOS_OPTION_DIR NIXOS_OPTION_NIX
|
||||||
--options_expr "$modulesExpr.options" \
|
NIXOS_OPTION_CMD=$(command -v nixos-option)
|
||||||
--config_expr "$modulesExpr.config" \
|
NIXOS_OPTION_REAL=$(realpath "${NIXOS_OPTION_CMD}")
|
||||||
"${extraArgs[@]}" \
|
NIXOS_OPTION_NIX=$(nix-store -q --references "${NIXOS_OPTION_REAL}" | grep 'nixos-option\.nix$')
|
||||||
"${PASSTHROUGH_OPTS[@]}"
|
|
||||||
|
if [[ ! -f "$NIXOS_OPTION_NIX" ]]; then
|
||||||
|
_iError "nixos-option.nix not found."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
for path in "${paths[@]}"; do
|
||||||
|
nix-instantiate --eval --json \
|
||||||
|
--arg nixos "$modulesExpr" \
|
||||||
|
--argstr path "$path" \
|
||||||
|
--arg recursive "$recursive" \
|
||||||
|
"$NIXOS_OPTION_NIX" \
|
||||||
|
| jq -r
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
function doInit() {
|
function doInit() {
|
||||||
|
|
@ -1063,9 +1098,11 @@ function doHelp() {
|
||||||
echo
|
echo
|
||||||
echo " edit Open the home configuration in \$VISUAL or \$EDITOR"
|
echo " edit Open the home configuration in \$VISUAL or \$EDITOR"
|
||||||
echo
|
echo
|
||||||
echo " option OPTION.NAME"
|
echo " option [--recursive] OPTION.NAME"
|
||||||
echo " Inspect configuration option named OPTION.NAME."
|
echo " Inspect configuration option named OPTION.NAME."
|
||||||
echo
|
echo
|
||||||
|
echo " --recursive Print all the values at or below the option name recursively."
|
||||||
|
echo
|
||||||
echo " build Build configuration into result directory"
|
echo " build Build configuration into result directory"
|
||||||
echo
|
echo
|
||||||
echo " init [--switch] [DIR]"
|
echo " init [--switch] [DIR]"
|
||||||
|
|
@ -1211,6 +1248,16 @@ while [[ $# -gt 0 ]]; do
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
|
--recursive)
|
||||||
|
case $COMMAND in
|
||||||
|
option)
|
||||||
|
COMMAND_ARGS+=("$opt")
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
errTopLevelSubcommandOpt "--recursive" "option"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
--option|--arg|--argstr)
|
--option|--arg|--argstr)
|
||||||
[[ -v 1 && $1 != -* ]] || errMissingOptArg "$opt"
|
[[ -v 1 && $1 != -* ]] || errMissingOptArg "$opt"
|
||||||
[[ -v 2 ]] || errMissingOptArg "$opt $1"
|
[[ -v 2 ]] || errMissingOptArg "$opt $1"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue