List available services and their options

Is there a command to list all available services and their options, preferably in a machine-readable format? I know about nix search --json, for example, but that only seems to search for packages.

Have you looked at nixos-option?

From the manpage and the programā€™s behavior, it seems to only inspect the current configuration. Iā€™d like to have a list of all services, even those not currently enabled by me.
There is this service listing all the options on a website, how is that generated?

Ermā€¦it does show you the current status on your system but it also shows the full doc for the service/program even if it isnā€™t configured.

nixos-option services - returns a list of all the available services.
nixos-option services.zookeeper - returns a list of everything that can be set for zookeeper
nixos-option services.zookeeper.service provides the full doc for that specific option

Am I misunderstanding what you are wanting?

2 Likes

Is man 5 configuration.nix or this appendix of the NixOS manual good enough?

2 Likes

You can list all options using

$ curl https://nixos.org/nixos/options.json | jq keys

Or better in a local clone of the Nixpkgs repo

$ nix-build nixos/release.nix -A options
$ jq keys < result/share/doc/nixos/options.json

Of course, the JSON also contains various other information about the options.

7 Likes

Thanks guys for your excellent replies, problem solved!

Hi @pimiddy, I would be interrested in which of the above options solved the task that you were trying to do.
Would you mind sharing?

Thanks in advance.

@mkroehnert Absolutely! So, nixos-options turned out to be a dead-end for me. It does list all available options, but not in a form thatā€™s readily machine-readable. It also crashes on unknown CLI options, which leads me to believe not much work is being done on this tool (or QA standards are extremely low).

man 5 configuration.nix is, of course, also not machine-readable.

So I went with downloading and parsing the options.json file. Parsing JSON is easy enough, and with some minimal post-processing you can group options into services. Itā€™s still rather meant for human consumption (as seen by the type field) and Iā€™d love a command-based solution so I donā€™t have to drag around this huge JSON file, but for now, this is fine.

In case youā€™re asking my use-case specifically, Iā€™m currently spending my Coronatimeā„¢ working on a graphical NixOS manager, (see here) for fun.

2 Likes

@pimiddy thank you very much for your detailed answer.

Okay, as ofā€¦today? This file (meaning https://nixos.org/nixos/options.json) is no longer available. Was it moved?

Edit: Nevermind. It was moved and brotli-compressed.

1 Like

Actually I think you can generate that file locally using something like the following:
nix-build -E 'with import <nixpkgs> {}; let eval = import (pkgs.path + "/nixos/lib/eval-config.nix") { modules = []; }; opts = (nixosOptionsDoc { options = eval.options; }).optionsJSON; in runCommandLocal "options.json" { inherit opts; } "cp $opts/share/doc/nixos/options.json $out" '
Someone with better knowledge of nixpkgs can probably say, if that is a sound way to do thingsā€¦

2 Likes

I am very sorry to re-open this, but I was just wondering if anyone knows a way to get the holy grail (options.json) that works now? I need it for a program that I am currently working on which is quite similar to pimiddyā€™s

nix-build '<nixpkgs/nixos/release.nix>' -A options
3 Likes

Thanks this works! Could you explain it to me (sorry I am still a bit new)?

Sure:

  • ā€˜nix-build path -A attrpathā€™ is a command that will evaluate a Nix file found at path, then select an attribute from the result which should contain a derivation, and realize (build) that derivation.
  • <nixpkgs/path> is a syntax that in Nix means to look up the location of nixpkgs in the Nix paths (meaning, usually, the NIX_PATH environment variableā€”itself meaning, usually, oneā€™s channels), and find path relative to that location.
  • nixos/release.nix is a file that I found poking around in Nixpkgs that, among other at-release tasks, builds options.json in an attribute called options.
2 Likes

Woah thanks for the explanation, it makes good sense! Have a good day/night.