lix/src/libexpr/flake
Maximilian Bosch c1c37f3200
flakes: throw an error if follows-declaration for an input is invalid
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] 2664a216e5
[2] https://github.com/NixOS/nix/issues/5790
2022-07-12 10:18:38 +02:00
..
call-flake.nix Represent 'follows' inputs explicitly in the lock file 2020-06-11 14:40:21 +02:00
config.cc Allow setting bash-prompt-prefix nix develop configuration 2022-05-10 16:53:22 -04:00
flake.cc flakes: throw an error if follows-declaration for an input is invalid 2022-07-12 10:18:38 +02:00
flake.hh If we can't write a lock file, pretend the top-level flake is dirty 2021-09-15 18:31:42 +02:00
flakeref.cc Get rid of most .at calls (#6393) 2022-05-04 07:44:32 +02:00
flakeref.hh Allow selecting derivation outputs using 'installable!outputs' 2022-05-03 13:43:52 +02:00
lockfile.cc libfetchers: Rename immutable -> locked 2022-02-24 18:09:00 +01:00
lockfile.hh Capitalize JSON for consistency 2020-10-28 17:54:28 -05:00