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

infinite recursion when self assigned to option #185

Closed
DavHau opened this issue Sep 2, 2023 · 6 comments
Closed

infinite recursion when self assigned to option #185

DavHau opened this issue Sep 2, 2023 · 6 comments
Assignees

Comments

@DavHau
Copy link
Contributor

DavHau commented Sep 2, 2023

The following flake leads to an infinite recursion:

{
  outputs = inputs@{flake-parts, nixpkgs, self, ...}:
    flake-parts.lib.mkFlake {inherit inputs;} {
      nixosConfigurations.default = nixpkgs.lib.nixosSystem {
        modules = [
          {
            # assigning self to a non existent option triggers the infinite recursion
            foo.repoRoot = self;
          }
        ];
      };
    };
}

I think this issue is import to fix.
For example this could as well happen with the treefmt.repoRoot option. If it ever gets deprecated, users will be puzzled by a hard to debug issue.

In my case this lead to a stack overflow with no trace at all.

This does only happen when using flake-parts and not with vanilla flakes.

@roberth
Copy link
Member

roberth commented Sep 3, 2023

@DavHau which version and platform did that happen?

When I run it on x86_64-linux, I get infinite recursions instead, which do have a trace, although the quality of the trace varies between Nix versions. 2.13.3 seems best.
Good thing the latest two or three releases have test infrastructure to catch such regressions - wish we had it sooner.

Seems like a serious problem indeed. I think we should add sourceInfo directly to inputs in Nix to solve this without removing source locations for all the other errors when they occur in the anonymous "root" module that is the mkFlake {} argument.

This solution may also help with

@DavHau
Copy link
Contributor Author

DavHau commented Sep 3, 2023

In my case this lead to a stack overflow with no trace at all.

The example above results in an infinite recursion for me as well.
I got a stack overflow error in dream2nix, but after stripping it down to a minimal reproducer it became an infinite recursion.
Not sure if that change in behavior was due to complexity or due to library versions.

Let me know if I should publish the dream2nix expression that lead to a stack overflow.

@roberth
Copy link
Member

roberth commented Sep 3, 2023

Could you try with this?

PR description shows how to nix run that nix.

You might be able to tell what's the difference between your original problem and reproducer with it.

@roberth
Copy link
Member

roberth commented Sep 3, 2023

Blocked on NixOS/nix#8908

@roberth
Copy link
Member

roberth commented Oct 13, 2023

Does #192 help?

With it I get:

$ nix eval . --override-input flake-parts github:hercules-ci/flake-parts/refs/pull/192/head
warning: not writing modified lock file of flake 'path:/home/user/h/issue-flake-parts-185':
• Updated input 'flake-parts':
    'github:hercules-ci/flake-parts/7f53fdb7bdc5bb237da7fefef12d099e4fd611ca' (2023-09-01)
  → 'github:hercules-ci/flake-parts/0effb5db5ccc46f8787c98ca91ec64cc9721c121' (2023-10-13)
error: The option `nixosConfigurations' does not exist. Definition values:
       - In `<unknown-file>'
(use '--show-trace' to show detailed location information)

Still an error, as expected, but actionable.

Fixing it up a bit:

{
  outputs = inputs@{flake-parts, nixpkgs, self, ...}:
    flake-parts.lib.mkFlake {inherit inputs;} {
      systems = [ "x86_64-linux" ];
      flake.nixosConfigurations.default = nixpkgs.lib.nixosSystem {
        modules = [
          {
            # assigning self to a non existent option triggers the infinite recursion
            foo.repoRoot = self;
          }
        ];
      };
    };
}

I then get this, simulating nixos-rebuild a bit:

$ nix eval .#nixosConfigurations.default.config.system.build.toplevel.drvPath --override-input flake-parts github:hercules-ci/flake-parts/refs/pull/192/head
warning: not writing modified lock file of flake 'path:/home/user/h/issue-flake-parts-185':
• Updated input 'flake-parts':
    'github:hercules-ci/flake-parts/7f53fdb7bdc5bb237da7fefef12d099e4fd611ca' (2023-09-01)
  → 'github:hercules-ci/flake-parts/0effb5db5ccc46f8787c98ca91ec64cc9721c121' (2023-10-13)
error: Neither nixpkgs.hostPlatform nor the legacy option nixpkgs.system has been set.
       You can set nixpkgs.hostPlatform in hardware-configuration.nix by re-running
       a recent version of nixos-generate-config.
       The option nixpkgs.system is still fully supported for NixOS 22.05 interoperability,
       but will be deprecated in the future, so we recommend to set nixpkgs.hostPlatform.
(use '--show-trace' to show detailed location information)

@roberth
Copy link
Member

roberth commented Oct 29, 2023

Fixed in #192

@roberth roberth closed this as completed Oct 29, 2023
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

No branches or pull requests

2 participants