Skip to content

Commit

Permalink
home-manager: add instantiate subcommand
Browse files Browse the repository at this point in the history
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 nix-community#1099
  • Loading branch information
timokau authored and NickHu committed May 19, 2020
1 parent de4895c commit dfd0434
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
14 changes: 14 additions & 0 deletions doc/man-home-manager.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
build
</arg>

<arg choice="plain">
instantiate
</arg>

<arg choice="plain">
edit
</arg>
Expand Down Expand Up @@ -163,6 +167,16 @@
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>instantiate</option>
</term>
<listitem>
<para>
Instantiate the configuration and print the resulting derivation.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>edit</option>
Expand Down
2 changes: 1 addition & 1 deletion home-manager/completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
29 changes: 28 additions & 1 deletion home-manager/home-manager
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
"<home-manager/home-manager/home-manager.nix>" \
"${extraArgs[@]}" \
"${PASSTHROUGH_OPTS[@]}" \
--argstr confPath "$HOME_MANAGER_CONFIG" \
--argstr confAttr "$HOME_MANAGER_CONFIG_ATTRIBUTE"
}

function doBuildAttr() {
setConfigFile
setHomeManagerNixPath
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -542,6 +566,9 @@ case $COMMAND in
build)
doBuild
;;
instantiate)
doInstantiate
;;
switch)
doSwitch
;;
Expand Down

0 comments on commit dfd0434

Please sign in to comment.