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