diff options
Diffstat (limited to 'home-manager/home-manager')
-rw-r--r-- | home-manager/home-manager/completion.bash | 2 | ||||
-rw-r--r-- | home-manager/home-manager/home-manager | 124 | ||||
-rw-r--r-- | home-manager/home-manager/home-manager.nix | 4 | ||||
-rw-r--r-- | home-manager/home-manager/install.nix | 19 |
4 files changed, 81 insertions, 68 deletions
diff --git a/home-manager/home-manager/completion.bash b/home-manager/home-manager/completion.bash index 501b87279fa..e9f04578916 100644 --- a/home-manager/home-manager/completion.bash +++ b/home-manager/home-manager/completion.bash @@ -278,7 +278,7 @@ _home-manager_completions () #--------------------------# local Subcommands - Subcommands=( "help" "edit" "build" "switch" "generations" "remove-generations" "expire-generations" "packages" "news" "uninstall" ) + Subcommands=( "help" "edit" "build" "instantiate" "switch" "generations" "remove-generations" "expire-generations" "packages" "news" "uninstall" ) # ^ ยซ home-manager ยป's subcommands. 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 ;; diff --git a/home-manager/home-manager/home-manager.nix b/home-manager/home-manager/home-manager.nix index 7a6748942c8..04c2d28d32b 100644 --- a/home-manager/home-manager/home-manager.nix +++ b/home-manager/home-manager/home-manager.nix @@ -1,6 +1,6 @@ { pkgs ? import <nixpkgs> {} , confPath -, confAttr +, confAttr ? null , check ? true , newsReadIdsFile ? null }: @@ -11,7 +11,7 @@ let env = import ../modules { configuration = - if confAttr == "" + if confAttr == "" || confAttr == null then confPath else (import confPath).${confAttr}; pkgs = pkgs; diff --git a/home-manager/home-manager/install.nix b/home-manager/home-manager/install.nix index 87aae50470e..87252730e6f 100644 --- a/home-manager/home-manager/install.nix +++ b/home-manager/home-manager/install.nix @@ -12,6 +12,18 @@ runCommand "home-manager-install" { echo echo "Creating initial Home Manager configuration..." + nl=$'\n' + xdgVars="" + if [[ -v XDG_CACHE_HOME && $XDG_CACHE_HOME != "$HOME/.cache" ]]; then + xdgVars="$xdgVars xdg.cacheHome = \"$XDG_CACHE_HOME\";$nl" + fi + if [[ -v XDG_CONFIG_HOME && $XDG_CONFIG_HOME != "$HOME/.config" ]]; then + xdgVars="$xdgVars xdg.configHome = \"$XDG_CONFIG_HOME\";$nl" + fi + if [[ -v XDG_DATA_HOME && $XDG_DATA_HOME != "$HOME/.local/share" ]]; then + xdgVars="$xdgVars xdg.dataHome = \"$XDG_DATA_HOME\";$nl" + fi + mkdir -p "$(dirname "$confFile")" cat > $confFile <<EOF { config, pkgs, ... }: @@ -20,6 +32,11 @@ runCommand "home-manager-install" { # Let Home Manager install and manage itself. programs.home-manager.enable = true; + # Home Manager needs a bit of information about you and the + # paths it should manage. + home.username = "$USER"; + home.homeDirectory = "$HOME"; + $xdgVars # This value determines the Home Manager release that your # configuration is compatible with. This helps avoid breakage # when a new Home Manager release introduces backwards @@ -28,7 +45,7 @@ runCommand "home-manager-install" { # You can update Home Manager without changing this value. See # the Home Manager release notes for a list of state version # changes in each release. - home.stateVersion = "19.09"; + home.stateVersion = "20.09"; } EOF fi |