Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)

Add read-only options

These are options that can have only one definition, regardless of
priority.

+16 -5
+8 -3
lib/modules.nix
··· 261 evalOptionValue = loc: opt: defs: 262 let 263 # Add in the default value for this option, if any. 264 - defs' = (optional (opt ? default) 265 - { file = head opt.declarations; value = mkOptionDefault opt.default; }) ++ defs; 266 267 # Handle properties, check types, and merge everything together. 268 - res = mergeDefinitions loc opt.type defs'; 269 270 # Check whether the option is defined, and apply the ‘apply’ 271 # function to the merged value. This allows options to yield a
··· 261 evalOptionValue = loc: opt: defs: 262 let 263 # Add in the default value for this option, if any. 264 + defs' = 265 + (optional (opt ? default) 266 + { file = head opt.declarations; value = mkOptionDefault opt.default; }) ++ defs; 267 268 # Handle properties, check types, and merge everything together. 269 + res = 270 + if opt.readOnly or false && length defs' > 1 then 271 + throw "The option `${showOption loc}' is read-only, but it's set multiple times." 272 + else 273 + mergeDefinitions loc opt.type defs'; 274 275 # Check whether the option is defined, and apply the ‘apply’ 276 # function to the merged value. This allows options to yield a
+2
lib/options.nix
··· 19 , apply ? null # Function that converts the option value to something else. 20 , internal ? null # Whether the option is for NixOS developers only. 21 , visible ? null # Whether the option shows up in the manual. 22 , options ? null # Obsolete, used by types.optionSet. 23 } @ attrs: 24 attrs // { _type = "option"; }; ··· 90 declarations = filter (x: x != unknownModule) opt.declarations; 91 internal = opt.internal or false; 92 visible = opt.visible or true; 93 type = opt.type.name or null; 94 } 95 // (if opt ? example then { example = scrubOptionValue opt.example; } else {})
··· 19 , apply ? null # Function that converts the option value to something else. 20 , internal ? null # Whether the option is for NixOS developers only. 21 , visible ? null # Whether the option shows up in the manual. 22 + , readOnly ? null # Whether the option can be set only once 23 , options ? null # Obsolete, used by types.optionSet. 24 } @ attrs: 25 attrs // { _type = "option"; }; ··· 91 declarations = filter (x: x != unknownModule) opt.declarations; 92 internal = opt.internal or false; 93 visible = opt.visible or true; 94 + readOnly = opt.readOnly or false; 95 type = opt.type.name or null; 96 } 97 // (if opt ? example then { example = scrubOptionValue opt.example; } else {})
+4
nixos/doc/manual/options-to-docbook.xsl
··· 39 <emphasis>Type:</emphasis> 40 <xsl:text> </xsl:text> 41 <xsl:apply-templates select="attr[@name = 'type']" mode="top" /> 42 </para> 43 </xsl:if> 44
··· 39 <emphasis>Type:</emphasis> 40 <xsl:text> </xsl:text> 41 <xsl:apply-templates select="attr[@name = 'type']" mode="top" /> 42 + <xsl:if test="attr[@name = 'readOnly']/bool/@value = 'true'"> 43 + <xsl:text> </xsl:text> 44 + <emphasis>(read only)</emphasis> 45 + </xsl:if> 46 </para> 47 </xsl:if> 48
+2 -2
nixos/modules/misc/version.nix
··· 29 }; 30 31 system.nixosRelease = mkOption { 32 - internal = true; 33 type = types.str; 34 default = readFile "${toString pkgs.path}/.version"; 35 description = "NixOS release."; ··· 48 }; 49 50 system.nixosCodeName = mkOption { 51 - internal = true; 52 type = types.str; 53 description = "NixOS release code name."; 54 };
··· 29 }; 30 31 system.nixosRelease = mkOption { 32 + readOnly = true; 33 type = types.str; 34 default = readFile "${toString pkgs.path}/.version"; 35 description = "NixOS release."; ··· 48 }; 49 50 system.nixosCodeName = mkOption { 51 + readOnly = true; 52 type = types.str; 53 description = "NixOS release code name."; 54 };