diff options
Diffstat (limited to 'home-manager/home-manager/home-manager')
-rw-r--r-- | home-manager/home-manager/home-manager | 124 |
1 files changed, 60 insertions, 64 deletions
diff --git a/home-manager/home-manager/home-manager b/home-manager/home-manager/home-manager index d5a4c4f41a1..2ad91dc90c4 100644 --- a/home-manager/home-manager/home-manager +++ b/home-manager/home-manager/home-manager @@ -74,36 +74,48 @@ function setHomeManagerNixPath() { done } -function doBuildAttr() { +function doInstantiate() { setConfigFile setHomeManagerNixPath - local extraArgs="$*" + local extraArgs=() for p in "${EXTRA_NIX_PATH[@]}"; do - extraArgs="$extraArgs -I $p" + extraArgs=("${extraArgs[@]}" "-I" "$p") done if [[ -v VERBOSE ]]; then - extraArgs="$extraArgs --show-trace" + extraArgs=("${extraArgs[@]}" "--show-trace") fi - # shellcheck disable=2086 - if [[ -v USE_NIX2_COMMAND ]]; then - nix build \ - -f "<home-manager/home-manager/home-manager.nix>" \ - $extraArgs \ - "${PASSTHROUGH_OPTS[@]}" \ - --argstr confPath "$HOME_MANAGER_CONFIG" \ - --argstr confAttr "$HOME_MANAGER_CONFIG_ATTRIBUTE" - else - nix-build \ - "<home-manager/home-manager/home-manager.nix>" \ - $extraArgs \ - "${PASSTHROUGH_OPTS[@]}" \ - --argstr confPath "$HOME_MANAGER_CONFIG" \ - --argstr confAttr "$HOME_MANAGER_CONFIG_ATTRIBUTE" + nix-instantiate \ + "<home-manager/home-manager/home-manager.nix>" \ + "${extraArgs[@]}" \ + "${PASSTHROUGH_OPTS[@]}" \ + --argstr confPath "$HOME_MANAGER_CONFIG" \ + --argstr confAttr "$HOME_MANAGER_CONFIG_ATTRIBUTE" +} + +function doBuildAttr() { + setConfigFile + setHomeManagerNixPath + + local extraArgs=("$@") + + for p in "${EXTRA_NIX_PATH[@]}"; do + extraArgs=("${extraArgs[@]}" "-I" "$p") + done + + if [[ -v VERBOSE ]]; then + extraArgs=("${extraArgs[@]}" "--show-trace") fi + + nix-build \ + "<home-manager/home-manager/home-manager.nix>" \ + "${extraArgs[@]}" \ + "${PASSTHROUGH_OPTS[@]}" \ + --argstr confPath "$HOME_MANAGER_CONFIG" \ + --argstr confAttr "$HOME_MANAGER_CONFIG_ATTRIBUTE" } # Presents news to the user. Takes as argument the path to a "news @@ -169,13 +181,8 @@ function doBuild() { local exitCode - if [[ -v USE_NIX2_COMMAND ]]; then - doBuildAttr activationPackage \ - && exitCode=0 || exitCode=1 - else - doBuildAttr --attr activationPackage \ - && exitCode=0 || exitCode=1 - fi + doBuildAttr --attr activationPackage \ + && exitCode=0 || exitCode=1 presentNews "$newsInfo" @@ -197,17 +204,10 @@ function doSwitch() { # before activation completes. generation="$WORK_DIR/generation" - if [[ -v USE_NIX2_COMMAND ]]; then - doBuildAttr \ - --out-link "$generation" \ - activationPackage \ - && "$generation/activate" || exitCode=1 - else - doBuildAttr \ - --out-link "$generation" \ - --attr activationPackage \ - && "$generation/activate" || exitCode=1 - fi + doBuildAttr \ + --out-link "$generation" \ + --attr activationPackage \ + && "$generation/activate" || exitCode=1 presentNews "$newsInfo" @@ -221,7 +221,7 @@ function doListGens() { color="always" fi - pushd "/nix/var/nix/profiles/per-user/$USER" > /dev/null + pushd "$NIX_STATE_DIR/profiles/per-user/$USER" > /dev/null # shellcheck disable=2012 ls --color=$color -gG --time-style=long-iso --sort time home-manager-*-link \ | cut -d' ' -f 4- \ @@ -234,7 +234,7 @@ function doListGens() { function doRmGenerations() { setVerboseAndDryRun - pushd "/nix/var/nix/profiles/per-user/$USER" > /dev/null + pushd "$NIX_STATE_DIR/profiles/per-user/$USER" > /dev/null for generationId in "$@"; do local linkName="home-manager-$generationId-link" @@ -254,11 +254,11 @@ function doRmGenerations() { function doRmAllGenerations() { $DRY_RUN_CMD rm $VERBOSE_ARG \ - "/nix/var/nix/profiles/per-user/$USER/home-manager"* + "$NIX_STATE_DIR/profiles/per-user/$USER/home-manager"* } function doExpireGenerations() { - local profileDir="/nix/var/nix/profiles/per-user/$USER" + local profileDir="$NIX_STATE_DIR/profiles/per-user/$USER" local generations generations="$( \ @@ -307,23 +307,14 @@ function buildNews() { local output output="$WORK_DIR/news-info.sh" - if [[ -v USE_NIX2_COMMAND ]]; then - doBuildAttr \ - --out-link "$output" \ - --quiet \ - --arg check false \ - --argstr newsReadIdsFile "$(newsReadIdsFile)" \ - newsInfo - else - doBuildAttr \ - --out-link "$output" \ - --no-build-output \ - --quiet \ - --arg check false \ - --argstr newsReadIdsFile "$(newsReadIdsFile)" \ - --attr newsInfo \ - > /dev/null - fi + doBuildAttr \ + --out-link "$output" \ + --no-build-output \ + --quiet \ + --arg check false \ + --argstr newsReadIdsFile "$(newsReadIdsFile)" \ + --attr newsInfo \ + > /dev/null echo "$output" } @@ -375,13 +366,14 @@ function doUninstall() { y|Y) echo "Switching to empty Home Manager configuration..." HOME_MANAGER_CONFIG="$(mktemp --tmpdir home-manager.XXXXXXXXXX)" - echo "{}" > "$HOME_MANAGER_CONFIG" + echo "{ lib, ... }: { home.file = lib.mkForce {}; }" > "$HOME_MANAGER_CONFIG" doSwitch + $DRY_RUN_CMD nix-env -e home-manager-path || true rm "$HOME_MANAGER_CONFIG" $DRY_RUN_CMD rm $VERBOSE_ARG -r \ "${XDG_DATA_HOME:-$HOME/.local/share}/home-manager" $DRY_RUN_CMD rm $VERBOSE_ARG \ - "/nix/var/nix/gcroots/per-user/$USER/current-home" + "$NIX_STATE_DIR/gcroots/per-user/$USER/current-home" ;; *) echo "Yay!" @@ -441,6 +433,8 @@ function doHelp() { echo echo " build Build configuration into result directory" echo + echo " instantiate Instantiate the configuration and print the resulting derivation" + echo echo " switch Build and activate configuration" echo echo " generations List all home environment generations" @@ -461,6 +455,8 @@ function doHelp() { echo " uninstall Remove Home Manager" } +readonly NIX_STATE_DIR="${NIX_STATE_DIR:-/nix/var/nix}" + EXTRA_NIX_PATH=() HOME_MANAGER_CONFIG_ATTRIBUTE="" PASSTHROUGH_OPTS=() @@ -471,12 +467,9 @@ 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) - USE_NIX2_COMMAND=1 - ;; -A) HOME_MANAGER_CONFIG_ATTRIBUTE="$1" shift @@ -542,6 +535,9 @@ case $COMMAND in build) doBuild ;; + instantiate) + doInstantiate + ;; switch) doSwitch ;; |