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

follows behavior for flakes used as inputs #3602

Open
mkenigs opened this issue May 20, 2020 · 13 comments
Open

follows behavior for flakes used as inputs #3602

mkenigs opened this issue May 20, 2020 · 13 comments

Comments

@mkenigs
Copy link
Contributor

mkenigs commented May 20, 2020

Follows seems to break when a flake that has follows is used as an input for another flake. For example for a circular dependency flakeB<->flakeC, if flakeA inputs flakeB it causes a circular import error. If A->B->C and A->D->C2 but B follows D/C, the follows works, but if another flake inputs A, B no longer follows D/C.

The RFC says follows should be a path from the root flake, but it looks like sometimes the path is actually treated as relative

/* Otherwise, it's relative to the current flake. */

Not sure what the intended behavior is, but it seems kind of brittle to require a flake to know the path it is being input along, and it might be better to always treat a follows as relative to the flake where it is defined.

@stale
Copy link

stale bot commented Feb 13, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the stale label Feb 13, 2021
@mkenigs
Copy link
Contributor Author

mkenigs commented Feb 13, 2021

The implementation of follows and overrides are related, so I think changing follows behavior depends on #4004

@tejing1
Copy link

tejing1 commented Jun 5, 2021

I also just encountered this bug. I have, in the inputs section of my main nixos config flake:

inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-21.05";
inputs.home-manager.url = "github:nix-community/home-manager/release-21.05";
inputs.home-manager.inputs.nixpkgs.follows = "nixpkgs";

then I made (programatically as part of my nixos system generation) a small flake which I registered as 'pkgs' with nothing but the following flake.nix: (the nix store path points to the current rev of my main nixos config flake)

{
  inputs.config.url = "path:/nix/store/174i3c4d8v3zx7j2hijsmjfln05c50xf-source";
  outputs = { self, config }: {
    legacyPackages."x86_64-linux" = config.nixosConfigurations."tejingdesk".pkgs;
  };
}

the idea was to allow commands like nix shell pkgs#foo to access overlays and other nixpkgs configuration specified in my system config, but instead I get this:

error: input 'config/home-manager/nixpkgs' follows a non-existent input 'nixpkgs'

It seems that "follows" attributes are being interpreted from the pkgs flake, rather than the flake they are written in, which in essence means they can't be used in any flake that might be an input to another flake.

I would expect that the follows line I have written would have the same effect as putting

inputs.config.inputs.home-manager.inputs.nixpkgs.follows = "config/nixpkgs";

in the pkgs flake, but instead it seems to be equivalent to putting

inputs.config.inputs.home-manager.inputs.nixpkgs.follows = "nixpkgs";

there.

@tejing1
Copy link

tejing1 commented Jun 5, 2021

PR #4641 seems to fix this issue?

@rocky-fuchsian-frog
Copy link

I just wanted to add in a similar issue I'm having in the hopes that maybe someone can help me. So I have a flake:

{
  description = "The www development shell";
  inputs.flake-utils.url = "github:numtide/flake-utils";
  inputs.nixpkgs-fmt.url = "github:nix-community/nixpkgs-fmt";
  outputs = { self, nixpkgs, flake-utils, nixpkgs-fmt }:
    flake-utils.lib.eachDefaultSystem
      (system:
        let pkgs = nixpkgs.legacyPackages.${system}; in
        {
          devShell = pkgs.mkShell {
            buildInputs = [
              nixpkgs-fmt
            ];
          };
        }
      );
}

which fails on nix develop with:

error: input 'nixpkgs-fmt/fenix/naersk' follows a non-existent input 'naersk'

@nixos-discourse
Copy link

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

https://discourse.nixos.org/t/possible-nix-flake-hierarchical-lookup-bug/14057/2

teto pushed a commit to teto/haskell-language-server that referenced this issue Sep 17, 2021
The feature is especially broken in nix:
    nixFlake suffers from an issue when using "follows" keyword:
    NixOS/nix#3602

    A solution here https://discourse.nixos.org/t/flake-how-make-nixpkgs-self-follow-another-inputs-nixpkgs/10867
    presents how to set self.inputs from children flakes so that's what we
    end up doing
teto pushed a commit to teto/haskell-language-server that referenced this issue Sep 20, 2021
nixFlake suffers from a bug when using "follows" keyword:
NixOS/nix#3602
teto pushed a commit to teto/haskell-language-server that referenced this issue Sep 20, 2021
nixFlake suffers from a bug when using "follows" keyword:
NixOS/nix#3602
mergify bot pushed a commit to haskell/haskell-language-server that referenced this issue Sep 23, 2021
nixFlake suffers from a bug when using "follows" keyword:
NixOS/nix#3602
contrun added a commit to contrun/infra that referenced this issue Feb 11, 2022
@mikepurvis
Copy link

mikepurvis commented Apr 13, 2022

I recently adopted follows in my hierarchical flake setup and hit this as well (with Nix 2.6.1). I have:

A -> B -> C -> D -> nixpkgs

C also has nixpkgs as an input, and has a follows declaration so that D should use C's nixpkgs. All this works fine when B is used directly, but once A uses B as an input, I get eg:

error: input 'B/C/D/nixpkgs' follows a non-existent input 'C/nixpkgs'

When going "up a level", it should have been looking for B/C/nixpkgs rather than C/nixpkgs.

EDIT: I can confirm that this issue still exists in Nix 2.8.0pre20220413_0e58aff.

@shadowrylander
Copy link

Also happening on the latest master:

nix (Nix) 2.10.0pre20220706_f6316b4

@mikepurvis
Copy link

From my trivial reproduction, this appears to now be fixed in nix (Nix) 2.12.0pre20221005_ac0fb38, likely due to #6983

Thanks @edolstra!

@cfhammill
Copy link

I'm still seeing this issue on nix (Nix) 2.12.0

@shroomist
Copy link

,I'm in the same boat, observing this behavior on nix (Nix) 2.12.0

@nixos-discourse
Copy link

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

https://discourse.nixos.org/t/nix-flake-to-aggregate-and-concurrently-update-some-dependencies/10774/10

@sellout
Copy link
Contributor

sellout commented Nov 29, 2024

I had an issue like this, not sure if exactly the same case, but it was solved for me some time between Nix 2.13.5 and 2.18.4.

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

No branches or pull requests

10 participants