nixos options json schema
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let | |
pkgs = import ./. {}; | |
lib = pkgs.lib; | |
allOptions = (import ./nixos {}).options; | |
depot = import /home/philip/depot {}; | |
optionSchema = opt: { | |
type = simpletype opt; | |
description = opt.description.text or ""; | |
}; | |
simpletype = option: lib.pipe option [ | |
({type,...}: let n = type.name; in | |
if n == "bool" then "boolean" | |
else if n == "int" then "number" | |
else if n == "str" then "string" | |
else "undefined") | |
]; | |
valMap = f: xs: map ({name, value}: {inherit name; value = f name value; }) xs; | |
optionDiscr = depot.nix.tag.discr [ | |
{ namespace = v: !(v ? _type); } | |
{ invisibleOption = v: | |
# Apparently "shallow" is also an option for `visible`. | |
(v.visible or true) | |
== false; } | |
{ option = _: true; } | |
]; | |
optionNamespaceSchema = nsName: ns: lib.pipe ns [ | |
(depot.nix.mapAttrsMaybe (name: val: lib.pipe val [ | |
optionDiscr | |
(depot.nix.tag.matchLam { | |
namespace = optionNamespaceSchema name; | |
invisibleOption = v: lib.traceSeqN 2 (v.type) null; | |
option = optionSchema; | |
}) | |
])) | |
(vals: { | |
type = "object"; | |
description = "Option namespace ${nsName}"; | |
properties = vals; | |
}) | |
]; | |
in optionNamespaceSchema "toplevel" allOptions |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment