2020-09-16 14:55:24 +02:00
|
|
|
with builtins;
|
|
|
|
|
2021-01-25 18:19:32 +01:00
|
|
|
rec {
|
2020-09-16 14:55:24 +02:00
|
|
|
splitLines = s: filter (x: !isList x) (split "\n" s);
|
|
|
|
|
|
|
|
concatStrings = concatStringsSep "";
|
2021-01-25 18:19:32 +01:00
|
|
|
|
2024-04-05 01:07:44 +02:00
|
|
|
attrsToList =
|
|
|
|
a:
|
|
|
|
map (name: {
|
|
|
|
inherit name;
|
|
|
|
value = a.${name};
|
|
|
|
}) (builtins.attrNames a);
|
|
|
|
|
|
|
|
replaceStringsRec =
|
|
|
|
from: to: string:
|
2022-08-26 23:09:19 +02:00
|
|
|
# recursively replace occurrences of `from` with `to` within `string`
|
|
|
|
# example:
|
|
|
|
# replaceStringRec "--" "-" "hello-----world"
|
|
|
|
# => "hello-world"
|
|
|
|
let
|
|
|
|
replaced = replaceStrings [ from ] [ to ] string;
|
|
|
|
in
|
2024-04-05 01:07:44 +02:00
|
|
|
if replaced == string then string else replaceStringsRec from to replaced;
|
2022-08-26 23:09:19 +02:00
|
|
|
|
|
|
|
squash = replaceStringsRec "\n\n\n" "\n\n";
|
|
|
|
|
2024-04-05 01:07:44 +02:00
|
|
|
trim =
|
|
|
|
string:
|
2022-08-26 23:09:19 +02:00
|
|
|
# trim trailing spaces and squash non-leading spaces
|
|
|
|
let
|
2024-04-05 01:07:44 +02:00
|
|
|
trimLine =
|
|
|
|
line:
|
2022-08-26 23:09:19 +02:00
|
|
|
let
|
|
|
|
# separate leading spaces from the rest
|
|
|
|
parts = split "(^ *)" line;
|
|
|
|
spaces = head (elemAt parts 1);
|
|
|
|
rest = elemAt parts 2;
|
|
|
|
# drop trailing spaces
|
|
|
|
body = head (split " *$" rest);
|
2024-04-05 01:07:44 +02:00
|
|
|
in
|
|
|
|
spaces + replaceStringsRec " " " " body;
|
|
|
|
in
|
|
|
|
concatStringsSep "\n" (map trimLine (splitLines string));
|
2022-08-26 23:09:19 +02:00
|
|
|
|
2021-01-25 18:19:32 +01:00
|
|
|
# FIXME: O(n^2)
|
2024-04-05 01:07:44 +02:00
|
|
|
unique = foldl' (acc: e: if elem e acc then acc else acc ++ [ e ]) [ ];
|
2021-01-25 18:19:32 +01:00
|
|
|
|
|
|
|
nameValuePair = name: value: { inherit name value; };
|
|
|
|
|
2024-04-05 01:07:44 +02:00
|
|
|
filterAttrs =
|
|
|
|
pred: set:
|
|
|
|
listToAttrs (
|
|
|
|
concatMap (
|
|
|
|
name:
|
|
|
|
let
|
|
|
|
v = set.${name};
|
|
|
|
in
|
|
|
|
if pred name v then [ (nameValuePair name v) ] else [ ]
|
|
|
|
) (attrNames set)
|
|
|
|
);
|
2023-03-21 12:58:14 +01:00
|
|
|
|
2023-04-16 16:44:03 +02:00
|
|
|
optionalString = cond: string: if cond then string else "";
|
|
|
|
|
2024-04-05 01:07:44 +02:00
|
|
|
showSetting =
|
|
|
|
{ inlineHTML }:
|
|
|
|
name:
|
|
|
|
{
|
|
|
|
description,
|
|
|
|
documentDefault,
|
|
|
|
defaultValue,
|
|
|
|
aliases,
|
|
|
|
value,
|
|
|
|
experimentalFeature,
|
|
|
|
}:
|
2023-03-21 12:58:14 +01:00
|
|
|
let
|
|
|
|
result = squash ''
|
2024-04-05 01:07:44 +02:00
|
|
|
- ${
|
|
|
|
if inlineHTML then ''<span id="conf-${name}">[`${name}`](#conf-${name})</span>'' else ''`${name}`''
|
|
|
|
}
|
2023-03-21 12:58:14 +01:00
|
|
|
|
2024-04-05 01:07:44 +02:00
|
|
|
${indent " " body}
|
|
|
|
'';
|
2023-03-21 14:12:15 +01:00
|
|
|
|
2023-04-10 18:02:35 +02:00
|
|
|
experimentalFeatureNote = optionalString (experimentalFeature != null) ''
|
2024-04-05 01:07:44 +02:00
|
|
|
> **Warning**
|
|
|
|
> This setting is part of an
|
|
|
|
> [experimental feature](@docroot@/contributing/experimental-features.md).
|
2023-04-10 18:02:35 +02:00
|
|
|
|
2024-04-05 01:07:44 +02:00
|
|
|
To change this setting, you need to make sure the corresponding experimental feature,
|
|
|
|
[`${experimentalFeature}`](@docroot@/contributing/experimental-features.md#xp-feature-${experimentalFeature}),
|
|
|
|
is enabled.
|
|
|
|
For example, include the following in [`nix.conf`](#):
|
2023-04-10 18:02:35 +02:00
|
|
|
|
2024-04-05 01:07:44 +02:00
|
|
|
```
|
|
|
|
extra-experimental-features = ${experimentalFeature}
|
|
|
|
${name} = ...
|
|
|
|
```
|
|
|
|
'';
|
2023-04-10 18:02:35 +02:00
|
|
|
|
2023-03-21 12:58:14 +01:00
|
|
|
# separate body to cleanly handle indentation
|
|
|
|
body = ''
|
2024-04-05 01:07:44 +02:00
|
|
|
${description}
|
2023-03-21 12:58:14 +01:00
|
|
|
|
2024-04-05 01:07:44 +02:00
|
|
|
${experimentalFeatureNote}
|
2023-04-10 18:02:35 +02:00
|
|
|
|
2024-04-05 01:07:44 +02:00
|
|
|
**Default:** ${showDefault documentDefault defaultValue}
|
2023-03-21 12:58:14 +01:00
|
|
|
|
2024-04-05 01:07:44 +02:00
|
|
|
${showAliases aliases}
|
|
|
|
'';
|
2023-03-21 14:12:15 +01:00
|
|
|
|
2024-04-05 01:07:44 +02:00
|
|
|
showDefault =
|
|
|
|
documentDefault: defaultValue:
|
2023-03-21 12:58:14 +01:00
|
|
|
if documentDefault then
|
|
|
|
# a StringMap value type is specified as a string, but
|
|
|
|
# this shows the value type. The empty stringmap is `null` in
|
|
|
|
# JSON, but that converts to `{ }` here.
|
2024-04-05 01:07:44 +02:00
|
|
|
if defaultValue == "" || defaultValue == [ ] || isAttrs defaultValue then
|
|
|
|
"*empty*"
|
|
|
|
else if isBool defaultValue then
|
|
|
|
if defaultValue then "`true`" else "`false`"
|
|
|
|
else
|
|
|
|
"`${toString defaultValue}`"
|
|
|
|
else
|
|
|
|
"*machine-specific*";
|
|
|
|
|
|
|
|
showAliases =
|
|
|
|
aliases:
|
|
|
|
optionalString (aliases != [ ])
|
|
|
|
"**Deprecated alias:** ${(concatStringsSep ", " (map (s: "`${s}`") aliases))}";
|
|
|
|
in
|
|
|
|
result;
|
2023-03-21 12:58:14 +01:00
|
|
|
|
2024-04-05 01:07:44 +02:00
|
|
|
indent =
|
|
|
|
prefix: s: concatStringsSep "\n" (map (x: if x == "" then x else "${prefix}${x}") (splitLines s));
|
2023-04-05 04:57:11 +02:00
|
|
|
|
2024-04-05 01:07:44 +02:00
|
|
|
showSettings =
|
|
|
|
args: settingsInfo: concatStrings (attrValues (mapAttrs (showSetting args) settingsInfo));
|
2020-09-16 14:55:24 +02:00
|
|
|
}
|