From 7b73f71fb0f9e8cbd1f34c5f58fa63f48652c9cc Mon Sep 17 00:00:00 2001 From: Timo Kaufmann Date: Wed, 18 Mar 2020 00:02:38 +0100 Subject: [PATCH] Add home-manager 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. --- home-manager/home-manager | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/home-manager/home-manager b/home-manager/home-manager index 7fa5c35c300c..78e793368a50 100644 --- a/home-manager/home-manager +++ b/home-manager/home-manager @@ -74,6 +74,7 @@ function setHomeManagerNixPath() { done } + function doBuildAttr() { setConfigFile setHomeManagerNixPath @@ -89,7 +90,14 @@ function doBuildAttr() { fi # shellcheck disable=2086 - if [[ -v USE_NIX2_COMMAND ]]; then + if [[ -v INSTANTIATE ]]; then + nix-instantiate \ + "" \ + "${extraArgs[@]}" \ + "${PASSTHROUGH_OPTS[@]}" \ + --argstr confPath "$HOME_MANAGER_CONFIG" \ + --argstr confAttr "$HOME_MANAGER_CONFIG_ATTRIBUTE" + elif [[ -v USE_NIX2_COMMAND ]]; then nix build \ -f "" \ "${extraArgs[@]}" \ @@ -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 @@ -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) @@ -542,6 +565,9 @@ case $COMMAND in build) doBuild ;; + instantiate) + doInstantiate + ;; switch) doSwitch ;;