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

[BUG] home-manager nixvim type getSubOptions errors with attribute 'pkgs' missing #2378

Closed
1 task done
stasjok opened this issue Oct 6, 2024 · 2 comments · Fixed by #2406
Closed
1 task done

[BUG] home-manager nixvim type getSubOptions errors with attribute 'pkgs' missing #2378

stasjok opened this issue Oct 6, 2024 · 2 comments · Fixed by #2406
Labels
bug Something isn't working

Comments

@stasjok
Copy link
Contributor

stasjok commented Oct 6, 2024

Field Description
Plugin d42c804ad515f45f8addaf5a4bb0b8ce405ea140
Nixpkgs bc947f541ae55e999ffdb4013441347d83b00fe
Home Manager 509dbf8d45606b618e9ec3bbe4e936b7c5bc6c1e
  • I have read the FAQ and my bug is not listed there.

Description

This is some low-level stuff, but I need it for nixd language server setup. It was working before 4b7a412. In order to provide nixvim options to nixd I need to get top-level nixvim options. To get my options with my custom modules I'm using homeConfigurations.stas.options.programs.nixvim.type.getSubOptions [] for this. But it stopped working and I don't know a workaround yet. Full trace of the error:

error:
       … from call site

         at «string»:1:2:

            1| ((builtins.getFlake path:/home/stas/repro_nixvim_pkgs).homeConfigurations.stas.options.programs.nixvim.t
ype.getSubOptions []).enable
             |  ^

       … while calling 'getSubOptions'

         at /nix/store/sdzpqjwx7pdx6lsq6llyfqqf7hspp83c-source/lib/types.nix:887:25:

          886|         emptyValue = { value = {}; };
          887|         getSubOptions = prefix: (base.extendModules
             |                         ^
          888|           { inherit prefix; }).options // optionalAttrs (freeformType != null) {

       … while calling anonymous lambda

         at /nix/store/sdzpqjwx7pdx6lsq6llyfqqf7hspp83c-source/lib/attrsets.nix:1096:10:

         1095|     attrs:
         1096|     map (name: f name attrs.${name}) (attrNames attrs);
             |          ^
         1097|

       … from call site

         at /nix/store/sdzpqjwx7pdx6lsq6llyfqqf7hspp83c-source/lib/attrsets.nix:1096:16:

         1095|     attrs:
         1096|     map (name: f name attrs.${name}) (attrNames attrs);
             |                ^
         1097|

       … while calling anonymous lambda

         at /nix/store/sdzpqjwx7pdx6lsq6llyfqqf7hspp83c-source/lib/modules.nix:702:46:

          701|         else
          702|           concatLists (mapAttrsToList (name: defs:
             |                                              ^
          703|             map (def: def // {

       … while calling anonymous lambda

         at /nix/store/sdzpqjwx7pdx6lsq6llyfqqf7hspp83c-source/lib/modules.nix:688:22:

          687|         # Propagate all unmatched definitions from nested option sets
          688|         mapAttrs (n: v: v.unmatchedDefns) resultsByName
             |                      ^
          689|         # Plus the definitions for the current prefix that don't have a matching option

       … while calling anonymous lambda

         at /nix/store/sdzpqjwx7pdx6lsq6llyfqqf7hspp83c-source/lib/modules.nix:636:39:

          635|
          636|       resultsByName = mapAttrs (name: decls:
             |                                       ^
          637|         # We're descending into attribute ‘name’.

       … while calling anonymous lambda

         at /nix/store/sdzpqjwx7pdx6lsq6llyfqqf7hspp83c-source/lib/modules.nix:643:14:

          642|           optionDecls = filter
          643|             (m: m.options?_type
             |              ^
          644|                 && (m.options._type == "option"

       … while calling 'go'

         at /nix/store/16dmwpwbbhc19xpcbazx64vl9smpn2lg-source/modules/top-level/readonly-renames.nix:24:21:

           23|       go =
           24|         path: name: opt:
             |                     ^
           25|         let

       … from call site

         at /nix/store/16dmwpwbbhc19xpcbazx64vl9smpn2lg-source/modules/top-level/readonly-renames.nix:28:34:

           27|         in
           28|         if lib.isOption opt then mkAlias loc opt else lib.mapAttrs (go loc) opt;
             |                                  ^
           29|     in

       … while calling 'mkAlias'

         at /nix/store/16dmwpwbbhc19xpcbazx64vl9smpn2lg-source/modules/top-level/readonly-renames.nix:9:15:

            8|       mkAlias =
            9|         from: toOpt:
             |               ^
           10|         assert lib.assertMsg toOpt.readOnly

       … from call site

         at /nix/store/16dmwpwbbhc19xpcbazx64vl9smpn2lg-source/modules/top-level/readonly-renames.nix:12:16:

           11|           "toReadOnlyRenameOptions used on non-readOnly option `${lib.showOption toOpt.loc}'.";
           12|         assert lib.assertMsg toOpt.isDefined
             |                ^
           13|           "toReadOnlyRenameOptions used on undefined option `${lib.showOption toOpt.loc}'.";

       … while calling 'assertMsg'

         at /nix/store/sdzpqjwx7pdx6lsq6llyfqqf7hspp83c-source/lib/asserts.nix:41:5:

           40|     pred:
           41|     msg:
             |     ^
           42|     pred || builtins.throw msg;

       … while calling anonymous lambda

         at /nix/store/sdzpqjwx7pdx6lsq6llyfqqf7hspp83c-source/lib/modules.nix:831:28:

          830|         # Process mkMerge and mkIf properties.
          831|         defs' = concatMap (m:
             |                            ^
          832|           map (value: { inherit (m) file; inherit value; }) (addErrorContext "while evaluating definitio
ns from `${m.file}':" (dischargeProperties m.value))

       … while evaluating definitions from `/nix/store/16dmwpwbbhc19xpcbazx64vl9smpn2lg-source/modules/top-level/files'
:

       … from call site

         at /nix/store/sdzpqjwx7pdx6lsq6llyfqqf7hspp83c-source/lib/modules.nix:832:128:

          831|         defs' = concatMap (m:
          832|           map (value: { inherit (m) file; inherit value; }) (addErrorContext "while evaluating definitio
ns from `${m.file}':" (dischargeProperties m.value))
             |                                                                                                         
                       ^
          833|         ) defs;

       … while calling 'dischargeProperties'

         at /nix/store/sdzpqjwx7pdx6lsq6llyfqqf7hspp83c-source/lib/modules.nix:903:25:

          902|   */
          903|   dischargeProperties = def:
             |                         ^
          904|     if def._type or "" == "merge" then

       … while calling anonymous lambda

         at /nix/store/sdzpqjwx7pdx6lsq6llyfqqf7hspp83c-source/lib/modules.nix:513:35:

          512|       context = name: ''while evaluating the module argument `${name}' in "${key}":'';
          513|       extraArgs = mapAttrs (name: _:
             |                                   ^
          514|         addErrorContext (context name)

       … while evaluating the module argument `pkgs' in "/nix/store/16dmwpwbbhc19xpcbazx64vl9smpn2lg-source/modules/top
-level/files":

       error: attribute 'pkgs' missing

       at /nix/store/sdzpqjwx7pdx6lsq6llyfqqf7hspp83c-source/lib/modules.nix:515:28:

          514|         addErrorContext (context name)
          515|           (args.${name} or config._module.args.${name})
             |                            ^
          516|       ) (functionArgs f);

Any ideas where pkgs attr is missing?

Minimal, Reproducible Example (MRE)

Minimal flake.nix:

{
  inputs = {
    # Specify the source of Home Manager and Nixpkgs.
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    nixvim = {
      url = "github:nix-community/nixvim";
      # url = "github:nix-community/nixvim?rev=8c3d521bff0142f9b690bccd62c29b3ce8c71ac8";
      # If using a stable channel you can use `url = "github:nix-community/nixvim/nixos-<version>"`
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = {
    nixpkgs,
    home-manager,
    nixvim,
    ...
  }: let
    pkgs = nixpkgs.legacyPackages.${builtins.currentSystem};
  in {
    homeConfigurations.stas = home-manager.lib.homeManagerConfiguration {
      inherit pkgs;

      # Specify your home configuration modules here, for example,
      # the path to your home.nix.
      modules = [
        nixvim.homeManagerModules.nixvim
        {
          home = {
            stateVersion = "24.05";
            username = "stas";
            homeDirectory = "/home/stas";
          };
        }
      ];
    };
  };
}

Then run in a directory with the flake above:

nix eval --impure --expr "((builtins.getFlake path:$PWD).homeConfigurations.stas.options.programs.nixvim.type.getSubOptions []).enable" --show-trace

Alternatively use nix repl:

~$ nix repl .#

nix-repl> homeConfigurations.stas.options.programs.nixvim.type.getSubOptions []

If I change nixvim URL to github:nix-community/nixvim?rev=8c3d521bff0142f9b690bccd62c29b3ce8c71ac8 then it's working again.

@stasjok stasjok added the bug Something isn't working label Oct 6, 2024
@MattSturgeon
Copy link
Member

MattSturgeon commented Oct 10, 2024

Any ideas where pkgs attr is missing?

pkgs comes from the nixpkgs.pkgs option which in tern defines _module.args.pkgs.

Currently, nixpkgs.pkgs is a no-default option and the value is provided by the relevant wrapper module.

In the future, when nixpkgs.pkgs is undefined it will be unused and _module.args.pkgs will instead be based on an internally created nixpkgs instance.

The issue is, we have several options that depend on pkgs for their default value but the submodlue type itself doesn't (yet) have a definition for pkgs, since that is done in the submodule definitions not its declaration.

There may be a less verbose way to do this, perhaps abusing option declaration merging, but one workaround is to use substSubModules:

let
  inherit (homeConfigurations.stas.options.programs.nixvim) type;
  extraModules = [
    { nixpkgs.pkgs = pkgs; }
  ];
  type' = type.substSubModules (type.getSubModules ++ extraModules);
in
  type'.getSubOptions [ ]

But this is a valid issue and we should keep it open until it is resolved on our end. Will be resolved by #1784, but could also be resolved sooner.
EDIT: #2406 should fix this. If you're able to test it out that'd be great!

@stasjok
Copy link
Contributor Author

stasjok commented Oct 11, 2024

the submodlue type itself doesn't (yet) have a definition for pkgs, since that is done in the submodule definitions not its declaration

I see, that explains why setting nixpkgs.pkgs explicitly didn't help.

EDIT: #2406 should fix this. If you're able to test it out that'd be great!

With this PR go to definition in nixd is working correctly for me again, no more errors, no other changes. So it is fixed.

@mergify mergify bot closed this as completed in 5cd8c9c Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants