Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Types from lib.nix #180

Open
lapp0 opened this issue Nov 14, 2021 · 0 comments · May be fixed by #181
Open

Get Types from lib.nix #180

lapp0 opened this issue Nov 14, 2021 · 0 comments · May be fixed by #181

Comments

@lapp0
Copy link
Collaborator

lapp0 commented Nov 14, 2021

#187 (comment)

Parsing type strings is hacky and we can do better for all types. For this issue, we will update lib.nix to extract the type, and update types.py to handle type checking without parsing.

Simple case

nix-instantiate --eval '<nixpkgs/nixos>' --arg configuration '{}' -A "options.sound.enable.type.name"
"bool"

A complex YAML type example

NixOS/nixpkgs#99132

The above PRs author suggests we can break down each component of a type so it's more specific than YAML (AnythingType):

nix-instantiate --eval '<nixpkgs/nixos>' --arg configuration '{}' -A "options.services.zrepl.settings.type.nestedTypes.freeformType.nestedTypes.elemType.nestedTypes.left.nestedTypes.left.nestedTypes.left.nestedTypes.left.nestedTypes.left.name"
"bool"

Submodules

Get submodule structure in cases where <name> and * don't exist

Some options, for example system.userActivationScripts, system.activationScripts, services.certmgr.specs, programs.firejail.wrappedBinaries have the types AttrsOf(Submodule) or ListOf(Submodule), however there isn't system.userActivationScripts."<name>".options in the option tree.

Additionally, some options are simply submodules whose structure isn't discoverable through the option tree.

pkgs.nixosOptionsDoc is insufficient to get data about all submodules, however matrix user sternenseemann has suggested:

(builtins.head ((nixos {}).options.system.userActivationScripts.type.nestedTypes.elemType.nestedTypes.right.getSubModules)) which gives us details about the structure of submodules.

Types with Checks

Types that have checks (e.g. time.timezone is "null or string without spaces"):

nix-instantiate --eval '<nixpkgs/nixos>' --arg configuration '{}' -A "options.time.timeZone.type.name"
"nullOr"

nix-instantiate --eval '<nixpkgs/nixos>' --arg configuration '{}' -A "options.time.timeZone.type.nestedTypes.elemType.name"
"str"

nix-instantiate --eval '<nixpkgs/nixos>' --arg configuration '{}' -A "options.time.timeZone.type.nestedTypes.elemType.check"
<LAMBDA>

# We can execute the typecheck as follows
nix-instantiate --eval -E 'let nixos = (import <nixpkgs/nixos> {configuration={};}); in nixos.options.time.timeZone.type.nestedTypes.elemType.check "foo"'
true

nix-instantiate --eval -E 'let nixos = (import <nixpkgs/nixos> {configuration={};}); in nixos.options.time.timeZone.type.nestedTypes.elemType.check "foo bar"'
false
This was referenced Nov 15, 2021
@lapp0 lapp0 changed the title Get submodule structure in cases where <name> and * don't exist Get Types from lib.nix Nov 18, 2021
@lapp0 lapp0 added this to the V0.3 milestone Dec 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant