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?
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.
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.
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.
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…