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

nixos/nix-daemon: fix registry flake type #131814

Conversation

blaggacao
Copy link
Contributor

@blaggacao blaggacao commented Jul 28, 2021

Before this commit, the flake option was typed with types.unspecified.

This type get's merged via mergeDefaultOption, which has a line

else if all isFunction list then x: mergeDefaultOption loc (map (f: f x) list)

lib.isFunction detects an attrs in the shape of {__functor = ...} as
a function and hence this line substitutes such attrs with a function
(f: f x).

If now, a flake input has a __functor as it's output, this will
coerce the once attrs to a function. This breaks a lot of things later
in the stack, for example a later lib.filterAttrs seive <LAMBDA> will
fail for obious reasons.

According to @infinisil, types.unspecified is due to deprecation. In
the meantime this PR provides a specific fix for the specific problem
discovered.

EDIT: this needs quite some back-porting, please someone can add the respective labels?

@github-actions github-actions bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels Jul 28, 2021
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 labels Jul 28, 2021
@@ -458,7 +458,7 @@ in
description = "The flake reference to which <option>from></option> is to be rewritten.";
};
flake = mkOption {
type = types.unspecified;
type = types.attrs;
Copy link
Member

Choose a reason for hiding this comment

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

Type does not match the default or the example. What's going on with all three?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, oversight fixed in force-push. The literalExample is actually correct and refers to a hypothetical nixpkgs input, which is a flake, hence an attrs.

Before this commit, the `flake` option was typed with `types.unspecified`.

This type get's merged via [`mergeDefaultOption`](https://github.com/NixOS/nixpkgs/blob/ebb592a04c5282f316d60cd4aba066f6e5d74b65/lib/options.nix#L119-L128), which has a line
```nix
else if all isFunction list then x: mergeDefaultOption loc (map (f: f x) list)
```

`lib.isFunction` detects an attrs in the shape of `{__functor = ...}` as
a function and hence this line substitutes such attrs with a function
(f: f x).

If now, a flake input has a `__functor` as it's output, this will
coerce the once attrs to a function. This breaks a lot of things later
in the stack, for example a later `lib.filterAttrs seive <LAMBDA>` will
fail for obious reasons.

According to @infinisil, `types.unspecified` is due to deprecation. In
the meantime this PR provides a specific fix for the specific problem
discovered.
@blaggacao blaggacao force-pushed the fix-nix-daemon-registry-type-unspecified-error branch from 73e3095 to ecae25c Compare August 1, 2021 19:56
Copy link
Member

@roberth roberth left a comment

Choose a reason for hiding this comment

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

The change looks good. I've written a review for the original PR which wasn't reviewed... which I kind of understand, but alas.

@roberth roberth merged commit 151c2f5 into NixOS:master Aug 1, 2021
@blaggacao
Copy link
Contributor Author

@roberth I'd say this warrants backporting, does it?

@github-actions
Copy link
Contributor

github-actions bot commented Aug 1, 2021

Successfully created backport PR #132363 for release-21.05.

Pacman99 pushed a commit to divnix/digga that referenced this pull request Feb 23, 2022
There was never an intention to setup the registry with aliases, which
would not avoid a network call ayhow if an input is not specified as an
registry-resolvable input.

At the same time, this clarification also eliniates an error that is
addressed upstream via NixOS/nixpkgs#131814

---

work-around: for spurious reasons w.r.t. functor attrs in module system

Without any obvious reason, the module system appears to substitute
attrs that contain a `__functor` with the value of that functor.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants