home-manager: simplify use of nix-build output

There is no need to specify an out link when switching to a new
generation since nix-build prints the store path on standard output.
Similarly, when just building a generation we specify no out link
since nix-build will use "result" by default.
This commit is contained in:
Robert Helgesson 2017-08-27 12:55:30 +02:00
parent e561beab44
commit 2245b0ac94
No known key found for this signature in database
GPG key ID: C3DB11069E65DC86

View file

@ -49,27 +49,11 @@ function setHomeManagerModulesPath() {
} }
function doBuild() { function doBuild() {
if [[ -z "$1" ]]; then
echo "Need to provide generation output path."
exit 1
fi
if [[ -e "$1" ]]; then
echo "The output path $1 already exists."
exit 1
fi
setConfigFile setConfigFile
setHomeManagerModulesPath setHomeManagerModulesPath
output="$(realpath "$1")"
if [[ $? -ne 0 ]]; then
exit 1
fi
local extraArgs local extraArgs
extraArgs="" extraArgs="$1"
for p in "${EXTRA_NIX_PATH[@]}"; do for p in "${EXTRA_NIX_PATH[@]}"; do
extraArgs="$extraArgs -I $p" extraArgs="$extraArgs -I $p"
@ -83,21 +67,15 @@ function doBuild() {
"@HOME_MANAGER_EXPR_PATH@" \ "@HOME_MANAGER_EXPR_PATH@" \
--argstr confPath "$HOME_MANAGER_CONFIG" \ --argstr confPath "$HOME_MANAGER_CONFIG" \
--argstr confAttr "$HOME_MANAGER_CONFIG_ATTRIBUTE" \ --argstr confAttr "$HOME_MANAGER_CONFIG_ATTRIBUTE" \
-A activation-script \ -A activation-script
-o "$output"
} }
function doSwitch() { function doSwitch() {
local wrkdir
wrkdir="$(mktemp -d)"
local generation local generation
local exitCode=0 local exitCode=0
generation=$(doBuild "$wrkdir/result") && $generation/activate || exitCode=1
# Because the previous command never fails, the script keeps running and generation=$(doBuild "--no-out-link") && $generation/activate || exitCode=1
# $wrkdir is always removed.
rm -r "$wrkdir"
return $exitCode return $exitCode
} }
@ -179,7 +157,7 @@ cmd="$*"
case "$cmd" in case "$cmd" in
build) build)
doBuild "result" doBuild ""
;; ;;
switch) switch)
doSwitch doSwitch