Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nix flake update and nix flake lock disagree on how to handle nested follows #5728

Closed
max-privatevoid opened this issue Dec 4, 2021 · 5 comments · Fixed by #5839
Closed
Labels

Comments

@max-privatevoid
Copy link
Contributor

Describe the bug
The following flake setup

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    flake2.url = "...";
    flake2.inputs.nixpkgs.follows = "nixpkgs";
  };
  outputs = _: {};
}
{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    flake3.url = "...";
    flake3.inputs.nixpkgs.follows = "nixpkgs";
  };
  outputs = _: {};
}
{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
  };
  outputs = _: {};
}

Results in the following input tree when running nix flake update on flake1, which is also the behavior shown by Nix 2.4 for either command.

Inputs:
├───flake2: ...
│   ├───flake3: ...
│   │   └───nixpkgs follows input 'flake2/nixpkgs'
│   └───nixpkgs follows input 'nixpkgs'
└───nixpkgs: github:NixOS/nixpkgs/...

When running nix flake lock (or any other operation that triggers a lock check) on the same flake, the input tree is changed:

Inputs:
├───flake2: ...
│   ├───flake3: ...
│   │   └───nixpkgs github:NixOS/nixpkgs/...
│   └───nixpkgs follows input 'nixpkgs'
└───nixpkgs: github:NixOS/nixpkgs/...

Steps To Reproduce

  1. Create the 3 flakes from above and link them together
  2. Run nix flake update on flake3, then flake2, then flake1 for the initial lockfile
  3. Run the commands below in flake1 and observe the lockfile unexpectedly changing
$ nix run github:nixos/nixpkgs/nixos-21.11#nix_2_4 flake update
  # Inputs are up-to-date -> does nothing

$ nix run github:nixos/nixpkgs/nixos-21.11#nix_2_4 flake lock
  # Lockfile is consistent -> does nothing

$ nix run github:nixos/nix/07bffe799853ef5e2757b9892e4e3dac89bfccbb flake update
  # Does nothing

$ nix run github:nixos/nix/07bffe799853ef5e2757b9892e4e3dac89bfccbb flake lock
warning: updating lock file '.../flake.lock':
• Updated input 'flake2/flake3/nixpkgs/nixpkgs':
    follows 'flake2/nixpkgs'
  → 'github:nixos/nixpkgs/6daa4a5c045d40e6eae60a3b6e427e8700f1c07f' (2021-12-01)

$ nix run github:nixos/nix/07bffe799853ef5e2757b9892e4e3dac89bfccbb flake update
warning: updating lock file '.../flake.lock':
• Updated input 'flake2/flake3/nixpkgs':
    'github:nixos/nixpkgs/6daa4a5c045d40e6eae60a3b6e427e8700f1c07f' (2021-12-01)
  → follows 'flake2/nixpkgs'

Bisect points to commit 07bffe7

Expected behavior

nix flake update and nix flake lock ran back-to-back should result in no lockfile modification.

nix-env --version output

nix (Nix) 2.5pre20211111_07bffe7
@thufschmitt
Copy link
Member

I can indeed reproduce that. Self-contained repro script (to run from a scratch dir with the right Nix version).

cc @balsoft any idea what might have gone wrong in 07bffe7 ?

@balsoft
Copy link
Member

balsoft commented Dec 10, 2021

I feel like I misunderstood that part of the code that I was changing, despite my best efforts. I don't understand why it broke so many seemingly unrelated things :(

@nifoc
Copy link

nifoc commented Dec 21, 2021

Just ran into this issue after updating nix to 2.5.1 (coming from 2.4).

In my particular case, it's caused by nix flake update followed by nix flake build. But I was also able to reproduce it with update followed by a simple info.

@balsoft
Copy link
Member

balsoft commented Dec 28, 2021

Now that I look at it, I'm not sure how this is different from https://github.com/NixOS/nix/blob/master/tests/flakes.sh#L779

@balsoft
Copy link
Member

balsoft commented Dec 28, 2021

Ok, I got it.

See #5839

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants