diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc index 7e3861e2f..7e8a1b9d1 100644 --- a/src/libcmd/installables.cc +++ b/src/libcmd/installables.cc @@ -125,14 +125,17 @@ MixFlakeOptions::MixFlakeOptions() addFlag({ .longName = "override-input", - .description = "Override a specific flake input (e.g. `dwarffs/nixpkgs`). This implies `--no-write-lock-file`.", + .description = + "Override a specific flake input (e.g. `dwarffs/nixpkgs`). The input path must not be empty. This implies `--no-write-lock-file`.", .category = category, .labels = {"input-path", "flake-url"}, .handler = {[&](std::string inputAttrPath, std::string flakeRef) { lockFlags.writeLockFile = false; + auto path = flake::parseInputAttrPath(inputAttrPath); + if (path.empty()) + throw UsageError("--override-input: input path cannot be empty"); lockFlags.inputOverrides.insert_or_assign( - flake::parseInputAttrPath(inputAttrPath), - parseFlakeRef(fetchSettings, flakeRef, absPath(getCommandBaseDir()).string(), true)); + std::move(path), parseFlakeRef(fetchSettings, flakeRef, absPath(getCommandBaseDir()).string(), true)); }}, .completer = {[&](AddCompletions & completions, size_t n, std::string_view prefix) { if (n == 0) { diff --git a/tests/functional/flakes/flakes.sh b/tests/functional/flakes/flakes.sh index d9e187251..c7f0771f9 100755 --- a/tests/functional/flakes/flakes.sh +++ b/tests/functional/flakes/flakes.sh @@ -395,6 +395,9 @@ nix flake lock "$flake3Dir" --override-input flake2/flake1 flake1 nix flake lock "$flake3Dir" --override-input flake2/flake1 flake1/master/"$hash1" [[ $(jq -r .nodes.flake1_2.locked.rev "$flake3Dir/flake.lock") =~ $hash1 ]] +# Test that --override-input with empty input path is rejected (issue #14816). +expectStderr 1 nix flake lock "$flake3Dir" --override-input '' . | grepQuiet "input path cannot be empty" + # Test --update-input. nix flake lock "$flake3Dir" [[ $(jq -r .nodes.flake1_2.locked.rev "$flake3Dir/flake.lock") = "$hash1" ]]