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?
Is man 5 configuration.nix
or this appendix of the NixOS manual good enough?
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.
@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.
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ā¦
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
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 ofnixpkgs
in the Nix paths (meaning, usually, theNIX_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, buildsoptions.json
in an attribute calledoptions
.
Woah thanks for the explanation, it makes good sense! Have a good day/night.