From 9f11b1b0c4724ad81f91f14756b475e0de64379f Mon Sep 17 00:00:00 2001 From: Olmo Kramer Date: Sat, 24 Feb 2024 20:58:44 +0100 Subject: [PATCH 1/2] Accept multiple inputs in `nix flake update` --- src/nix/flake.cc | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/nix/flake.cc b/src/nix/flake.cc index 131589f35..de23a122d 100644 --- a/src/nix/flake.cc +++ b/src/nix/flake.cc @@ -88,17 +88,19 @@ public: expectArgs({ .label="inputs", .optional=true, - .handler={[&](std::string 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; + .handler={[&](std::vector inputsToUpdate){ + for (auto inputToUpdate : inputsToUpdate) { + 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); } - if (lockFlags.inputUpdates.contains(inputPath)) - warn("Input '%s' was specified multiple times. You may have done this by accident."); - lockFlags.inputUpdates.insert(inputPath); }}, .completer = {[&](AddCompletions & completions, size_t, std::string_view prefix) { completeFlakeInputPath(completions, getEvalState(), getFlakeRefsForCompletion(), prefix); From b1ad729add0714cd123ea96497adf0ef14f683c4 Mon Sep 17 00:00:00 2001 From: Olmo Kramer Date: Sun, 3 Mar 2024 13:51:40 +0100 Subject: [PATCH 2/2] Add test for `nix flake update` with multiple inputs --- tests/functional/flakes/flakes.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/functional/flakes/flakes.sh b/tests/functional/flakes/flakes.sh index 7506b6b3b..427290883 100644 --- a/tests/functional/flakes/flakes.sh +++ b/tests/functional/flakes/flakes.sh @@ -564,6 +564,16 @@ nix flake lock "$flake3Dir" nix flake update flake2/flake1 --flake "$flake3Dir" [[ $(jq -r .nodes.flake1_2.locked.rev "$flake3Dir/flake.lock") =~ $hash2 ]] +# Test updating multiple inputs. +nix flake lock "$flake3Dir" --override-input flake1 flake1/master/$hash1 +nix flake lock "$flake3Dir" --override-input flake2/flake1 flake1/master/$hash1 +[[ $(jq -r .nodes.flake1.locked.rev "$flake3Dir/flake.lock") =~ $hash1 ]] +[[ $(jq -r .nodes.flake1_2.locked.rev "$flake3Dir/flake.lock") =~ $hash1 ]] + +nix flake update flake1 flake2/flake1 --flake "$flake3Dir" +[[ $(jq -r .nodes.flake1.locked.rev "$flake3Dir/flake.lock") =~ $hash2 ]] +[[ $(jq -r .nodes.flake1_2.locked.rev "$flake3Dir/flake.lock") =~ $hash2 ]] + # Test 'nix flake metadata --json'. nix flake metadata "$flake3Dir" --json | jq .