Skip to content

flakes: throw an error if follows-declaration for an input is invalid #6663

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

Merged
merged 3 commits into from
Jul 12, 2022

Conversation

Ma27
Copy link
Member

@Ma27 Ma27 commented Jun 13, 2022

I recently got fairly confused why the following expression didn't have
any effect

{
  description = "Foobar";
  inputs.sops-nix = {
    url = github:mic92/sops-nix;
    inputs.nixpkgs_22_05.follows = "nixpkgs";
  };
}

until I found out that the input was called nixpkgs-22_05 (please note
the dash vs. underscore).

IMHO it's not a good idea to not throw an error in that case and
probably leave end-users rather confused, so I implemented a small check
for that which basically checks whether follows-declaration from
overrides actually have corresponding inputs in the transitive flake.

In fact this was done by accident already in our own test-suite where
the removal of a follows was apparently forgotten[1].

Since the key of the std::map that holds the overrides is a vector
and we have to find the last element of each vector (i.e. the override)
this has to be done with a for loop in O(n) complexity with n being
the total amount of overrides (which shouldn't be that large though).

Please note that this doesn't work with nested expressions, i.e.

inputs.fenix.inputs.nixpkgs.follows = "...";

which is a known problem[2].

For the expression demonstrated above, an error like this will be
thrown:

error: sops-nix has a `follows'-declaration for a non-existant input nixpkgs_22_05!

[1] 2664a21
[2] #5790

cc @edolstra @thufschmitt @Ericson2314

@Ma27
Copy link
Member Author

Ma27 commented Jul 10, 2022

ping @edolstra @thufschmitt would you mind taking a look? :)

Copy link
Member

@thufschmitt thufschmitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks :)

A few comments, but looks good overall

Ma27 added 3 commits July 12, 2022 10:18
I recently got fairly confused why the following expression didn't have
any effect

    {
      description = "Foobar";
      inputs.sops-nix = {
        url = github:mic92/sops-nix;
        inputs.nixpkgs_22_05.follows = "nixpkgs";
      };
    }

until I found out that the input was called `nixpkgs-22_05` (please note
the dash vs. underscore).

IMHO it's not a good idea to not throw an error in that case and
probably leave end-users rather confused, so I implemented a small check
for that which basically checks whether `follows`-declaration from
overrides actually have corresponding inputs in the transitive flake.

In fact this was done by accident already in our own test-suite where
the removal of a `follows` was apparently forgotten[1].

Since the key of the `std::map` that holds the `overrides` is a vector
and we have to find the last element of each vector (i.e. the override)
this has to be done with a for loop in O(n) complexity with `n` being
the total amount of overrides (which shouldn't be that large though).

Please note that this doesn't work with nested expressions, i.e.

    inputs.fenix.inputs.nixpkgs.follows = "...";

which is a known problem[2].

For the expression demonstrated above, an error like this will be
thrown:

    error: sops-nix has a `follows'-declaration for a non-existant input nixpkgs_22_05!

[1] 2664a21
[2] NixOS#5790
@Ma27 Ma27 force-pushed the follows-invalid-input branch from 2003172 to 1f77106 Compare July 12, 2022 09:30
@Ma27 Ma27 requested a review from thufschmitt July 12, 2022 09:31
@thufschmitt thufschmitt merged commit 2dbd5ed into NixOS:master Jul 12, 2022
@Ma27 Ma27 deleted the follows-invalid-input branch July 12, 2022 14:49
lf- pushed a commit to lix-project/lix that referenced this pull request May 5, 2024
… works recursively

When I added the warning that an input X has an override for a
non-existent input, the recursive flake input override fix wasn't
implemented yet[1].

This patch tests that both work together.

[1] NixOS/nix#6663

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

Successfully merging this pull request may close these issues.

3 participants