How to look up NixOS module maintainers in the CLI?

I have a command I use to look up package maintainers without manually indexing the meta.maintainers to maintainers/maintainer-list.nix every time (since a lot of the keys are not the same as the GitHub username):

nix eval --expr 'let pkgs = import <nixpkgs> {}; in toString (builtins.map (maintainer: "@${maintainer.github}") pkgs.PACKAGE.meta.maintainers)' --impure --raw

But I’m struggling to come up with a command to do the same for NixOS option maintainers such as these. nixos-option, for example, does not seem to expose the metadata at all.

Update: I’m using flakes for my NixOS configuration, and I don’t have an /etc/nixos/configuration.nix. My NixOS configuration is in a repo.

1 Like

Good question, it seems the maintainers of each modules are exposed through a single config.meta.maintainers. This is quite ugly but it works:

#!/bin/sh
module=$(nixos-option "$1" | grep 'Declared by:' -A 1 | tail -n1 | sed 's/ \+//')

nix-instantiate --eval --strict --expr '
{ module }:
with import <nixpkgs/nixos> {};
  map (x: x.github) config.meta.maintainers.${module}
' --argstr module "$module"

2 Likes

Might as well drop the nixos-option invocation altogether; it’s not doing much.

with import <nixpkgs/nixos> { };
map (x: x.github)
  (config.meta.maintainers.${pkgs.lib.head options.OPTION.declarations} or [ ])
1 Like

I tried doing this in a shell command:

nix eval --expr 'let inherit (import <nixpkgs/nixos> {}) config options pkgs; in map (maintainer: maintainer.github) (config.meta.maintainers.${pkgs.lib.head options.documentation.declarations} or [])' --impure --raw

But I get the same issue as many other attempts:

error: file ‘nixos-config’ was not found in the Nix search path (add it using $NIX_PATH or -I)

Wait, but nixos-option documentation does the expected thing? That’s strange if so.

Are you flakin’? I see there’s a comment in nixos/modules/misc/nixpkgs-flake.nix about NIX_PATH not containing nixos-config in the flake case, and I guess if you’re using nixos-option --flake that’ll continue to work. Someone else will have to tell you how to import the NixOS module system when your system is flaked, I’m afraid.

No, nixos-option documentation has the same issue. And yes, I’m using flakes.

1 Like

This should give an attrset with config and options:

import <nixpkgs/nixos/lib/eval-config.nix> { modules = [{}]; }

This has the same problem:

❯ nix eval --expr 'let inherit (import <nixpkgs/nixos> {}) pkgs; inherit (import <nixpkgs/nixos/lib/eval-config.nix> { modules = [{}]; }) config options; in map (maintainer: maintainer.github) (config.meta.maintainers.${pkgs.lib.head options.documentation.declarations} or [])' --impure --raw
error:
       … while calling the 'map' builtin
         at «string»:1:139:
            1| let inherit (import <nixpkgs/nixos> {}) pkgs; inherit (import <nixpkgs/nixos/lib/eval-config.nix> { modules = [{}]; }) config options; in map (maintainer: maintainer.github) (config.meta.maintainers.${pkgs.lib.head options.documentation.declarations} or [])
             |                                                                                                                                           ^

       … while evaluating the attribute 'pkgs'
         at /nix/store/klbzxibpzfh6qqvn78axh0373zl4kkrh-source/nixos/default.nix:19:18:
           18| {
           19|   inherit (eval) pkgs config options;
             |                  ^
           20|

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: file 'nixos-config' was not found in the Nix search path (add it using $NIX_PATH or -I)

You might find this project useful. I’ve got an update coming out soon for it that improves speed, but in the mean-time it’s still maybe helpful.

right, because you are still import <nixpkgs/nixos> {}ing… seemingly to get pkgs which is then only used for pkgs.lib.head which can likely be replaced by builtins.head.

If you really truly need pkgs, then the import statement I provided also provides pkgs and others beyond just config and options.

1 Like

Nice, that helped! But it looks like declarations isn’t always available:

❯ nix eval --expr 'let inherit (import <nixpkgs/nixos/lib/eval-config.nix> { modules = [{}]; }) config options; in map (maintainer: maintainer.github) (config.meta.maintainers.${builtins.head options.documentation.declarations} or [])' --impure --raw    
error:
       … while calling the 'map' builtin
         at «string»:1:97:
            1| let inherit (import <nixpkgs/nixos/lib/eval-config.nix> { modules = [{}]; }) config options; in map (maintainer: maintainer.github) (config.meta.maintainers.${builtins.head options.documentation.declarations} or [])
             |                                                                                                 ^

       … while calling the 'head' builtin
         at «string»:1:160:
            1| let inherit (import <nixpkgs/nixos/lib/eval-config.nix> { modules = [{}]; }) config options; in map (maintainer: maintainer.github) (config.meta.maintainers.${builtins.head options.documentation.declarations} or [])
             |                                                                                                                                                                ^

       error: attribute 'declarations' missing
       at «string»:1:174:
            1| let inherit (import <nixpkgs/nixos/lib/eval-config.nix> { modules = [{}]; }) config options; in map (maintainer: maintainer.github) (config.meta.maintainers.${builtins.head options.documentation.declarations} or [])
             |                                                                                                                                                                              ^

(Got the same result with options.documentation.man.declarations.)

I’m pretty sure the declaration tracking code only happens for things that get defined with mkOption. Use the leaf node documentation.man.enable?

Prob if you don’t expect a description, also don’t expect a declarations.

It looks like declarations is just a store path with a percentage sign after it:

nix-repl> builtins.elemAt options.documentation.man.enable.declarations 0 
"/nix/store/klbzxibpzfh6qqvn78axh0373zl4kkrh-source/nixos/modules/misc/documentation.nix"

Percentage sign?

Anyway, yes, the attribute names of config.meta.maintainers are also store paths, so that’s as it should be.

OK, so this doesn’t look like it’ll work:

❯ nix eval --expr 'let inherit (import <nixpkgs/nixos/lib/eval-config.nix> { modules = [{}]; }) config options; in toString (map (maintainer: "@${maintainer.github}") config.meta.maintainers.${builtins.head options.documentation.man.enable.declarations})' --impure --raw
error:
       … while calling the 'toString' builtin
         at «string»:1:97:
            1| let inherit (import <nixpkgs/nixos/lib/eval-config.nix> { modules = [{}]; }) config options; in toString (map (maintainer: "@${maintainer.github}") config.meta.maintainers.${builtins.head options.documentation.man.enable.declarations})
             |                                                                                                 ^

       … while calling the 'map' builtin
         at «string»:1:107:
            1| let inherit (import <nixpkgs/nixos/lib/eval-config.nix> { modules = [{}]; }) config options; in toString (map (maintainer: "@${maintainer.github}") config.meta.maintainers.${builtins.head options.documentation.man.enable.declarations})
             |                                                                                                           ^

       error: attribute '"/nix/store/klbzxibpzfh6qqvn78axh0373zl4kkrh-source/nixos/modules/misc/documentation.nix"' missing
       at «string»:1:149:
            1| let inherit (import <nixpkgs/nixos/lib/eval-config.nix> { modules = [{}]; }) config options; in toString (map (maintainer: "@${maintainer.github}") config.meta.maintainers.${builtins.head options.documentation.man.enable.declarations})
             |                                                                                                                                                     ^

It’s ‘working’; there are no meta.maintainers defined in nixpkgs/nixos/modules/misc/documentation.nix at 4382ed2b7a6839d4280a9b386db49cbc5907414d · NixOS/nixpkgs · GitHub. (That’s what the or [ ] was for).

1 Like

There are maintainers defined in an import of that file, though.

yet that doesn’t seem to matter for config.meta.maintainers which is where the error message you posted is pointing you. Is it unreasonable to just add back the or [] as suggested?

EDIT: actually I’m just confused. Why are you linking meta.doc when you are having issues with documentation.man.enable?

I don’t know what you mean. I don’t see meta.doc anywhere in this post.

I simply want to know a simple shell command to get the maintainers of the documentation options. It’s imported in documentation.nix, but I can’t find it anywhere in options.documentation in the Nix REPL.

Modules don’t inherit the maintainers of modules they import. Each module is distinct. So if you’re interested in the meta.doc option:

nix-repl> map (x: x.github) (config.meta.maintainers.${pkgs.lib.head options.meta.doc.declarations} or [ ])
[
  "nbp"
  "roberth"
]

That’s correct.

If you’re interested in documentation.man.enable, which is defined in a different module,

nix-repl> map (x: x.github) (config.meta.maintainers.${pkgs.lib.head options.documentation.man.enable.declarations} or [ ])
[ ]

That’s also correct.

1 Like