`nix flake update` to system revision

Hello, trying out flakes and I was wondering if there’s a way to run something like nix flake update but use the nixpkgs revision that is currently being used by the system. The system is now also using a flake build (nixos-rebuild switch --flake 'path:...').

To try to avoid an XY problem, what I’d like to do is update a flake that has multiple inputs, including nixpkgs.url = "github:NixOS/nixpkgs";. I want all of them to update to the latest version except nixpkgs which I’d like to use the version that NixOS is using. My reason is that I likely already have the packages in my store for that version and I can avoid having to download quite as many copies.

I do have nix.registry.nixpkgs.flake = inputs.nixpkgs; in my host config, so I think I might be able to use flake:nixpkgs instead of the github link. This doesn’t quite seem like the right solution though.

I’ve seen --override-input used, but the manual says that will not update the lock file. I want to update the lock file, just with the rev of my system.

Can anyone recommend a good solution (or tell me why what I’m asking doesn’t make sense)?

Thanks!

To try to avoid an XY problem, what I’d like to do is update a flake that has multiple inputs, including nixpkgs.url = "github:NixOS/nixpkgs"; . I want all of them to update to the latest version except nixpkgs which I’d like to use the version that NixOS is using. My reason is that I likely already have the packages in my store for that version and I can avoid having to download quite as many copies.

Assuming that you absolutely do not want to use the registry when defining your inputs:

$ nix flake update --override-input nixpkgs "github:nixos/nixpkgs/$(nixos-version --revision)"

Though, using the registry really is much simpler, and so:

You can either specify the input explicitly with nixpkgs.url = "nixpkgs"; as seen here: https://github.com/NixOS/templates/blob/3eff6e7c77f697652aa9ea0c564be3481e377ded/full/flake.nix#L16-L17

Or, specifically in the case of nixpkgs, just use the default which happens to be to get it from the registry. An example of this can be seen in the trivial template. To test if this works for you, simply do:

$ nix flake init
$ nix flake update
$ cat flake.lock

And see if the lock-file matches what you want.

3 Likes

I use flake:nixpkgs with a registry linking to my system input :slight_smile:

Doing this in general is probably frowned upon a little, since the entire point of flakes is pinning consistently, and avoiding host state to leak in. I think this is fine in some contexts though, because flake.lock still guarantees revisions, and sometimes there simply are good use cases for using what’s already on the system, rather than downloading dozens of independent copies of nixpkgs (especially if you use devShells a lot).

Depending on how the pinning is done, this might result in a flake.lock which refers to the copy of nixpkgs in the store as a local path dependency.

1 Like

The --override-input line seems to work, but then I don’t get why the manual page says This implies --no-write-lock-file, because it did write to the lock file, both to update it and to create it if I try deleting it.

On the registry version, if I do that I see this in the lock file:

"path": "/nix/store/n04lw5nrskzmz7rv17p09qrnjanfkg5d-source",

Is that okay? The intro I read said using flakes improves reproducibility, but can someone else build the same thing with a path in the lock file?

Or is there some step I’m missing that should be done to create a flake.lock that’s made for being pushed to a public repo rather than used locally?

No it is not. As you do not know anymore how to create that store path in the future.

You might want to use the approach as described in My painpoints with flakes - #14 by hmenke for pinning to circumvent the problem.

3 Likes

Sorry to bump this old thread, but the approach described in My painpoints with flakes - #14 by hmenke requires me to use

{
  descripttion = "a dev flake with nixpkgs pinned to system";
  inputs.nixpkgs.url = "nixpkgs";
  outputs =  {};
}

but I prefer inputs.nixpkgs.url = "github:nixos/nixpkgs/<branch>"; as per your follow up comment.

Is there no way initialize flake.lock so it points to the same commit as the system is using and still use the gtihub:nixos/nixpkgs/ syntax?