From cab8104e9236fab1eb9a702165454ffed353c20f Mon Sep 17 00:00:00 2001 From: Adam Dinwoodie Date: Mon, 30 Jun 2025 00:12:33 +0100 Subject: [PATCH] home-manager: add repl subcommand (#5600) Similar to the `nixos-rebuild repl` command, `home-manager repl` will launch the Nix read-evaluate-print-loop environment with the Home Manager configuration loaded. To make that more useful, also add the pkgs and options attributes from the generated Home Manager configuration to the environment. This doesn't currently work with flakes, because I don't use them and I'm not confident I could safely test that function. --- home-manager/home-manager | 30 +++++++++++++++++++++++++++++- home-manager/home-manager.nix | 7 ++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/home-manager/home-manager b/home-manager/home-manager index 1a27dc4db..969f704ed 100644 --- a/home-manager/home-manager +++ b/home-manager/home-manager @@ -637,6 +637,28 @@ function doBuild() { presentNews } +function doRepl() { + setFlakeAttribute + if [[ -v FLAKE_CONFIG_URI ]]; then + _i 'home-manager repl does not (yet) support flakes' >&2 + return 1 + fi + + setConfigFile + + extraArgs=() + for p in "${EXTRA_NIX_PATH[@]}"; do + extraArgs+=(-I "$p") + done + + exec nix repl \ + --file '' \ + "${extraArgs[@]}" \ + "${PASSTHROUGH_OPTS[@]}" \ + --argstr confPath "$HOME_MANAGER_CONFIG" \ + --argstr confAttr "$HOME_MANAGER_CONFIG_ATTRIBUTE" +} + function doSwitch() { setWorkDir @@ -941,6 +963,9 @@ function doHelp() { echo " Remove indicated generations. Use 'generations' command to" echo " find suitable generation numbers." echo + echo " repl" + echo " Opens the configuration in \`nix repl\`" + echo echo " expire-generations TIMESTAMP" echo " Remove generations older than TIMESTAMP where TIMESTAMP is" echo " interpreted as in the -d argument of the date tool. For" @@ -964,7 +989,7 @@ while [[ $# -gt 0 ]]; do opt="$1" shift case $opt in - build|init|instantiate|option|edit|expire-generations|generations|help|news|packages|remove-generations|switch|uninstall) + build|init|instantiate|option|edit|expire-generations|generations|help|news|packages|remove-generations|repl|switch|uninstall) COMMAND="$opt" ;; -A) @@ -1109,6 +1134,9 @@ case $COMMAND in packages) doListPackages ;; + repl) + doRepl + ;; news) doShowNews --all ;; diff --git a/home-manager/home-manager.nix b/home-manager/home-manager.nix index 89dd66139..084fbd2f2 100644 --- a/home-manager/home-manager.nix +++ b/home-manager/home-manager.nix @@ -16,5 +16,10 @@ let in { - inherit (env) activationPackage config; + inherit (env) + activationPackage + config + pkgs + options + ; }