mirror of
https://github.com/nix-community/home-manager
synced 2024-12-27 20:29:47 +01:00
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:
parent
e561beab44
commit
2245b0ac94
1 changed files with 5 additions and 27 deletions
|
@ -49,27 +49,11 @@ function setHomeManagerModulesPath() {
|
|||
}
|
||||
|
||||
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
|
||||
setHomeManagerModulesPath
|
||||
|
||||
output="$(realpath "$1")"
|
||||
|
||||
if [[ $? -ne 0 ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local extraArgs
|
||||
extraArgs=""
|
||||
extraArgs="$1"
|
||||
|
||||
for p in "${EXTRA_NIX_PATH[@]}"; do
|
||||
extraArgs="$extraArgs -I $p"
|
||||
|
@ -83,21 +67,15 @@ function doBuild() {
|
|||
"@HOME_MANAGER_EXPR_PATH@" \
|
||||
--argstr confPath "$HOME_MANAGER_CONFIG" \
|
||||
--argstr confAttr "$HOME_MANAGER_CONFIG_ATTRIBUTE" \
|
||||
-A activation-script \
|
||||
-o "$output"
|
||||
-A activation-script
|
||||
}
|
||||
|
||||
function doSwitch() {
|
||||
local wrkdir
|
||||
wrkdir="$(mktemp -d)"
|
||||
|
||||
local generation
|
||||
local exitCode=0
|
||||
generation=$(doBuild "$wrkdir/result") && $generation/activate || exitCode=1
|
||||
|
||||
# Because the previous command never fails, the script keeps running and
|
||||
# $wrkdir is always removed.
|
||||
rm -r "$wrkdir"
|
||||
generation=$(doBuild "--no-out-link") && $generation/activate || exitCode=1
|
||||
|
||||
return $exitCode
|
||||
}
|
||||
|
||||
|
@ -179,7 +157,7 @@ cmd="$*"
|
|||
|
||||
case "$cmd" in
|
||||
build)
|
||||
doBuild "result"
|
||||
doBuild ""
|
||||
;;
|
||||
switch)
|
||||
doSwitch
|
||||
|
|
Loading…
Reference in a new issue