From 392ddb642abec771d63688c49fa7bcbb9d2a5717 Mon Sep 17 00:00:00 2001 From: Adam Dinwoodie Date: Sat, 12 Jul 2025 03:16:06 +0100 Subject: [PATCH] home-manager: add flake support for repl command (#7439) Extend the `home-manager repl` command to support flakes. This is heavily based on the equivalent `nixos-rebuild repl` code. --- home-manager/home-manager | 43 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/home-manager/home-manager b/home-manager/home-manager index 969f704e..3edc43dd 100644 --- a/home-manager/home-manager +++ b/home-manager/home-manager @@ -212,6 +212,8 @@ function setFlakeAttribute() { ;; esac export FLAKE_CONFIG_URI="$flake#homeConfigurations.\"$(printf %s "$name" | jq -sRr @uri)\"" + export FLAKE_PATH="$flake" + export FLAKE_ATTR="homeConfigurations.\"$name\"" fi } @@ -639,9 +641,46 @@ function doBuild() { function doRepl() { setFlakeAttribute + if [[ -v FLAKE_CONFIG_URI ]]; then - _i 'home-manager repl does not (yet) support flakes' >&2 - return 1 + printf -v bold '\033[1m' + printf -v blue '\033[34;1m' + printf -v reset '\033[0m' + exec nix repl --expr " + let + flake = builtins.getFlake ''$FLAKE_PATH''; + configuration = flake.$FLAKE_ATTR; + motd = '' + + + Hello and welcome to the Home Manager configuration + $FLAKE_ATTR + in $FLAKE_PATH + + The following is loaded into nix repl's scope: + + - ${blue}config${reset} All option values + - ${blue}options${reset} Option data and metadata + - ${blue}pkgs${reset} Nixpkgs package set + - ${blue}lib${reset} Nixpkgs library functions + + - ${blue}flake${reset} Flake outputs, inputs and source info of $FLAKE_PATH + + Use tab completion to browse around ${blue}config${reset}. + + Use ${bold}:r${reset} to ${bold}reload${reset} everything after making a change in the flake. + + See ${bold}:?${reset} for more repl commands. + ''; + scope = + assert configuration.class or ''homeManager'' == ''homeManager''; + { + inherit (configuration) config options pkgs; + inherit (configuration.pkgs) lib; + inherit flake; + }; + in builtins.seq scope builtins.trace motd scope + " "${PASSTHROUGH_OPTS[@]}" fi setConfigFile