extract-options.nix (1031B)
1 { 2 eval, 3 lib, 4 pkgs, 5 }: 6 let 7 conf = eval.config; 8 rootDir = builtins.toPath ./..; 9 stripAnyPrefixes = lib.flip (lib.fold lib.removePrefix) [ "${rootDir}/" ]; 10 optToDoc = name: opt: { 11 inherit name; 12 description = opt.description or null; 13 default = opt.default or null; 14 visible = if (opt ? visible && opt.visible == "shallow") then true else opt.visible or true; 15 readOnly = opt.readOnly or false; 16 type = opt.type.description or "unspecified"; 17 }; 18 spliceServiceDefn = 19 item: 20 if item.type == "parametrisable s6-rc service definition" then 21 let 22 sd = lib.attrByPath item.loc [ "not found" ] conf; 23 in 24 item 25 // { 26 declarations = map stripAnyPrefixes item.declarations; 27 parameters = 28 let 29 x = lib.mapAttrsToList optToDoc sd.parameters; 30 in 31 x; 32 } 33 else 34 item // { declarations = map stripAnyPrefixes item.declarations; }; 35 in 36 builtins.map spliceServiceDefn (pkgs.lib.optionAttrSetToDocList eval.options)