Skip to content

Commit

Permalink
Add home-manager 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.
  • Loading branch information
timokau committed Mar 17, 2020
1 parent 5c1e734 commit 7b73f71
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions home-manager/home-manager
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function setHomeManagerNixPath() {
done
}


function doBuildAttr() {
setConfigFile
setHomeManagerNixPath
Expand All @@ -89,7 +90,14 @@ function doBuildAttr() {
fi

# shellcheck disable=2086
if [[ -v USE_NIX2_COMMAND ]]; then
if [[ -v INSTANTIATE ]]; then
nix-instantiate \
"<home-manager/home-manager/home-manager.nix>" \
"${extraArgs[@]}" \
"${PASSTHROUGH_OPTS[@]}" \
--argstr confPath "$HOME_MANAGER_CONFIG" \
--argstr confAttr "$HOME_MANAGER_CONFIG_ATTRIBUTE"
elif [[ -v USE_NIX2_COMMAND ]]; then
nix build \
-f "<home-manager/home-manager/home-manager.nix>" \
"${extraArgs[@]}" \
Expand Down Expand Up @@ -182,6 +190,21 @@ function doBuild() {
return $exitCode
}

function doInstantiate() {
local exitCode

INSTANTIATE=1
if [[ -v USE_NIX2_COMMAND ]]; then
doBuildAttr activationPackage \
&& exitCode=0 || exitCode=1
else
doBuildAttr --attr activationPackage \
&& exitCode=0 || exitCode=1
fi

return $exitCode
}

function doSwitch() {
setWorkDir

Expand Down Expand Up @@ -471,7 +494,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 +565,9 @@ case $COMMAND in
build)
doBuild
;;
instantiate)
doInstantiate
;;
switch)
doSwitch
;;
Expand Down

0 comments on commit 7b73f71

Please sign in to comment.