-
Notifications
You must be signed in to change notification settings - Fork 59
overview: add content-type for option #1288
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bb30b13
overview: add content-type for option
eljamm f9df586
refactor
eljamm 6b941aa
render many options
eljamm 4098dd3
cleanup
eljamm 50e6b1b
more cleanup
eljamm 070c654
address review comments
eljamm b3affe1
address more review comments
eljamm ff63039
rename options to option-list
eljamm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| { | ||
| lib, | ||
| name, | ||
| config, | ||
| pkgs, | ||
| ... | ||
| }: | ||
| let | ||
| inherit (lib) | ||
| types | ||
| mkOption | ||
| optionalString | ||
| join | ||
| concatLines | ||
| ; | ||
| in | ||
| { | ||
| options = { | ||
| prefix = mkOption { | ||
| type = with types; listOf str; | ||
| }; | ||
| project-options = mkOption { | ||
| type = | ||
| with types; | ||
| listOf (submodule { | ||
| imports = [ ./option.nix ]; | ||
| _module.args.pkgs = pkgs; | ||
| }); | ||
| default = [ ]; | ||
| }; | ||
| __toString = mkOption { | ||
| type = with types; functionTo str; | ||
| readOnly = true; | ||
| default = | ||
| self: | ||
| optionalString (self.project-options != [ ]) '' | ||
| <details><summary><code>${join "." self.prefix}</code></summary><dl> | ||
| ${concatLines (map toString self.project-options)} | ||
| </dl></details> | ||
| ''; | ||
| }; | ||
| }; | ||
| } |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| { | ||
| lib, | ||
| pkgs, | ||
| config, | ||
| ... | ||
| }: | ||
| let | ||
| inherit (lib) | ||
| types | ||
| mkOption | ||
| join | ||
| drop | ||
| optionalString | ||
| take | ||
| ; | ||
| in | ||
| { | ||
| options = { | ||
| # TODO: simplify this / make it dynamic | ||
| prefix-length = mkOption { | ||
| type = types.int; | ||
| description = '' | ||
| Length to visually separate the fixed and moving parts of an option, making | ||
| less specific elements less dominant to reduce cognitive load. | ||
| ''; | ||
| default = 2; | ||
| }; | ||
| attrpath = mkOption { | ||
| type = with types; listOf str; | ||
| description = '' | ||
| Attribute path in the NixOS options tree. | ||
| ''; | ||
| }; | ||
| type = mkOption { | ||
| type = types.str; | ||
| }; | ||
| default = mkOption { | ||
| type = types.attrs; | ||
| default = { }; | ||
| }; | ||
| description = mkOption { | ||
| type = types.str; | ||
| }; | ||
| readOnly = mkOption { | ||
| type = types.bool; | ||
| }; | ||
| __toString = mkOption { | ||
| type = with types; functionTo str; | ||
| readOnly = true; | ||
| default = | ||
| self: | ||
| let | ||
| option-prefix = | ||
| let | ||
| prefix-head = take self.prefix-length self.attrpath; | ||
| prefix-tail = drop self.prefix-length self.attrpath; | ||
| in | ||
| '' | ||
| <span class="option-prefix">${join "." prefix-head}.</span><span>${join "." prefix-tail}</span> | ||
| ''; | ||
| option-type = '' | ||
| <dt>Type:</dt> | ||
| <dd class="option-type"><code>${self.type}</code></dd> | ||
| ''; | ||
| option-default = optionalString (self.default ? text) '' | ||
| <dt>Default:</dt> | ||
| <dd class="option-default"><code>${self.default.text}</code></dd> | ||
| ''; | ||
| option-description = | ||
| let | ||
| # This doesn't actually produce a HTML string but a Jinja2 template string | ||
| # literal, that is then replaced by it's HTML translation at the last build | ||
| # step. | ||
| # Also, this avoids IFD (which would make things very slow with a | ||
| # growing number of such strings in the website rendering) since | ||
| # this way we can do markdown processing in a single step per output file at the end | ||
| markdownToHtml = markdown: "{{ markdown_to_html(${builtins.toJSON markdown}) }}"; | ||
| in | ||
| '' | ||
| <div class="option-description"> | ||
| ${markdownToHtml self.description} | ||
| </div> | ||
| ''; | ||
| alert-update-script = | ||
| let | ||
| isDrv = self.type == "package"; | ||
| optionName = lib.removePrefix "pkgs." self.default.text; | ||
| in | ||
| # TODO: plug a function that recurses into all dependencies, | ||
| # so we'd know how much of the build graph is kept up to date automatically | ||
| optionalString (isDrv && !pkgs ? ${optionName}.passthru.updateScript) '' | ||
| <dt>Notes:</dt> | ||
| <dd><span class="option-alert">Missing update script</span> An update script is required for automatically tracking the latest release.</dd> | ||
| ''; | ||
| in | ||
| '' | ||
| <dt class="option-name"> | ||
| ${option-prefix} | ||
| ${optionalString self.readOnly '' | ||
| <span class="option-alert" title="This option can't be set by users">Read-only</span> | ||
| ''} | ||
| </dt> | ||
| <dd class="option-body"> | ||
| ${option-description} | ||
| <dl> | ||
| ${option-type} | ||
| ${option-default} | ||
| ${alert-update-script} | ||
| </dl> | ||
| </dd> | ||
| ''; | ||
| }; | ||
| }; | ||
| } | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.