mirror of
https://github.com/nix-community/home-manager
synced 2024-11-23 19:49:45 +01:00
home-manager: do not build news when using flake (#2501)
Currently, the `buildNews` and `doBuildAttrs` are always called unconditionally even if a flake configuration is specified. This cause it to always fail prior to the actual build performed by `doBuildAttrs` because `setConfigFIle` can not find the home-manager configuration file. As a result, an error message specifying no configuration file is shown. Furthermore, if a user has remnant legacy configuration, the `doSwitch` and `doBuild` functions will effectively build the activationPackage twice, with the legacy configuration overriding the flake configuration. A conditional check for FLAKE_CONFIG_URI was added to mitigate this by building the legacy configuration when no flake configuration is present. There is one exception which is when a flake configuration exists in the default location, where the user can not build the legacy configuration as along as the file is present. However, the tradeoff is acceptable as it matches current behavior when FLAKe_CONFIG_URI is set for instantiation, and an user is unlikely to simulataneously switch between the two mechanisms. An abstract function for building flakes `doBuildFlake` was created to match `doBuildAttrs` for manageing options and build flags. The --no-write-lock-file flag was removed from the --debug case as it is already matched previously at the --recreate-lock-file case.
This commit is contained in:
parent
df931a59a5
commit
609370699f
1 changed files with 52 additions and 42 deletions
|
@ -186,6 +186,18 @@ function doBuildAttr() {
|
||||||
--argstr confAttr "$HOME_MANAGER_CONFIG_ATTRIBUTE"
|
--argstr confAttr "$HOME_MANAGER_CONFIG_ATTRIBUTE"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function doBuildFlake() {
|
||||||
|
local extraArgs=("$@")
|
||||||
|
|
||||||
|
if [[ -v VERBOSE ]]; then
|
||||||
|
extraArgs=("${extraArgs[@]}" "--verbose")
|
||||||
|
fi
|
||||||
|
|
||||||
|
nix build \
|
||||||
|
"${extraArgs[@]}" \
|
||||||
|
"${PASSTHROUGH_OPTS[@]}"
|
||||||
|
}
|
||||||
|
|
||||||
# Presents news to the user. Takes as argument the path to a "news
|
# Presents news to the user. Takes as argument the path to a "news
|
||||||
# info" file as generated by `buildNews`.
|
# info" file as generated by `buildNews`.
|
||||||
function presentNews() {
|
function presentNews() {
|
||||||
|
@ -246,43 +258,31 @@ function doBuild() {
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
setFlakeAttribute
|
|
||||||
if [[ -v FLAKE_CONFIG_URI ]]; then
|
|
||||||
nix build \
|
|
||||||
"${PASSTHROUGH_OPTS[@]}" \
|
|
||||||
${DRY_RUN+--dry-run} \
|
|
||||||
${NO_OUT_LINK+--no-link} \
|
|
||||||
"$FLAKE_CONFIG_URI.activationPackage" \
|
|
||||||
|| return
|
|
||||||
fi
|
|
||||||
|
|
||||||
setWorkDir
|
setWorkDir
|
||||||
|
|
||||||
local newsInfo
|
setFlakeAttribute
|
||||||
newsInfo=$(buildNews)
|
if [[ -v FLAKE_CONFIG_URI ]]; then
|
||||||
|
doBuildFlake \
|
||||||
doBuildAttr \
|
"${DRY_RUN+--dry-run} \
|
||||||
${NO_OUT_LINK+--no-out-link} \
|
"${NO_OUT_LINK+--no-link} \
|
||||||
--attr activationPackage \
|
"$FLAKE_CONFIG_URI.activationPackage" \
|
||||||
|
|| return
|
||||||
|
else
|
||||||
|
doBuildAttr \
|
||||||
|
${NO_OUT_LINK+--no-out-link} \
|
||||||
|
--attr activationPackage \
|
||||||
|| return
|
|| return
|
||||||
|
|
||||||
presentNews "$newsInfo"
|
local newsInfo
|
||||||
|
newsInfo=$(buildNews)
|
||||||
|
|
||||||
|
presentNews "$newsInfo"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function doSwitch() {
|
function doSwitch() {
|
||||||
setFlakeAttribute
|
|
||||||
if [[ -v FLAKE_CONFIG_URI ]]; then
|
|
||||||
nix run \
|
|
||||||
"${PASSTHROUGH_OPTS[@]}" \
|
|
||||||
"$FLAKE_CONFIG_URI.activationPackage" \
|
|
||||||
|| return
|
|
||||||
fi
|
|
||||||
|
|
||||||
setWorkDir
|
setWorkDir
|
||||||
|
|
||||||
local newsInfo
|
|
||||||
newsInfo=$(buildNews)
|
|
||||||
|
|
||||||
local generation
|
local generation
|
||||||
|
|
||||||
# Build the generation and run the activate script. Note, we
|
# Build the generation and run the activate script. Note, we
|
||||||
|
@ -291,12 +291,23 @@ function doSwitch() {
|
||||||
# before activation completes.
|
# before activation completes.
|
||||||
generation="$WORK_DIR/generation"
|
generation="$WORK_DIR/generation"
|
||||||
|
|
||||||
doBuildAttr \
|
setFlakeAttribute
|
||||||
--out-link "$generation" \
|
if [[ -v FLAKE_CONFIG_URI ]]; then
|
||||||
--attr activationPackage \
|
doBuildFlake \
|
||||||
&& "$generation/activate" || return
|
--out-link "$generation" \
|
||||||
|
"$FLAKE_CONFIG_URI.activationPackage" \
|
||||||
|
&& "$generation/activate" || return
|
||||||
|
else
|
||||||
|
doBuildAttr \
|
||||||
|
--out-link "$generation" \
|
||||||
|
--attr activationPackage \
|
||||||
|
&& "$generation/activate" || return
|
||||||
|
|
||||||
presentNews "$newsInfo"
|
local newsInfo
|
||||||
|
newsInfo=$(buildNews)
|
||||||
|
|
||||||
|
presentNews "$newsInfo"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function doListGens() {
|
function doListGens() {
|
||||||
|
@ -393,13 +404,13 @@ function buildNews() {
|
||||||
output="$WORK_DIR/news-info.sh"
|
output="$WORK_DIR/news-info.sh"
|
||||||
|
|
||||||
doBuildAttr \
|
doBuildAttr \
|
||||||
--out-link "$output" \
|
--out-link "$output" \
|
||||||
--no-build-output \
|
--no-build-output \
|
||||||
--quiet \
|
--quiet \
|
||||||
--arg check false \
|
--arg check false \
|
||||||
--argstr newsReadIdsFile "$(newsReadIdsFile)" \
|
--argstr newsReadIdsFile "$(newsReadIdsFile)" \
|
||||||
--attr newsInfo \
|
--attr newsInfo \
|
||||||
> /dev/null
|
> /dev/null
|
||||||
|
|
||||||
echo "$output"
|
echo "$output"
|
||||||
}
|
}
|
||||||
|
@ -616,8 +627,7 @@ while [[ $# -gt 0 ]]; do
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--debug|--keep-failed|--keep-going|--show-trace\
|
--debug|--keep-failed|--keep-going|--show-trace\
|
||||||
|--substitute|--no-substitute|--impure\
|
|--substitute|--no-substitute|--impure)
|
||||||
|--no-write-lock-file)
|
|
||||||
PASSTHROUGH_OPTS+=("$opt")
|
PASSTHROUGH_OPTS+=("$opt")
|
||||||
;;
|
;;
|
||||||
-v|--verbose)
|
-v|--verbose)
|
||||||
|
|
Loading…
Reference in a new issue