From dfd0434136318ad39e7f35907c77036e0e20f8fd Mon Sep 17 00:00:00 2001 From: Timo Kaufmann Date: Wed, 18 Mar 2020 00:02:38 +0100 Subject: [PATCH] home-manager: add instantiate subcommand It can be useful to simply instantiate a Home Manager configuration without actually building it, for example for the purpose of pre-building it with some custom command. PR #1099 --- doc/man-home-manager.xml | 14 ++++++++++++++ home-manager/completion.bash | 2 +- home-manager/home-manager | 29 ++++++++++++++++++++++++++++- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/doc/man-home-manager.xml b/doc/man-home-manager.xml index 117bc4946879..90f58063ea95 100644 --- a/doc/man-home-manager.xml +++ b/doc/man-home-manager.xml @@ -17,6 +17,10 @@ build + + instantiate + + edit @@ -163,6 +167,16 @@ + + + + + + + Instantiate the configuration and print the resulting derivation. + + + diff --git a/home-manager/completion.bash b/home-manager/completion.bash index 501b87279fa4..e9f04578916a 100644 --- a/home-manager/completion.bash +++ b/home-manager/completion.bash @@ -278,7 +278,7 @@ _home-manager_completions () #--------------------------# local Subcommands - Subcommands=( "help" "edit" "build" "switch" "generations" "remove-generations" "expire-generations" "packages" "news" "uninstall" ) + Subcommands=( "help" "edit" "build" "instantiate" "switch" "generations" "remove-generations" "expire-generations" "packages" "news" "uninstall" ) # ^ « home-manager »'s subcommands. diff --git a/home-manager/home-manager b/home-manager/home-manager index 7fa5c35c300c..f7436e3e2906 100644 --- a/home-manager/home-manager +++ b/home-manager/home-manager @@ -74,6 +74,28 @@ function setHomeManagerNixPath() { done } +function doInstantiate() { + 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 + + nix-instantiate \ + "" \ + "${extraArgs[@]}" \ + "${PASSTHROUGH_OPTS[@]}" \ + --argstr confPath "$HOME_MANAGER_CONFIG" \ + --argstr confAttr "$HOME_MANAGER_CONFIG_ATTRIBUTE" +} + function doBuildAttr() { setConfigFile setHomeManagerNixPath @@ -441,6 +463,8 @@ function doHelp() { echo echo " build Build configuration into result directory" echo + echo " instantiate Instantiate the configuration and print the resulting derivation" + echo echo " switch Build and activate configuration" echo echo " generations List all home environment generations" @@ -471,7 +495,7 @@ while [[ $# -gt 0 ]]; do opt="$1" shift case $opt in - build|edit|expire-generations|generations|help|news|packages|remove-generations|switch|uninstall) + build|instantiate|edit|expire-generations|generations|help|news|packages|remove-generations|switch|uninstall) COMMAND="$opt" ;; -2) @@ -542,6 +566,9 @@ case $COMMAND in build) doBuild ;; + instantiate) + doInstantiate + ;; switch) doSwitch ;;