Merge pull request #300335 from amarshall/nixos-rebuild-repl-path

nixos-rebuild: Fix `repl` with a relative flake path
This commit is contained in:
Robert Hensing 2024-04-02 14:22:49 +02:00 committed by GitHub
commit 9ffe63c6fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 2 deletions

View File

@ -559,11 +559,16 @@ if [ "$action" = repl ]; then
blue="$(echo -e '\033[34;1m')"
attention="$(echo -e '\033[35;1m')"
reset="$(echo -e '\033[0m')"
if [[ -e $flake ]]; then
flakePath=$(realpath "$flake")
else
flakePath=$flake
fi
# This nix repl invocation is impure, because usually the flakeref is.
# For a solution that preserves the motd and custom scope, we need
# something like https://github.com/NixOS/nix/issues/8679.
exec nix repl --impure --expr "
let flake = builtins.getFlake ''$flake'';
let flake = builtins.getFlake ''$flakePath'';
configuration = flake.$flakeAttr;
motd = ''
$d{$q\n$q}

View File

@ -113,7 +113,7 @@ runCommand "test-nixos-rebuild-repl" {
# cat -n ~/flake.nix
expect ${writeText "test-nixos-rebuild-repl-expect" ''
expect ${writeText "test-nixos-rebuild-repl-absolute-path-expect" ''
${expectSetup}
spawn sh -c "nixos-rebuild repl --fast --flake path:\$HOME#testconf"
@ -138,6 +138,19 @@ runCommand "test-nixos-rebuild-repl" {
send "lib?nixos\n"
expect_simple "true"
''}
pushd "$HOME"
expect ${writeText "test-nixos-rebuild-repl-relative-path-expect" ''
${expectSetup}
spawn sh -c "nixos-rebuild repl --fast --flake .#testconf"
expect_simple "nix-repl>"
send "config.networking.hostName\n"
expect_simple "itsme"
''}
popd
echo
#########