Skip to content

Commit

Permalink
nix flake update add deprecation warnings.
Browse files Browse the repository at this point in the history
This builds on NixOS#8817, to add additional UX help for people with existing
muscle memory (or shell history) with --update-input and tries to gently
guide them towards the newly evolved CLI UI.

Co-authored-by: Cole Helbling <cole.e.helbling@outlook.com>
  • Loading branch information
angerman and cole-h committed Nov 25, 2023
1 parent dda0e34 commit af00298
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/libcmd/installables.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ MixFlakeOptions::MixFlakeOptions()
{
auto category = "Common flake-related options";

addFlag({
.longName = "recreate-lock-file",
.description = "Recreate the flake's lock file from scratch.",
.category = category,
.handler = {[&]() {
lockFlags.recreateLockFile = true;
warn("'--recreate-lock-file' is deprecated and will be removed in a future version; use 'nix flake update' instead.");
}}
});

addFlag({
.longName = "no-update-lock-file",
.description = "Do not allow any updates to the flake's lock file.",
Expand Down Expand Up @@ -79,6 +89,20 @@ MixFlakeOptions::MixFlakeOptions()
.handler = {&lockFlags.commitLockFile, true}
});

addFlag({
.longName = "update-input",
.description = "Update a specific flake input (ignoring its previous entry in the lock file).",
.category = category,
.labels = {"input-path"},
.handler = {[&](std::string s) {
warn("'--update-input' is a deprecated alias for 'flake update' and will be removed in a future version.");
lockFlags.inputUpdates.insert(flake::parseInputPath(s));
}},
.completer = {[&](AddCompletions & completions, size_t, std::string_view prefix) {
completeFlakeInputPath(completions, getEvalState(), getFlakeRefsForCompletion(), prefix);
}}
});

addFlag({
.longName = "override-input",
.description = "Override a specific flake input (e.g. `dwarffs/nixpkgs`). This implies `--no-write-lock-file`.",
Expand Down
8 changes: 7 additions & 1 deletion src/nix/flake.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,13 @@ struct CmdFlakeUpdate : FlakeCommand
.label="inputs",
.optional=true,
.handler={[&](std::string inputToUpdate){
auto inputPath = flake::parseInputPath(inputToUpdate);
InputPath inputPath;
try {
inputPath = flake::parseInputPath(inputToUpdate);
} catch (Error & e) {
warn("Invalid flake input '%s'. To update a specific flake, use 'nix flake update --flake %s' instead.", inputToUpdate, inputToUpdate);
throw e;
}
if (lockFlags.inputUpdates.contains(inputPath))
warn("Input '%s' was specified multiple times. You may have done this by accident.");
lockFlags.inputUpdates.insert(inputPath);
Expand Down

0 comments on commit af00298

Please sign in to comment.