home-manager: handle args with spaces to doBuildAttr

Presently, if you pass an argument with spaces in it to `doBuildAttr`,
it will be split it into multiple arguments to `nix build` or
`nix-build`. This situation arises, for example, on systems with
spaces in `XDG_DATA_HOME`.

Specifically, the `home-manager` script errors out in trying to
address the `read-news` state file. With this change, argument
separation should be preserved properly in `doBuildAttr`.

PR #1044
This commit is contained in:
Chris Hodapp 2020-02-23 02:37:03 -08:00 committed by Robert Helgesson
parent 9ab4e70d17
commit 9ab59dd6ac
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89

View file

@ -78,28 +78,28 @@ function doBuildAttr() {
setConfigFile setConfigFile
setHomeManagerNixPath setHomeManagerNixPath
local extraArgs="$*" local extraArgs=("$@")
for p in "${EXTRA_NIX_PATH[@]}"; do for p in "${EXTRA_NIX_PATH[@]}"; do
extraArgs="$extraArgs -I $p" extraArgs=("${extraArgs[@]}" "-I" "$p")
done done
if [[ -v VERBOSE ]]; then if [[ -v VERBOSE ]]; then
extraArgs="$extraArgs --show-trace" extraArgs=("${extraArgs[@]}" "--show-trace")
fi fi
# shellcheck disable=2086 # shellcheck disable=2086
if [[ -v USE_NIX2_COMMAND ]]; then if [[ -v USE_NIX2_COMMAND ]]; then
nix build \ nix build \
-f "<home-manager/home-manager/home-manager.nix>" \ -f "<home-manager/home-manager/home-manager.nix>" \
$extraArgs \ "${extraArgs[@]}" \
"${PASSTHROUGH_OPTS[@]}" \ "${PASSTHROUGH_OPTS[@]}" \
--argstr confPath "$HOME_MANAGER_CONFIG" \ --argstr confPath "$HOME_MANAGER_CONFIG" \
--argstr confAttr "$HOME_MANAGER_CONFIG_ATTRIBUTE" --argstr confAttr "$HOME_MANAGER_CONFIG_ATTRIBUTE"
else else
nix-build \ nix-build \
"<home-manager/home-manager/home-manager.nix>" \ "<home-manager/home-manager/home-manager.nix>" \
$extraArgs \ "${extraArgs[@]}" \
"${PASSTHROUGH_OPTS[@]}" \ "${PASSTHROUGH_OPTS[@]}" \
--argstr confPath "$HOME_MANAGER_CONFIG" \ --argstr confPath "$HOME_MANAGER_CONFIG" \
--argstr confAttr "$HOME_MANAGER_CONFIG_ATTRIBUTE" --argstr confAttr "$HOME_MANAGER_CONFIG_ATTRIBUTE"