+8
-3
lib/options.nix
+8
-3
lib/options.nix
···
113
113
: Optional boolean indicating whether the option is for NixOS developers only.
114
114
115
115
`visible`
116
-
: Optional boolean indicating whether the option shows up in the manual. Default: true. Use false to hide the option and any sub-options from submodules. Use "shallow" to hide only sub-options.
116
+
: Optional, whether the option and/or sub-options show up in the manual.
117
+
Use false to hide the option and any sub-options from submodules.
118
+
Use "shallow" to hide only sub-options.
119
+
Use "transparent" to hide this option, but not its sub-options.
120
+
Default: true.
117
121
118
122
`readOnly`
119
123
: Optional boolean indicating whether the option can be set only once.
···
572
576
opt:
573
577
let
574
578
name = showOption opt.loc;
579
+
visible = opt.visible or true;
575
580
docOption = {
576
581
loc = opt.loc;
577
582
inherit name;
578
583
description = opt.description or null;
579
584
declarations = filter (x: x != unknownModule) opt.declarations;
580
585
internal = opt.internal or false;
581
-
visible = if (opt ? visible && opt.visible == "shallow") then true else opt.visible or true;
586
+
visible = if isBool visible then visible else visible == "shallow";
582
587
readOnly = opt.readOnly or false;
583
588
type = opt.type.description or "unspecified";
584
589
}
···
601
606
ss = opt.type.getSubOptions opt.loc;
602
607
in
603
608
if ss != { } then optionAttrSetToDocList' opt.loc ss else [ ];
604
-
subOptionsVisible = docOption.visible && opt.visible or null != "shallow";
609
+
subOptionsVisible = if isBool visible then visible else visible == "transparent";
605
610
in
606
611
# To find infinite recursion in NixOS option docs:
607
612
# builtins.trace opt.loc
+105
lib/tests/misc.nix
+105
lib/tests/misc.nix
···
3210
3210
];
3211
3211
};
3212
3212
3213
+
testDocOptionVisiblity = {
3214
+
expr =
3215
+
let
3216
+
submodule =
3217
+
{ lib, ... }:
3218
+
{
3219
+
freeformType = lib.types.attrsOf (
3220
+
lib.types.submodule {
3221
+
options.bar = lib.mkOption { };
3222
+
}
3223
+
);
3224
+
options.foo = lib.mkOption { };
3225
+
};
3226
+
3227
+
module =
3228
+
{ lib, ... }:
3229
+
{
3230
+
options = {
3231
+
shallow = lib.mkOption {
3232
+
type = lib.types.submodule submodule;
3233
+
visible = "shallow";
3234
+
};
3235
+
transparent = lib.mkOption {
3236
+
type = lib.types.submodule submodule;
3237
+
visible = "transparent";
3238
+
};
3239
+
"true" = lib.mkOption {
3240
+
type = lib.types.submodule submodule;
3241
+
visible = true;
3242
+
};
3243
+
"false" = lib.mkOption {
3244
+
type = lib.types.submodule submodule;
3245
+
visible = false;
3246
+
};
3247
+
"internal" = lib.mkOption {
3248
+
type = lib.types.submodule submodule;
3249
+
internal = true;
3250
+
};
3251
+
};
3252
+
};
3253
+
3254
+
options =
3255
+
(evalModules {
3256
+
modules = [ module ];
3257
+
}).options;
3258
+
in
3259
+
pipe options [
3260
+
optionAttrSetToDocList
3261
+
(filter (opt: !(builtins.elem "_module" opt.loc)))
3262
+
(map (
3263
+
opt:
3264
+
nameValuePair opt.name {
3265
+
inherit (opt) visible internal;
3266
+
}
3267
+
))
3268
+
listToAttrs
3269
+
];
3270
+
expected = {
3271
+
shallow = {
3272
+
visible = true;
3273
+
internal = false;
3274
+
};
3275
+
transparent = {
3276
+
visible = false;
3277
+
internal = false;
3278
+
};
3279
+
"transparent.foo" = {
3280
+
visible = true;
3281
+
internal = false;
3282
+
};
3283
+
"transparent.<name>.bar" = {
3284
+
visible = true;
3285
+
internal = false;
3286
+
};
3287
+
"true" = {
3288
+
visible = true;
3289
+
internal = false;
3290
+
};
3291
+
"true.foo" = {
3292
+
visible = true;
3293
+
internal = false;
3294
+
};
3295
+
"true.<name>.bar" = {
3296
+
visible = true;
3297
+
internal = false;
3298
+
};
3299
+
"false" = {
3300
+
visible = false;
3301
+
internal = false;
3302
+
};
3303
+
"internal" = {
3304
+
visible = true;
3305
+
internal = true;
3306
+
};
3307
+
"internal.foo" = {
3308
+
visible = true;
3309
+
internal = false;
3310
+
};
3311
+
"internal.<name>.bar" = {
3312
+
visible = true;
3313
+
internal = false;
3314
+
};
3315
+
};
3316
+
};
3317
+
3213
3318
testAttrsWithName = {
3214
3319
expr =
3215
3320
let