diff --git a/doc/man-home-manager.xml b/doc/man-home-manager.xml
index e9db70449..357f4d5e8 100644
--- a/doc/man-home-manager.xml
+++ b/doc/man-home-manager.xml
@@ -41,6 +41,10 @@
news
+
+ option option.name
+
+
packages
@@ -250,6 +254,18 @@
+
+
+
+
+
+
+ Inspect the given option name in the home configuration, like
+ nixos-option
+ 8 .
+
+
+
diff --git a/home-manager/completion.bash b/home-manager/completion.bash
index 5b2f72345..9a470cc2c 100644
--- a/home-manager/completion.bash
+++ b/home-manager/completion.bash
@@ -62,6 +62,7 @@
# generations
# help
# news
+# option
# packages
# remove-generations
# switch
@@ -86,6 +87,7 @@
#
# help
# edit
+# option
# build
# switch
# generations
@@ -131,6 +133,9 @@
#
# edit Open the home configuration in $EDITOR
#
+# option OPTION.NAME
+# Inspect configuration option named OPTION.NAME.
+#
# build Build configuration into result directory
#
# switch Build and activate configuration
@@ -278,7 +283,7 @@ _home-manager_completions ()
#--------------------------#
local Subcommands
- Subcommands=( "help" "edit" "build" "instantiate" "switch" "generations" "remove-generations" "expire-generations" "packages" "news" "uninstall" )
+ Subcommands=( "help" "edit" "option" "build" "instantiate" "switch" "generations" "remove-generations" "expire-generations" "packages" "news" "uninstall" )
# ^ « home-manager »'s subcommands.
@@ -354,4 +359,4 @@ _home-manager_completions ()
complete -F _home-manager_completions -o default home-manager
-#complete -W "help edit build switch generations remove-generations expire-generations packages news" home-manager
+#complete -W "help edit option build switch generations remove-generations expire-generations packages news" home-manager
diff --git a/home-manager/completion.zsh b/home-manager/completion.zsh
index 6b33f24ab..9d346851b 100644
--- a/home-manager/completion.zsh
+++ b/home-manager/completion.zsh
@@ -25,6 +25,7 @@ case "$state" in
_values 'command' \
'help[help]' \
'edit[edit]' \
+ 'option[inspect option]' \
'build[build]' \
'switch[switch]' \
'generations[list generations]' \
diff --git a/home-manager/default.nix b/home-manager/default.nix
index 4af2be2e4..e898fec1d 100644
--- a/home-manager/default.nix
+++ b/home-manager/default.nix
@@ -1,4 +1,6 @@
-{ runCommand, lib, bash, coreutils, findutils, gnused, less
+{ runCommand, lib, bash, callPackage, coreutils, findutils, gnused, less
+# used for pkgs.path for nixos-option
+, pkgs
# Extra path to Home Manager. If set then this path will be tried
# before `$HOME/.config/nixpkgs/home-manager` and
@@ -9,6 +11,9 @@ let
pathStr = if path == null then "" else path;
+ nixos-option =
+ callPackage "${pkgs.path}/nixos/modules/installer/tools/nixos-option" { };
+
in runCommand "home-manager" {
preferLocalBuild = true;
allowSubstitutes = false;
@@ -27,6 +32,7 @@ in runCommand "home-manager" {
--subst-var-by findutils "${findutils}" \
--subst-var-by gnused "${gnused}" \
--subst-var-by less "${less}" \
+ --subst-var-by nixos-option "${nixos-option}" \
--subst-var-by HOME_MANAGER_PATH '${pathStr}'
install -D -m755 ${./completion.bash} \
diff --git a/home-manager/home-manager b/home-manager/home-manager
index 34af3c0c6..de521242e 100644
--- a/home-manager/home-manager
+++ b/home-manager/home-manager
@@ -1,7 +1,7 @@
#!@bash@/bin/bash
# Prepare to use tools from Nixpkgs.
-PATH=@coreutils@/bin:@findutils@/bin:@gnused@/bin:@less@/bin${PATH:+:}$PATH
+PATH=@coreutils@/bin:@findutils@/bin:@gnused@/bin:@less@/bin:@nixos-option@/bin${PATH:+:}$PATH
set -euo pipefail
@@ -97,6 +97,46 @@ function setFlakeAttribute() {
fi
}
+function doInspectOption() {
+ setFlakeAttribute
+ if [[ -v FLAKE_CONFIG_URI ]]; then
+ errorEcho "Can't inspect options of a flake configuration"
+ exit 1
+ fi
+ setConfigFile
+ setHomeManagerNixPath
+
+ local extraArgs=("$@")
+
+ for p in "${EXTRA_NIX_PATH[@]}"; do
+ extraArgs=("${extraArgs[@]}" "-I" "$p")
+ done
+
+ if [[ -v VERBOSE ]]; then
+ extraArgs=("${extraArgs[@]}" "--show-trace")
+ fi
+
+ local HOME_MANAGER_CONFIG_NIX HOME_MANAGER_CONFIG_ATTRIBUTE_NIX
+ HOME_MANAGER_CONFIG_NIX=${HOME_MANAGER_CONFIG//'\'/'\\'}
+ HOME_MANAGER_CONFIG_NIX=${HOME_MANAGER_CONFIG_NIX//'"'/'\"'}
+ HOME_MANAGER_CONFIG_NIX=${HOME_MANAGER_CONFIG_NIX//$'\n'/$'\\n'}
+ HOME_MANAGER_CONFIG_ATTRIBUTE_NIX=${HOME_MANAGER_CONFIG_ATTRIBUTE//'\'/'\\'}
+ HOME_MANAGER_CONFIG_ATTRIBUTE_NIX=${HOME_MANAGER_CONFIG_ATTRIBUTE_NIX//'"'/'\"'}
+ HOME_MANAGER_CONFIG_ATTRIBUTE_NIX=${HOME_MANAGER_CONFIG_ATTRIBUTE_NIX//$'\n'/$'\\n'}
+ local modulesExpr
+ modulesExpr="let confPath = \"${HOME_MANAGER_CONFIG_NIX}\"; "
+ modulesExpr+="confAttr = \"${HOME_MANAGER_CONFIG_ATTRIBUTE_NIX}\"; in "
+ modulesExpr+="(import {"
+ modulesExpr+=" configuration = if confAttr == \"\" then confPath else (import confPath).\${confAttr};"
+ modulesExpr+=" pkgs = import {}; check = true; })"
+
+ nixos-option \
+ --options_expr "$modulesExpr.options" \
+ --config_expr "$modulesExpr.config" \
+ "${extraArgs[@]}" \
+ "${PASSTHROUGH_OPTS[@]}"
+}
+
function doInstantiate() {
setFlakeAttribute
if [[ -v FLAKE_CONFIG_URI ]]; then
@@ -487,6 +527,9 @@ function doHelp() {
echo
echo " edit Open the home configuration in \$EDITOR"
echo
+ echo " option OPTION.NAME"
+ echo " Inspect configuration option named OPTION.NAME."
+ echo
echo " build Build configuration into result directory"
echo
echo " instantiate Instantiate the configuration and print the resulting derivation"
@@ -524,7 +567,7 @@ while [[ $# -gt 0 ]]; do
opt="$1"
shift
case $opt in
- build|instantiate|edit|expire-generations|generations|help|news|packages|remove-generations|switch|uninstall)
+ build|instantiate|option|edit|expire-generations|generations|help|news|packages|remove-generations|switch|uninstall)
COMMAND="$opt"
;;
-A)
@@ -586,7 +629,7 @@ while [[ $# -gt 0 ]]; do
;;
*)
case $COMMAND in
- expire-generations|remove-generations)
+ expire-generations|remove-generations|option)
COMMAND_ARGS+=("$opt")
;;
*)
@@ -631,6 +674,9 @@ case $COMMAND in
doExpireGenerations "${COMMAND_ARGS[@]}"
fi
;;
+ option)
+ doInspectOption "${COMMAND_ARGS[@]}"
+ ;;
packages)
doListPackages
;;