Nix flake lock --update-input nixpkgs vs nix build --update-input nixpkgs

In the new nix cli documentation it says:

 nix flake lock --update-input nixpkgs
 nix build

is equivalent to:

 nix build --update-input nixpkgs

is this really the case? I just tried it right now and it seems not to be the case. Only nix flake lock --update-input nixpkgs updates the flake lock in my flake

That sounds like a bug to me, unless you used the commands right after one another on the same input, so there were no changes to update to?

For me both behave the same:

$ nix build .\#home/config/nmelzer@enceladeus --update-input home-manager
warning: updating lock file '/home/nmelzer/Projects/nixos-config/flake.lock':
• Updated input 'home-manager':
    'github:nix-community/home-manager/17198cf5ae27af5b647c7dac58d935a7d0dbd189' (2023-04-14)
  → 'github:nix-community/home-manager/53bd74f786934997e7f6a5ed9741b226e511e508' (2023-04-17)
warning: Git tree '/home/nmelzer/Projects/nixos-config' is dirty^C
error (ignored): error: interrupted by the user
error: interrupted by the user
$ git restore flake.lock
$ nix flake lock --update-input home-manager
warning: updating lock file '/home/nmelzer/Projects/nixos-config/flake.lock':
• Updated input 'home-manager':
    'github:nix-community/home-manager/17198cf5ae27af5b647c7dac58d935a7d0dbd189' (2023-04-14)
  → 'github:nix-community/home-manager/53bd74f786934997e7f6a5ed9741b226e511e508' (2023-04-17)
warning: Git tree '/home/nmelzer/Projects/nixos-config' is dirty
$
1 Like

If i run nix build --update-input nixpkgs first it doesn’t fetch the newest nixpkgs from my branch.
When i do it like you it works for me too. (it finds the already downloaded nixpgks revision)

I am using nix 2.11.1 on NixOS 22.11
if you can confirm the issue I think it makes sense to open a bug ticked

I do not understand what works or not works for you.

For me --update-input looks up the input and updates it to the latest version and will also write out a slightly altered lock file.

This does not depend on the subcommand I use, nor some order of operations.

And I use --update-input, --inputs-from, and --override-input a lot to create a variety of different results for the same flake in a temporal manor.

for me nix build --update-input nixpkgs doesn’t work to fetch the latest revision of my nixpgks branch.
It only finds it if i run nix flake lock --update-input nixpkgs before.
(and reset the lock file as you did)
to reproduce it you need to be sure that in your nix store you don’t have the updated-input.

I tried it today again and it did not fail to fetch the latest changes in the repository. To me it still seems to be unstable but have no idea how to test further.