Getting options of a module for nixd autocompletion

I added the non-nix docs, but it only covers hm, because I don’t do anything custom with nixos :slight_smile:

However I still think the basic pattern would be the same. Assuming your custom modules don’t live in glorious isolation from nixos, then what you want to is to eval nixos using your root configuration. You can figure this out in two ways.

  1. Know that nixos-rebuild repl somehow is doing what you want
  2. Know that building <nixpkgs/nixos> does something useful.

Lets assume mystically you’ve decided to look at nixpkgs/nixos/default.nix you’ll notice it takes an argument which is the path to a specific configuration.

❯ nix repl --file '<nixpkgs>'
Nix 2.24.14
Type :? for help.
Loading installable ''...
Added 23037 variables.
nix-repl> options = (import <nixpkgs/nixos> { configuration = /etc/nixos/configuration.nix; }).options

nix-repl> options.
options._module            options.ec2                options.jobs               options.nixpkgs            options.security           options.time
options.appstream          options.environment        options.krb5               options.oci                options.services           options.users
options.assertions         options.fileSystems        options.lib                options.openstack          options.snapraid           options.virtualisation
options.boot               options.fonts              options.location           options.passthru           options.sound              options.warnings
options.console            options.gtk                options.meta               options.power              options.specialisation     options.xdg
options.containers         options.hardware           options.nesting            options.powerManagement    options.stubby             options.zramSwap
options.docker-containers  options.i18n               options.networking         options.programs           options.swapDevices
options.documentation      options.ids                options.nix                options.qt                 options.system
options.dysnomia           options.isSpecialisation   options.nixops             options.qt5                options.systemd

These options will contain any custom options you imported under your configuration.

You could test this out then a contribution to the nixd docs :slight_smile:

1 Like