How to update a single flake input?

Is there a flake equivalent to niv update <name-of-single-source>?

Running nix flake update --help suggests no to me and I can’t find anything in online searches either.

I guess I can run nix flake update to update all flakes then revert lockfile changes for inputs I want to keep the same, but I was wondering if a better way exists.

5 Likes

You can update individual inputs using nix flake lock, an example from its help:

   • Update the nixpkgs and nix inputs of the flake in the current directory:

   # nix flake lock --update-input nixpkgs --update-input nix
   * Updated 'nix': 'github:NixOS/nix/9fab14adbc3810d5cc1f88672fde1eee4358405c' -> 'github:NixOS/nix/8927cba62f5afb33b01016d5c4f7f8b7d0adde3c'
   * Updated 'nixpkgs': 'github:NixOS/nixpkgs/3d2d8f281a27d466fa54b469b5993f7dde198375' -> 'github:NixOS/nixpkgs/a3a3dda3bacf61e8a39258a0ed9c924eeca8e293'
23 Likes

That’s it, thank you!

This is… this is just not good.

nix flake update --single <name> or something is just considerably, considerably more intuitive.

14 Likes

I believe it’s now nix flake lock --update-input <input>

2 Likes

Yeah, but why?

Why do we have nix flake update and nix flake lock that both specifically work to update the lock file?

Choosing to consolidate around

  • nix flake lock --update-all
  • nix flake lock --update-input <foo>

or

  • nix flake update --input <name>
  • nix flake update --all

would remove yet another mental hurdle of using nix cli v2.

Is there a reasoning for the split I’m missing?

I opened `nix flake update --single <name>` is more intuitive than `nix flake lock --update` · Issue #5110 · NixOS/nix · GitHub rushedly last night.

21 Likes

For me the command nix flake lock --update-input purebred does not only updated this one input as I would have expected but also some more inputs:

warning: updating lock file '/home/luc/src/sys/flake.lock':
• Updated input 'nvimpager/neovim/neovim-flake/nixpkgs':
    'github:nixos/nixpkgs/ac169ec6371f0d835542db654a65e0f2feb07838' (2021-12-26)
  → follows 'nvimpager/neovim/nixpkgs'
• Updated input 'nvimpager/neovim/nixpkgs':
    follows 'nvimpager/nixpkgs'
  → 'github:nixos/nixpkgs/efeefb2af1469a5d1f0ae7ca8f0dfd9bb87d5cfb' (2022-01-30)
• Updated input 'purebred':
    'github:purebred-mua/purebred/2d40be29aaec2a74aa61e539d8eaf1272c413ba2' (2021-09-25)
  → 'github:purebred-mua/purebred/5477e316c2dd2bf9b667c26f73a8d32dba59341d' (2021-12-22)
• Updated input 'purebred/nixpkgs':
    'github:nixos/nixpkgs/b2737d4980a17cc2b7d600d7d0b32fd7333aca88' (2022-01-11)
  → 'github:nixos/nixpkgs/34ad3ffe08adfca17fcb4e4a47bb5f3b113687be' (2021-10-21)
warning: Git tree '/home/luc/src/sys' is dirty

As you can see my purebred input and its inputs are updated. So far that is what I expected. But then some inputs of my nvimpager input also gets updated and I don’t want that.

If I also specify --no-update-lock-file it obviously fails with

error: flake 'git+file:///home/luc/src/sys' requires lock file changes but they're not allowed due to '--no-update-lock-file'

For reference my flake is here:

Do you know if this is to be expected our how I can update only one of my inputs (and maybe its inputs with it)?

2 Likes

While I don’t know for sure, I imagine the problem is the follows. Since you’re asking purebred to use the same inputs as your other inputs, those must in turn also be updated if you update purebred.

I’m a bit confused though, the flake on your repo doesn’t have an input named nvimpager, so it’s hard to tell what’s going on.

Sorry I had not pushed the correct code and my local git history is in a mess because I tried to rewrite some stuff.

I have now pushed a tests branch and the commit 8599d4ac3c9937e3f38b674b0b58801883e6ab15 shows the behaviour I describe above (some hashes differ by now but nvimpager stuff is updated even though I only request to update purebread).

Maybe the following is related: If I am on the mentioned commit 8599d4ac3c9937e3f38b674b0b58801883e6ab15 and execute nix flake metadata it also tries to modify my lock file:

• Updated input 'nvimpager/neovim/neovim-flake/nixpkgs':
    'github:nixos/nixpkgs/ac169ec6371f0d835542db654a65e0f2feb07838' (2021-12-26)
  → follows 'nvimpager/neovim/nixpkgs'
• Updated input 'nvimpager/neovim/nixpkgs':
    follows 'nvimpager/nixpkgs'
  → 'github:nixos/nixpkgs/554d2d8aa25b6e583575459c297ec23750adb6cb' (2022-02-02)
• Updated input 'purebred/nixpkgs':
    follows 'nixpkgs'
  → 'github:nixos/nixpkgs/554d2d8aa25b6e583575459c297ec23750adb6cb' (2022-02-02)

That was very astonishing to me because I assumed nix flake metadata to be purely inquiring.

It might be that the commit 364a3fd299e91b4b72d0b6e852f6ca7bd5154e8f is at fault where I removed inputs.purebred.inputs.nixpkgs.follows = "nixpkgs"; from my flake.nix but did not update the lock file accordingly.