Description
This command updates the user environment so that it corresponds to the
- configuration specified in ~/.config/nixpkgs/home.nix.
+ configuration specified in ~/.config/nixpkgs/home.nix or ~/.config/nixpkgs/flake.nix.
All operations using this tool expects a sub-command that indicates the
@@ -343,6 +347,18 @@
+
+
+
+
+
+
+ Build Home Manager configuration from the flake, which must contain the
+ output homeConfigurations.name. If no name is specified it will first try
+ username@hostname and then username.
+
+
+
diff --git a/home-manager/home-manager b/home-manager/home-manager
index d1007c9d6..47ef2d692 100644
--- a/home-manager/home-manager
+++ b/home-manager/home-manager
@@ -74,7 +74,35 @@ function setHomeManagerNixPath() {
done
}
+function setFlakeAttribute() {
+ local configFlake="${XDG_CONFIG_HOME:-$HOME/.config}/nixpkgs/flake.nix"
+ if [[ -z $FLAKE_ARG && ! -v HOME_MANAGER_CONFIG && -e "$configFlake" ]]; then
+ FLAKE_ARG="$(dirname "$(readlink -f "$configFlake")")"
+ fi
+
+ if [[ -n "$FLAKE_ARG" ]]; then
+ local flake="${FLAKE_ARG%#*}"
+ case $FLAKE_ARG in
+ *#*)
+ local name="${FLAKE_ARG#*#}"
+ ;;
+ *)
+ local name="$USER@$(hostname)"
+ if [ "$(nix eval "$flake#homeConfigurations" --apply "x: x ? \"$name\"")" = "false" ]; then
+ name="$USER"
+ fi
+ ;;
+ esac
+ export FLAKE_CONFIG_URI="$flake#homeConfigurations.\"$name\""
+ fi
+}
+
function doInstantiate() {
+ setFlakeAttribute
+ if [[ -v FLAKE_CONFIG_URI ]]; then
+ errorEcho "Can't instantiate a flake configuration"
+ exit 1
+ fi
setConfigFile
setHomeManagerNixPath
@@ -178,6 +206,17 @@ function doBuild() {
return 1
fi
+ setFlakeAttribute
+ if [[ -v FLAKE_CONFIG_URI ]]; then
+ local exitCode=0
+ nix build \
+ "${PASSTHROUGH_OPTS[@]}" \
+ ${DRY_RUN+--dry-run} \
+ "$FLAKE_CONFIG_URI.activationPackage" \
+ || exitCode=1
+ return $exitCode
+ fi
+
setWorkDir
local newsInfo
@@ -194,6 +233,16 @@ function doBuild() {
}
function doSwitch() {
+ setFlakeAttribute
+ if [[ -v FLAKE_CONFIG_URI ]]; then
+ local exitCode=0
+ nix run \
+ "${PASSTHROUGH_OPTS[@]}" \
+ "$FLAKE_CONFIG_URI.activationPackage" \
+ || exitCode=1
+ return $exitCode
+ fi
+
setWorkDir
local newsInfo
@@ -409,15 +458,16 @@ function doHelp() {
echo
echo "Options"
echo
- echo " -f FILE The home configuration file."
- echo " Default is '~/.config/nixpkgs/home.nix'."
- echo " -A ATTRIBUTE Optional attribute that selects a configuration"
- echo " expression in the configuration file."
- echo " -I PATH Add a path to the Nix expression search path."
- echo " -b EXT Move existing files to new path rather than fail."
- echo " -v Verbose output"
- echo " -n Do a dry run, only prints what actions would be taken"
- echo " -h Print this help"
+ echo " -f FILE The home configuration file."
+ echo " Default is '~/.config/nixpkgs/home.nix'."
+ echo " -A ATTRIBUTE Optional attribute that selects a configuration"
+ echo " expression in the configuration file."
+ echo " -I PATH Add a path to the Nix expression search path."
+ echo " --flake flake-uri Use home-manager configuration at flake-uri"
+ echo " -b EXT Move existing files to new path rather than fail."
+ echo " -v Verbose output"
+ echo " -n Do a dry run, only prints what actions would be taken"
+ echo " -h Print this help"
echo
echo "Options passed on to nix-build(1)"
echo
@@ -467,6 +517,7 @@ HOME_MANAGER_CONFIG_ATTRIBUTE=""
PASSTHROUGH_OPTS=()
COMMAND=""
COMMAND_ARGS=()
+FLAKE_ARG=""
while [[ $# -gt 0 ]]; do
opt="$1"
@@ -491,6 +542,21 @@ while [[ $# -gt 0 ]]; do
HOME_MANAGER_CONFIG="$1"
shift
;;
+ --flake)
+ FLAKE_ARG="$1"
+ shift
+ ;;
+ --recreate-lock-file|--no-update-lock-file|--no-write-lock-file|--no-registries|--commit-lock-file)
+ PASSTHROUGH_OPTS+=("$opt")
+ ;;
+ --update-input)
+ PASSTHROUGH_OPTS+=("$opt" "$1")
+ shift
+ ;;
+ --override-input)
+ PASSTHROUGH_OPTS+=("$opt" "$1" "$2")
+ shift 2
+ ;;
-h|--help)
doHelp
exit 0
diff --git a/modules/home-environment.nix b/modules/home-environment.nix
index e5b6cc3a6..b9b3a8cc8 100644
--- a/modules/home-environment.nix
+++ b/modules/home-environment.nix
@@ -552,6 +552,9 @@ in
cp ${activationScript} $out/activate
+ mkdir $out/bin
+ ln -s $out/activate $out/bin/home-manager-generation
+
substituteInPlace $out/activate \
--subst-var-by GENERATION_DIR $out