mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-10 03:23:29 +03:00
Add read-only options
These are options that can have only one definition, regardless of priority.
This commit is contained in:
parent
d61e1b24e6
commit
f463d24903
4 changed files with 16 additions and 5 deletions
|
@ -261,11 +261,16 @@ rec {
|
||||||
evalOptionValue = loc: opt: defs:
|
evalOptionValue = loc: opt: defs:
|
||||||
let
|
let
|
||||||
# Add in the default value for this option, if any.
|
# Add in the default value for this option, if any.
|
||||||
defs' = (optional (opt ? default)
|
defs' =
|
||||||
{ file = head opt.declarations; value = mkOptionDefault opt.default; }) ++ defs;
|
(optional (opt ? default)
|
||||||
|
{ file = head opt.declarations; value = mkOptionDefault opt.default; }) ++ defs;
|
||||||
|
|
||||||
# Handle properties, check types, and merge everything together.
|
# Handle properties, check types, and merge everything together.
|
||||||
res = mergeDefinitions loc opt.type defs';
|
res =
|
||||||
|
if opt.readOnly or false && length defs' > 1 then
|
||||||
|
throw "The option `${showOption loc}' is read-only, but it's set multiple times."
|
||||||
|
else
|
||||||
|
mergeDefinitions loc opt.type defs';
|
||||||
|
|
||||||
# Check whether the option is defined, and apply the ‘apply’
|
# Check whether the option is defined, and apply the ‘apply’
|
||||||
# function to the merged value. This allows options to yield a
|
# function to the merged value. This allows options to yield a
|
||||||
|
|
|
@ -19,6 +19,7 @@ rec {
|
||||||
, apply ? null # Function that converts the option value to something else.
|
, apply ? null # Function that converts the option value to something else.
|
||||||
, internal ? null # Whether the option is for NixOS developers only.
|
, internal ? null # Whether the option is for NixOS developers only.
|
||||||
, visible ? null # Whether the option shows up in the manual.
|
, visible ? null # Whether the option shows up in the manual.
|
||||||
|
, readOnly ? null # Whether the option can be set only once
|
||||||
, options ? null # Obsolete, used by types.optionSet.
|
, options ? null # Obsolete, used by types.optionSet.
|
||||||
} @ attrs:
|
} @ attrs:
|
||||||
attrs // { _type = "option"; };
|
attrs // { _type = "option"; };
|
||||||
|
@ -90,6 +91,7 @@ rec {
|
||||||
declarations = filter (x: x != unknownModule) opt.declarations;
|
declarations = filter (x: x != unknownModule) opt.declarations;
|
||||||
internal = opt.internal or false;
|
internal = opt.internal or false;
|
||||||
visible = opt.visible or true;
|
visible = opt.visible or true;
|
||||||
|
readOnly = opt.readOnly or false;
|
||||||
type = opt.type.name or null;
|
type = opt.type.name or null;
|
||||||
}
|
}
|
||||||
// (if opt ? example then { example = scrubOptionValue opt.example; } else {})
|
// (if opt ? example then { example = scrubOptionValue opt.example; } else {})
|
||||||
|
|
|
@ -39,6 +39,10 @@
|
||||||
<emphasis>Type:</emphasis>
|
<emphasis>Type:</emphasis>
|
||||||
<xsl:text> </xsl:text>
|
<xsl:text> </xsl:text>
|
||||||
<xsl:apply-templates select="attr[@name = 'type']" mode="top" />
|
<xsl:apply-templates select="attr[@name = 'type']" mode="top" />
|
||||||
|
<xsl:if test="attr[@name = 'readOnly']/bool/@value = 'true'">
|
||||||
|
<xsl:text> </xsl:text>
|
||||||
|
<emphasis>(read only)</emphasis>
|
||||||
|
</xsl:if>
|
||||||
</para>
|
</para>
|
||||||
</xsl:if>
|
</xsl:if>
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ with lib;
|
||||||
};
|
};
|
||||||
|
|
||||||
system.nixosRelease = mkOption {
|
system.nixosRelease = mkOption {
|
||||||
internal = true;
|
readOnly = true;
|
||||||
type = types.str;
|
type = types.str;
|
||||||
default = readFile "${toString pkgs.path}/.version";
|
default = readFile "${toString pkgs.path}/.version";
|
||||||
description = "NixOS release.";
|
description = "NixOS release.";
|
||||||
|
@ -48,7 +48,7 @@ with lib;
|
||||||
};
|
};
|
||||||
|
|
||||||
system.nixosCodeName = mkOption {
|
system.nixosCodeName = mkOption {
|
||||||
internal = true;
|
readOnly = true;
|
||||||
type = types.str;
|
type = types.str;
|
||||||
description = "NixOS release code name.";
|
description = "NixOS release code name.";
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue