NixOS / nix

Nix, the purely functional package manager
https://nixos.org/
GNU Lesser General Public License v2.1
12.96k stars 1.54k forks source link

Cannot lock unlocked input #11181

Open DavHau opened 4 months ago

DavHau commented 4 months ago

Not sure if this intentional, but with recent nix versions (using 2.23.x), I cannot persist an input override anymore that points to a local unclean repo.

$ nix flake lock --override-input clan-core $HOME/projects/clan/clan-core
warning: will not write lock file of flake [...] because it has an unlocked input ('git+file:///[...]/clan/clan-core')

Since nix now defaults to use --no-write-lock-file in this case, it is not possible to persist the override. I found this capability useful, as it allows me to continue operating on the overridden flake, without having to pass --override-input every single time. This is specifically needed, when I operate on the flake via some other tools, which do not support passing extra options to nix.

Though I can see that doing this might be bad practice, as there is a risk of people publishing non-reproducible flakes if that is allowed. So, not sure if a feature or a bug.

Add :+1: to issues you find important.

roberth commented 4 months ago

We could store a diff in or around the lock file. Such functionality would also benefit https://github.com/NixOS/nix/issues/11160, because unmerged PR commits also have a habit of disappearing.

takeda commented 1 month ago

This is a huge regression for me. No longer I can't use --override-input I get the same error when also referencing a local directory in flake.nix.

Why was this change necessary? Is there a workaround for it?

First we had change that prevented using a relative path and now this. It makes it so much more problematic testing things before making a commit.

Edit: looks like even having a local commit is not enough I need to push my change to repo and reference it to be able to use it. There's no way this isn't a bug is it? How can I use a local repo now?

pwaller commented 1 month ago

Also having the problem here of none of several methods I tried which worked in older versions of nix yielding the ability to override the nixpkgs input of a flake to point to an on-disk work in progress of nixpkgs.

pwaller commented 1 month ago

~Workaround for now (newest working version of nix is nix_2_20):~

nix run nixpkgs#nixVersions.nix_2_20 -- flake lock --override-input nixpkgs git+file:///home/pwaller/.local/src/nixpkgs

(edit, no, sorry - this also doesn't work, yielding: error: lock file contains unlocked input, during the build).

I think what the warning message might be trying to say is that the flake input be a dirty input, but it doesn't say that. At least to me, 'locking' is a nix concept, and 'dirty' is a git concept, so when the message says 'unlocked input' it is not clear that the underlying reason is a dirty git repository.

takeda commented 1 month ago

I get it to work, but I had:

  1. commit the change
  2. make sure there are no uncommitted files when invoking git status

If this is not a bug and it was intended to work like that it is really bad idea. Frankly I wish the reverse was possible. I sometimes use nix to set up dev environment and was in places where they did not like when I committed nix files with the project, so it makes really hard to use Nix if the whole team doesn't buy it.

lboklin commented 1 month ago

I can't figure out how to fix the problem. I change the input url from a local repo to a remote repo, commit the change, and then run nix flake update and I still get the error. What exactly am I supposed to do in this situation?

lboklin commented 1 month ago

Furthermore, if I entirely remove the entry from the lock file and run nix flake lock, I get error: lock file references missing node '<input-flake>'. This must be a bug, surely?

RooSoft commented 2 days ago

Also got this error... do I understand that it's now impossible to refer to a local folder with uncommited changes?

I am developing a flake that contains microVM configurations. The local machine can then refer to it with its specific environment, allowing for production, staging, development, etc.... While in development, I got to somehow test those changes, but the flake itself is unuseable without a host. So, I tend to refer to it from a development host to make sure it makes sense before committing new code.

Now, it seems that whenever I create a new microVM configuration, I got to commit untested stuff before I can even try it at all.

Is there a workaround for that specific case?

bendlas commented 11 hours ago

I am also in dire need for a solution for this. I don't want to create a commit every time I'm trying out a change in a flake I'm referring to ..

nixos-discourse commented 11 hours ago

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/refer-to-a-flake-in-a-local-folder/57000/2