mirror of
https://github.com/NixOS/nix.git
synced 2025-12-23 17:31:08 +01:00
libcmd: reject empty --override-input paths
An empty attribute path refers to the flake itself, contradicting the purpose of --override-input, which is for overriding inputs. Fixes: #14816
This commit is contained in:
parent
132a93625b
commit
fefcc4c7cc
2 changed files with 9 additions and 3 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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" ]]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue