git.iko.soy/typeable/nixpkgs
on master help sign in
Revert "Add the tool "nixos-typecheck" that can check an option declaration to:"

This reverts commit cad8957eabcbf73062226d28366fd446c15c8737. It breaks NixOps, but more importantly, such major changes to the module system really need to be reviewed.

commitf3d94cfc23a2787772a369e2ca9e0cd94e72b8b3 authorEelco Dolstra <eelco.dolstra@logicblox.com> dateTue 1 Mar 2016, 20:47 (11 years ago) parentbf4cafd
24 files changed+124−700
lib/modules.nix+17−82 lib/options.nix+21−124 lib/types.nix+48−169 nixos/default.nix−2 nixos/doc/manual/default.nix+2−4 nixos/doc/manual/development/option-declarations.xml+2−104 nixos/lib/eval-config.nix+3−12 nixos/lib/typechecker.nix−91 nixos/modules/config/i18n.nix−1 nixos/modules/config/sysctl.nix−1 nixos/modules/installer/tools/nixos-option.sh+2−2 nixos/modules/installer/tools/nixos-typecheck.sh−52 nixos/modules/installer/tools/tools.nix+1−7 nixos/modules/misc/meta.nix−1 nixos/modules/misc/nixpkgs.nix+23−26 nixos/modules/module-list.nix−1 nixos/modules/services/misc/gitlab.nix−3 nixos/modules/services/misc/ihaskell.nix−4 nixos/modules/services/misc/nixos-manual.nix+1−4 nixos/modules/services/web-servers/apache-httpd/default.nix+2−1 nixos/modules/services/x11/window-managers/xmonad.nix−3 nixos/modules/system/boot/kernel.nix−1 nixos/modules/system/boot/systemd-unit-options.nix+2−3 nixos/release.nix−2
lib/modules.nix+17−82
@@ -23,6 +23,8 @@ rec {
2323 specialArgs ? {}
2424 , # This would be remove in the future, Prefer _module.args option instead.
2525 args ? {}
26+ , # This would be remove in the future, Prefer _module.check option instead.
27+ check ? true
2628 }:
2729 let
2830 # This internal module declare internal options under the `_module'
@@ -43,22 +45,9 @@ rec {
4345 _module.check = mkOption {
4446 type = types.bool;
4547 internal = true;
46− default = true;
48+ default = check;
4749 description = "Whether to check whether all option definitions have matching declarations.";
4850 };
49−
50− _module.typeInference = mkOption {
51− type = types.nullOr types.str;
52− internal = true;
53− default = null; # TODO: Move away from 'null' after enough testing.
54− description = ''
55− Mode of type inferencing. Possible values are:
56− null = Disable type inferencing completely. Use 'types.unspecified' for every option without type definition.
57− "silent" = Try to infer type of option without type definition, but do not print anything.
58− "printUnspecified" = Try to infer type of option without type definition and print options for which no full type could be inferred.
59− "printAll" = Try to infer type of option without type definition and print all options without type definition.
60− '';
61− };
6251 };
6352
6453 config = {
@@ -71,7 +60,7 @@ rec {
7160 # Note: the list of modules is reversed to maintain backward
7261 # compatibility with the old module system. Not sure if this is
7362 # the most sensible policy.
74− options = mergeModules (config._module) prefix (reverseList closed);
63+ options = mergeModules prefix (reverseList closed);
7564
7665 # Traverse options and extract the option values into the final
7766 # config set. At the same time, check whether all option
@@ -181,11 +170,11 @@ rec {
181170 At the same time, for each option declaration, it will merge the
182171 corresponding option definitions in all machines, returning them
183172 in the ‘value’ attribute of each option. */
184− mergeModules = _module: prefix: modules:
185− mergeModules' _module prefix modules
173+ mergeModules = prefix: modules:
174+ mergeModules' prefix modules
186175 (concatMap (m: map (config: { inherit (m) file; inherit config; }) (pushDownProperties m.config)) modules);
187176
188− mergeModules' = _module: prefix: options: configs:
177+ mergeModules' = prefix: options: configs:
189178 listToAttrs (map (name: {
190179 # We're descending into attribute ‘name’.
191180 inherit name;
@@ -211,8 +200,8 @@ rec {
211200 (filter (m: m.config ? ${name}) configs);
212201 in
213202 if nrOptions == length decls then
214− let opt = fixupOptionType _module.typeInference loc (mergeOptionDecls loc decls);
215− in evalOptionValue _module loc opt defns'
203+ let opt = fixupOptionType loc (mergeOptionDecls loc decls);
204+ in evalOptionValue loc opt defns'
216205 else if nrOptions != 0 then
217206 let
218207 firstOption = findFirst (m: isOption m.options) "" decls;
@@ -220,7 +209,7 @@ rec {
220209 in
221210 throw "The option `${showOption loc}' in `${firstOption.file}' is a prefix of options in `${firstNonOption.file}'."
222211 else
223− mergeModules' _module loc decls defns;
212+ mergeModules' loc decls defns;
224213 }) (concatMap (m: attrNames m.options) options))
225214 // { _definedNames = map (m: { inherit (m) file; names = attrNames m.config; }) configs; };
226215
@@ -269,7 +258,7 @@ rec {
269258
270259 /* Merge all the definitions of an option to produce the final
271260 config value. */
272− evalOptionValue = _module: loc: opt: defs:
261+ evalOptionValue = loc: opt: defs:
273262 let
274263 # Add in the default value for this option, if any.
275264 defs' =
@@ -281,7 +270,7 @@ rec {
281270 if opt.readOnly or false && length defs' > 1 then
282271 throw "The option `${showOption loc}' is read-only, but it's set multiple times."
283272 else
284− mergeDefinitions _module loc opt.type defs';
273+ mergeDefinitions loc opt.type defs';
285274
286275 # Check whether the option is defined, and apply the ‘apply’
287276 # function to the merged value. This allows options to yield a
@@ -302,7 +291,7 @@ rec {
302291 };
303292
304293 # Merge definitions of a value of a given type.
305− mergeDefinitions = _module: loc: type: defs: rec {
294+ mergeDefinitions = loc: type: defs: rec {
306295 defsFinal =
307296 let
308297 # Process mkMerge and mkIf properties.
@@ -325,7 +314,7 @@ rec {
325314 mergedValue = foldl' (res: def:
326315 if type.check def.value then res
327316 else throw "The option value `${showOption loc}' in `${def.file}' is not a ${type.name}.")
328− (type.merge _module loc defsFinal) defsFinal;
317+ (type.merge loc defsFinal) defsFinal;
329318
330319 isDefined = defsFinal != [];
331320
@@ -423,7 +412,7 @@ rec {
423412 /* Hack for backward compatibility: convert options of type
424413 optionSet to options of type submodule. FIXME: remove
425414 eventually. */
426− fixupOptionType = typeInference: loc: opt:
415+ fixupOptionType = loc: opt:
427416 let
428417 options = opt.options or
429418 (throw "Option `${showOption loc'}' has type optionSet but has no option attribute, in ${showFiles opt.declarations}.");
@@ -435,66 +424,12 @@ rec {
435424 else if tp.name == "list of option sets" then types.listOf (types.submodule options)
436425 else if tp.name == "null or option set" then types.nullOr (types.submodule options)
437426 else tp;
438−
439427 in
440428 if opt.type.getSubModules or null == null
441− then opt // { type = f (opt.type or (inferType typeInference loc opt)); }
429+ then opt // { type = f (opt.type or types.unspecified); }
442430 else opt // { type = opt.type.substSubModules opt.options; options = []; };
443431
444432
445− /* Function that tries to infer the type of an option from the default value of the option. */
446− inferType = mode: loc: opt:
447− let
448− doc = x: elemAt x 0;
449− type = x: elemAt x 1;
450− containsUnspecified = x: elemAt x 2;
451− inferType' = def:
452− if isDerivation def then [ "package" types.package false ]
453− else if isBool def then [ "bool" types.bool false ]
454− else if builtins.isString def then [ "str" types.str false ]
455− else if isInt def then [ "int" types.int false ]
456− else if isFunction def then [ "functionTo unspecified" (types.functionTo types.unspecified) true ]
457− else if isList def then
458− let nestedType = if (length def > 0) && (all (x: (type (inferType' x)) == (type (inferType' (head def)))) def)
459− then inferType' (head def)
460− else [ "unspecified" types.unspecified true ];
461− in [ "listOf ${doc nestedType}" (types.listOf (type nestedType)) (containsUnspecified nestedType) ]
462− else if isAttrs def then
463− let list = mapAttrsToList (_: v: v) (removeAttrs def ["_args"]);
464− nestedType = if (length list > 0) && (all (x: (type (inferType' x)) == (type (inferType' (head list)))) list)
465− then inferType' (head list)
466− else [ "unspecified" types.unspecified true ];
467− in [ "attrsOf ${doc nestedType}" (types.attrsOf (type nestedType)) (containsUnspecified nestedType) ]
468− else [ "unspecified" types.unspecified true ];
469−
470− inferDoc = x: ''
471− Inferring the type of "${showOption loc}" to "${doc x}".
472− Please verify the inferred type and define the type explicitely in ${showFiles opt.declarations}!
473− '';
474−
475− inferredType = printMode:
476− let inferred = inferType' opt.default;
477− in if printMode == "silent" then type inferred
478− else if printMode == "printAll" then builtins.trace (inferDoc inferred) (type inferred)
479− else if printMode == "printUnspecified" && (containsUnspecified inferred) then builtins.trace (inferDoc inferred) (type inferred)
480− else type inferred;
481−
482− noInferDoc = ''
483− Could not infer a type for "${showOption loc}", using "unspecified" instead.
484− Please define the type explicitely in ${showFiles opt.declarations}!
485− '';
486−
487− hasDefault = (opt ? default) && !(opt ? defaultText);
488− isExternalVisible = (opt.visible or true) && !(opt.internal or false);
489− in
490−
491− if isNull mode || !isExternalVisible
492− then types.unspecified
493− else if hasDefault
494− then inferredType mode /* Set to 'true' to see every type that is being inferred, not just those types that result in 'unspecified'. */
495− else if mode != "silent" then builtins.trace noInferDoc types.unspecified else types.unspecified;
496−
497−
498433 /* Properties. */
499434
500435 mkIf = condition: content:
@@ -562,7 +497,7 @@ rec {
562497
563498
564499 /* Compatibility. */
565− fixMergeModules = modules: args: evalModules { inherit args; modules = (modules ++ [{ _module.check = false; }]); };
500+ fixMergeModules = modules: args: evalModules { inherit modules args; check = false; };
566501
567502
568503 /* Return a module that causes a warning to be shown if the
lib/options.nix+21−124
@@ -6,7 +6,6 @@ with import ./trivial.nix;
66with import ./lists.nix;
77with import ./attrsets.nix;
88with import ./strings.nix;
9−with {inherit (import ./types.nix) types; };
109
1110rec {
1211
@@ -43,17 +42,16 @@ rec {
4342 description = "Sink for option definitions.";
4443 type = mkOptionType {
4544 name = "sink";
46− typerep = "(sink)";
4745 check = x: true;
48− merge = config: loc: defs: false;
46+ merge = loc: defs: false;
4947 };
5048 apply = x: throw "Option value is not readable because the option is not declared.";
5149 } // attrs);
5250
53− mergeDefaultOption = config: loc: defs:
51+ mergeDefaultOption = loc: defs:
5452 let list = getValues defs; in
5553 if length list == 1 then head list
56− else if all isFunction list then x: mergeDefaultOption config loc (map (f: f x) list)
54+ else if all isFunction list then x: mergeDefaultOption loc (map (f: f x) list)
5755 else if all isList list then concatLists list
5856 else if all isAttrs list then foldl' lib.mergeAttrs {} list
5957 else if all isBool list then foldl' lib.or false list
@@ -61,14 +59,14 @@ rec {
6159 else if all isInt list && all (x: x == head list) list then head list
6260 else throw "Cannot merge definitions of `${showOption loc}' given in ${showFiles (getFiles defs)}.";
6361
64− mergeOneOption = config: loc: defs:
62+ mergeOneOption = loc: defs:
6563 if defs == [] then abort "This case should never happen."
6664 else if length defs != 1 then
6765 throw "The unique option `${showOption loc}' is defined multiple times, in ${showFiles (getFiles defs)}."
6866 else (head defs).value;
6967
7068 /* "Merge" option definitions by checking that they all have the same value. */
71− mergeEqualOption = config: loc: defs:
69+ mergeEqualOption = loc: defs:
7270 if defs == [] then abort "This case should never happen."
7371 else foldl' (val: def:
7472 if def.value != val then
@@ -79,154 +77,53 @@ rec {
7977 getValues = map (x: x.value);
8078 getFiles = map (x: x.file);
8179
80+
8281 # Generate documentation template from the list of option declaration like
8382 # the set generated with filterOptionSets.
8483 optionAttrSetToDocList = optionAttrSetToDocList' [];
8584
86− optionAttrSetToDocList' = prefix: internalModuleConfig: options:
85+ optionAttrSetToDocList' = prefix: options:
8786 concatMap (opt:
8887 let
89− decls = filter (x: x != unknownModule) opt.declarations;
9088 docOption = rec {
9189 name = showOption opt.loc;
9290 description = opt.description or (throw "Option `${name}' has no description.");
93− declarations = decls;
91+ declarations = filter (x: x != unknownModule) opt.declarations;
9492 internal = opt.internal or false;
9593 visible = opt.visible or true;
9694 readOnly = opt.readOnly or false;
9795 type = opt.type.name or null;
9896 }
99− // (if opt ? example then { example = detectDerivation decls opt.example; } else {})
100− // (if opt ? default then { default = detectDerivation decls opt.default; } else {})
97+ // (if opt ? example then { example = scrubOptionValue opt.example; } else {})
98+ // (if opt ? default then { default = scrubOptionValue opt.default; } else {})
10199 // (if opt ? defaultText then { default = opt.defaultText; } else {});
102100
103101 subOptions =
104− let ss = opt.type.getSubOptionsPrefixed opt.loc;
105− in if ss != {} then optionAttrSetToDocList' opt.loc internalModuleConfig (ss internalModuleConfig) else [];
102+ let ss = opt.type.getSubOptions opt.loc;
103+ in if ss != {} then optionAttrSetToDocList' opt.loc ss else [];
106104 in
107105 [ docOption ] ++ subOptions) (collect isOption options);
108106
109− # TODO: Use "extractOptionAttrSet" instead of "optionAttrSetToDocList'" to reduce the code size.
110− # It should be a drop-in-replacement. But first, examine the impact on the evaluation time.
111− # optionAttrSetToDocList = extractOptionAttrSet true [];
112−
113− # Generate a machine readable specification of the list of option declarations.
114− optionAttrSetToParseableSpecifications = extractOptionAttrSet false [];
115−
116− extractOptionAttrSet = toDoc: prefix: internalModuleConfig: options:
117− concatMap (opt:
118− let
119− optionName = showOption opt.loc;
120−
121− # Check if a type contains derivations, that is check if a type nests
122− # a 'package', 'packageSet' or 'nixpkgsConfig' type.
123− hasDerivation = any (t: elem t opt.type.nestedTypes) ((map (x: x.typerep) (with types; [package packageSet])) ++ ["(nixpkgsConfig)"]);
124−
125− # Check if type is 'path' which can potentially contain a derivation.
126− maybeHiddenDerivation = any (t: elem t opt.type.nestedTypes) (map (x: x.typerep) (with types; [path]));
127−
128− isDefaultValue = elem opt.default opt.type.defaultValues;
129−
130− /* Enforce that the example attribute is wrapped with 'literalExample'
131− for every type that contains derivations. */
132− example =
133− if opt ? example
134− then (if hasDerivation
135− then (if isLiteralExample opt.example
136− then { example = detectDerivation decls opt.example; }
137− else throw "The attribute ${optionName}.example must be wrapped with 'literalExample' in ${concatStringsSep " and " decls}!")
138− else { example = detectDerivation decls opt.example; })
139− else {};
140−
141− /* Enforce that the 'defaultText' attribute is defined for every option
142− that has a 'default' attribute that contains derivations. */
143− default =
144− if opt ? default
145− then (if hasDerivation
146− then (if isDefaultValue
147− then { default = opt.default; }
148− else (if opt ? defaultText
149− then { default = literalExample (detectDerivation decls opt.defaultText); }
150− else throw "The option ${optionName} requires a 'defaultText' attribute in ${concatStringsSep " and " decls}!"))
151− else (if opt ? defaultText
152− then (if maybeHiddenDerivation
153− then (if (let eval = builtins.tryEval (findDerivation opt.default); in eval.success && !eval.value)
154− then builtins.trace
155− "The attribute ${optionName}.defaultText might not be necessary in ${concatStringsSep " and " decls}!"
156− { default = literalExample (detectDerivation decls opt.defaultText); }
157− else { default = literalExample (detectDerivation decls opt.defaultText); })
158− else builtins.trace
159− "The attribute ${optionName}.defaultText is not used and can be removed in ${concatStringsSep " and " decls}!"
160− { default = detectDerivation decls opt.default; })
161− else { default = detectDerivation decls opt.default; }))
162− else {};
163−
164− decls = filter (x: x != unknownModule) opt.declarations;
165−
166− docOption = {
167− name = optionName;
168− description = opt.description or (throw "Option `${optionName}' has no description.");
169− declarations = decls;
170− internal = opt.internal or false;
171− visible = opt.visible or true;
172− readOnly = opt.readOnly or false;
173− } // example // default // subOptions // typeKeys;
174−
175− typeKeys = if toDoc then { type = opt.type.name or null; } else { type = opt.type.typerep; keys = opt.loc; };
176107
177− subOptions =
178− if toDoc
179− then {}
180− else let ss = opt.type.getSubOptions;
181− in if ss != {} then { suboptions = (extractOptionAttrSet false [] internalModuleConfig (ss internalModuleConfig)); } else {};
182−
183− subOptionsDoc =
184− if toDoc
185− then let ss = opt.type.getSubOptionsPrefixed opt.loc;
186− in if ss != {} then extractOptionAttrSet true opt.loc internalModuleConfig (ss internalModuleConfig) else []
187− else [];
188− in
189− [ docOption ] ++ subOptionsDoc )
190− (filter (opt: (opt.visible or true) && !(opt.internal or false)) (collect isOption options));
191−
192−
193− /* This function recursively checks for derivations within an
194− an expression, and throws an error if a derivation or a
195− store path is found. The function is used to ensure that no
196− derivation leaks from the 'default' or 'example' attributes
197− of an option.
198− This makes the generation of `options.xml' much more efficient:
199− the XML representation of derivations is very large (on the
200− order of megabytes) and is not actually used by the manual
201− generator. */
202− detectDerivation = decl: x:
108+ /* This function recursively removes all derivation attributes from
109+ `x' except for the `name' attribute. This is to make the
110+ generation of `options.xml' much more efficient: the XML
111+ representation of derivations is very large (on the order of
112+ megabytes) and is not actually used by the manual generator. */
113+ scrubOptionValue = x:
203114 if isDerivation x then
204− throw "Found unexpected derivation in '${x.name}' in '${concatStringsSep " and " decl}'!"
205− else if isString x && isStorePath x then
206− throw "Found unexpected store path in '${x.name}' in '${concatStringsSep " and " decl}'!"
207− else if isList x then map (detectDerivation decl) x
208− else if isAttrs x then mapAttrs (n: v: (detectDerivation decl) v) (removeAttrs x ["_args"])
115+ { type = "derivation"; drvPath = x.name; outPath = x.name; name = x.name; }
116+ else if isList x then map scrubOptionValue x
117+ else if isAttrs x then mapAttrs (n: v: scrubOptionValue v) (removeAttrs x ["_args"])
209118 else x;
210119
211− /* Same as detectDerivation, but returns a boolean instead of
212− throwing an exception. */
213− findDerivation = x:
214− if (isString x && isStorePath x) || isDerivation x then true
215− else if isList x then any findDerivation x
216− else if isAttrs x then any findDerivation (mapAttrsToList (_: v: v) (removeAttrs x ["_args"]))
217− else false;
218−
219−
220120
221121 /* For use in the ‘example’ option attribute. It causes the given
222122 text to be included verbatim in documentation. This is necessary
223123 for example values that are not simple values, e.g.,
224124 functions. */
225− # TODO: A more general name would probably be "literalNix".
226125 literalExample = text: { _type = "literalExample"; inherit text; };
227126
228− isLiteralExample = x: isAttrs x && hasAttr "_type" x && x._type == "literalExample";
229−
230127
231128 /* Helper functions. */
232129 showOption = concatStringsSep ".";
lib/types.nix+48−169
@@ -1,8 +1,6 @@
11# Definitions related to run-time type checking. Used in particular
22# to type-check NixOS configurations.
33
4−let lib = import ./default.nix; in
5−
64with import ./lists.nix;
75with import ./attrsets.nix;
86with import ./options.nix;
@@ -23,8 +21,6 @@ rec {
2321 mkOptionType =
2422 { # Human-readable representation of the type.
2523 name
26− , # Parseable representation of the type.
27− typerep
2824 , # Function applied to each definition that should return true if
2925 # its type-correct, false otherwise.
3026 check ? (x: true)
@@ -35,59 +31,40 @@ rec {
3531 # definition values and locations (e.g. [ { file = "/foo.nix";
3632 # value = 1; } { file = "/bar.nix"; value = 2 } ]).
3733 merge ? mergeDefaultOption
38− , # Return list of sub-options.
39− getSubOptions ? {}
40− , # Same as 'getSubOptions', but with extra information about the
41− # location of the option which is used to generate documentation.
42− getSubOptionsPrefixed ? null
34+ , # Return a flat list of sub-options. Used to generate
35+ # documentation.
36+ getSubOptions ? prefix: {}
4337 , # List of modules if any, or null if none.
4438 getSubModules ? null
4539 , # Function for building the same option type with a different list of
4640 # modules.
4741 substSubModules ? m: null
48− , # List of type representations (typerep) of all the elementary types
49− # that are nested within the type. For an elementary type the list is
50− # a singleton of the typerep of itself.
51− # NOTE: Must be specified for every container type!
52− nestedTypes ? null
53− , # List of all default values, and an empty list if no default value exists.
54− defaultValues ? []
5542 }:
5643 { _type = "option-type";
57− inherit name typerep check merge getSubOptions getSubModules substSubModules defaultValues;
58− nestedTypes = if (isNull nestedTypes) then (singleton typerep) else nestedTypes;
59− getSubOptionsPrefixed = if (isNull getSubOptionsPrefixed) then (prefix: getSubOptions) else getSubOptionsPrefixed;
44+ inherit name check merge getSubOptions getSubModules substSubModules;
6045 };
6146
6247
6348 types = rec {
6449
65− #
66− # Elementary types
67− #
68−
6950 unspecified = mkOptionType {
7051 name = "unspecified";
71− typerep = "(unspecified)";
7252 };
7353
7454 bool = mkOptionType {
7555 name = "boolean";
76− typerep = "(boolean)";
7756 check = isBool;
7857 merge = mergeEqualOption;
7958 };
8059
8160 int = mkOptionType {
8261 name = "integer";
83− typerep = "(integer)";
8462 check = isInt;
8563 merge = mergeOneOption;
8664 };
8765
8866 str = mkOptionType {
8967 name = "string";
90− typerep = "(string)";
9168 check = isString;
9269 merge = mergeOneOption;
9370 };
@@ -95,111 +72,73 @@ rec {
9572 # Merge multiple definitions by concatenating them (with the given
9673 # separator between the values).
9774 separatedString = sep: mkOptionType {
98− name = "string" + (optionalString (sep != "") " separated by ${sep}");
99− typerep = "(separatedString(${escape ["(" ")"] sep}))";
75+ name = "string";
10076 check = isString;
101− merge = _module: loc: defs: concatStringsSep sep (getValues defs);
77+ merge = loc: defs: concatStringsSep sep (getValues defs);
10278 };
10379
104− lines = separatedString "\n" // { typerep = "(lines)"; };
105− commas = separatedString "," // { typerep = "(commas)"; };
106− envVar = separatedString ":" // { typerep = "(envVar)"; };
80+ lines = separatedString "\n";
81+ commas = separatedString ",";
82+ envVar = separatedString ":";
10783
10884 # Deprecated; should not be used because it quietly concatenates
10985 # strings, which is usually not what you want.
110− string = separatedString "" // { typerep = "(string)"; };
86+ string = separatedString "";
11187
11288 attrs = mkOptionType {
11389 name = "attribute set";
114− typerep = "(attrs)";
11590 check = isAttrs;
116− merge = _module: loc: foldl' (res: def: mergeAttrs res def.value) {};
91+ merge = loc: foldl' (res: def: mergeAttrs res def.value) {};
11792 };
11893
11994 # derivation is a reserved keyword.
12095 package = mkOptionType {
12196 name = "package";
122− typerep = "(package)";
12397 check = x: isDerivation x || isStorePath x;
124− merge = _module: loc: defs:
125− let res = mergeOneOption _module loc defs;
98+ merge = loc: defs:
99+ let res = mergeOneOption loc defs;
126100 in if isDerivation res then res else toDerivation res;
127101 };
128102
129− # The correct type of packageSet would be:
130− # packageSet = attrsOf (either package packageSet)
131− # (Not sure if nix would allow to define a recursive type.)
132− # However, currently it is not possible to check that a packageSet actually
133− # contains packages (that is derivations). The check 'isDerivation' is too
134− # eager for the current implementation of the assertion mechanism and of the
135− # licenses control mechanism. That means it is not generally possible to go
136− # into the attribute set of packages to check that every attribute would
137− # evaluate to a derivation if the package would actually be evaluated. Maybe
138− # that restriction can be lifted in the future, but for now the content of
139− # the packageSet is not checked.
140− # TODO: The 'merge' function is copied from 'mergeDefaultOption' to keep
141− # backwards compatibility with the 'unspecified' type that was used for
142− # package sets previously. Maybe review if the merge function has to change.
143− packageSet = mkOptionType {
144− name = "derivation set";
145− typerep = "(packageSet)";
146− check = isAttrs;
147− merge = _module: loc: defs: foldl' mergeAttrs {} (map (x: x.value) defs);
148− };
149−
150103 path = mkOptionType {
151104 name = "path";
152− typerep = "(path)";
153105 # Hacky: there is no ‘isPath’ primop.
154106 check = x: builtins.substring 0 1 (toString x) == "/";
155107 merge = mergeOneOption;
156108 };
157109
158−
159− #
160− # Container types
161− #
162−
163110 # drop this in the future:
164111 list = builtins.trace "`types.list' is deprecated; use `types.listOf' instead" types.listOf;
165112
166113 listOf = elemType: mkOptionType {
167114 name = "list of ${elemType.name}s";
168− typerep = "(listOf${elemType.typerep})";
169115 check = isList;
170− merge = _module: loc: defs:
116+ merge = loc: defs:
171117 map (x: x.value) (filter (x: x ? value) (concatLists (imap (n: def: imap (m: def':
172− (mergeDefinitions _module
118+ (mergeDefinitions
173119 (loc ++ ["[definition ${toString n}-entry ${toString m}]"])
174120 elemType
175121 [{ inherit (def) file; value = def'; }]
176122 ).optionalValue
177123 ) def.value) defs)));
178− getSubOptions = elemType.getSubOptions;
179− getSubOptionsPrefixed = prefix: elemType.getSubOptionsPrefixed (prefix ++ ["*"]);
124+ getSubOptions = prefix: elemType.getSubOptions (prefix ++ ["*"]);
180125 getSubModules = elemType.getSubModules;
181126 substSubModules = m: listOf (elemType.substSubModules m);
182− nestedTypes = elemType.nestedTypes;
183− defaultValues = [[]];
184127 };
185128
186129 attrsOf = elemType: mkOptionType {
187130 name = "attribute set of ${elemType.name}s";
188− typerep = "(attrsOf${elemType.typerep})";
189131 check = isAttrs;
190− merge = _module: loc: defs:
132+ merge = loc: defs:
191133 mapAttrs (n: v: v.value) (filterAttrs (n: v: v ? value) (zipAttrsWith (name: defs:
192− (mergeDefinitions _module (loc ++ [name]) elemType defs).optionalValue
134+ (mergeDefinitions (loc ++ [name]) elemType defs).optionalValue
193135 )
194136 # Push down position info.
195137 (map (def: listToAttrs (mapAttrsToList (n: def':
196138 { name = n; value = { inherit (def) file; value = def'; }; }) def.value)) defs)));
197− getSubOptions = elemType.getSubOptions;
198− getSubOptionsPrefixed = prefix: elemType.getSubOptionsPrefixed (prefix ++ ["<name>"]);
139+ getSubOptions = prefix: elemType.getSubOptions (prefix ++ ["<name>"]);
199140 getSubModules = elemType.getSubModules;
200141 substSubModules = m: attrsOf (elemType.substSubModules m);
201− nestedTypes = elemType.nestedTypes;
202− defaultValues = [{}];
203142 };
204143
205144 # List or attribute set of ...
@@ -220,23 +159,18 @@ rec {
220159 attrOnly = attrsOf elemType;
221160 in mkOptionType {
222161 name = "list or attribute set of ${elemType.name}s";
223− typerep = "(loaOf${elemType.typerep})";
224162 check = x: isList x || isAttrs x;
225− merge = _module: loc: defs: attrOnly.merge _module loc (imap convertIfList defs);
226− getSubOptions = elemType.getSubOptions;
227− getSubOptionsPrefixed = prefix: elemType.getSubOptionsPrefixed (prefix ++ ["<name?>"]);
163+ merge = loc: defs: attrOnly.merge loc (imap convertIfList defs);
164+ getSubOptions = prefix: elemType.getSubOptions (prefix ++ ["<name?>"]);
228165 getSubModules = elemType.getSubModules;
229166 substSubModules = m: loaOf (elemType.substSubModules m);
230− nestedTypes = elemType.nestedTypes;
231− defaultValues = [{} []];
232167 };
233168
234169 # List or element of ...
235170 loeOf = elemType: mkOptionType {
236171 name = "element or list of ${elemType.name}s";
237− typerep = "(loeOf${elemType.typerep})";
238172 check = x: isList x || elemType.check x;
239− merge = _module: loc: defs:
173+ merge = loc: defs:
240174 let
241175 defs' = filterOverrides defs;
242176 res = (head defs').value;
@@ -247,136 +181,81 @@ rec {
247181 else if !isString res then
248182 throw "The option `${showOption loc}' does not have a string value, in ${showFiles (getFiles defs)}."
249183 else res;
250− nestedTypes = elemType.nestedTypes;
251− defaultValues = [[]] ++ elemType.defaultValues;
252184 };
253185
254186 uniq = elemType: mkOptionType {
255− inherit (elemType) check;
256− name = "unique ${elemType.name}";
257− typerep = "(uniq${elemType.typerep})";
187+ inherit (elemType) name check;
258188 merge = mergeOneOption;
259189 getSubOptions = elemType.getSubOptions;
260− getSubOptionsPrefixed = prefix: elemType.getSubOptionsPrefixed prefix;
261190 getSubModules = elemType.getSubModules;
262191 substSubModules = m: uniq (elemType.substSubModules m);
263− nestedTypes = elemType.nestedTypes;
264− defaultValues = elemType.defaultValues;
265192 };
266193
267194 nullOr = elemType: mkOptionType {
268195 name = "null or ${elemType.name}";
269− typerep = "(nullOr${elemType.typerep})";
270196 check = x: x == null || elemType.check x;
271− merge = _module: loc: defs:
197+ merge = loc: defs:
272198 let nrNulls = count (def: def.value == null) defs; in
273199 if nrNulls == length defs then null
274200 else if nrNulls != 0 then
275201 throw "The option `${showOption loc}' is defined both null and not null, in ${showFiles (getFiles defs)}."
276− else elemType.merge _module loc defs;
202+ else elemType.merge loc defs;
277203 getSubOptions = elemType.getSubOptions;
278− getSubOptionsPrefixed = prefix: elemType.getSubOptionsPrefixed prefix;
279204 getSubModules = elemType.getSubModules;
280205 substSubModules = m: nullOr (elemType.substSubModules m);
281− nestedTypes = elemType.nestedTypes;
282− defaultValues = [null] ++ elemType.defaultValues;
283− };
284−
285− enum = values:
286− let
287− show = v:
288− if builtins.isString v then ''"${v}"''
289− else if builtins.isInt v then builtins.toString v
290− else ''<${builtins.typeOf v}>'';
291− in
292− mkOptionType {
293− name = "one of ${concatMapStringsSep ", " show values}";
294− typerep = "(enum${concatMapStrings (x: "(${escape ["(" ")"] (builtins.toString x)})") values})";
295− check = flip elem values;
296− merge = mergeOneOption;
297− nestedTypes = [];
298− };
299−
300− either = t1: t2: mkOptionType {
301− name = "${t1.name} or ${t2.name}";
302− typerep = "(either${t1.typerep}${t2.typerep})";
303− check = x: t1.check x || t2.check x;
304− merge = mergeOneOption;
305− nestedTypes = t1.nestedTypes ++ t2.nestedTypes;
306− defaultValues = t1.defaultValues ++ t2.defaultValues;
307206 };
308207
309−
310− #
311− # Complex types
312− #
313−
314208 submodule = opts:
315209 let
316210 opts' = toList opts;
317211 inherit (import ./modules.nix) evalModules;
318− filterVisible = filter (opt: (if opt ? visible then opt.visible else true) && (if opt ? internal then !opt.internal else true));
319212 in
320213 mkOptionType rec {
321214 name = "submodule";
322− typerep = "(submodule)";
323215 check = x: isAttrs x || isFunction x;
324− merge = _module: loc: defs:
216+ merge = loc: defs:
325217 let
326− internalModule = [ { inherit _module; } { _module.args.name = lib.mkForce (last loc); } ];
327218 coerce = def: if isFunction def then def else { config = def; };
328− modules = opts' ++ internalModule ++ map (def: { _file = def.file; imports = [(coerce def.value)]; }) defs;
219+ modules = opts' ++ map (def: { _file = def.file; imports = [(coerce def.value)]; }) defs;
329220 in (evalModules {
330221 inherit modules;
222+ args.name = last loc;
331223 prefix = loc;
332224 }).config;
333− getSubOptions = getSubOptionsPrefixed [];
334− getSubOptionsPrefixed = prefix: _module:
335− let
225+ getSubOptions = prefix: (evalModules
226+ { modules = opts'; inherit prefix;
336227 # FIXME: hack to get shit to evaluate.
337− internalModule = [ { inherit _module; } { _module.args.name = lib.mkForce ""; } ];
338− in (evalModules {
339− modules = opts' ++ internalModule;
340− inherit prefix;
341− }).options;
228+ args = { name = ""; }; }).options;
342229 getSubModules = opts';
343230 substSubModules = m: submodule m;
344− nestedTypes = concatMap (opt: opt.type.nestedTypes) (collect (lib.isType "option") (getSubOptions {}));
345− defaultValues = [{}];
346231 };
347232
233+ enum = values:
234+ let
235+ show = v:
236+ if builtins.isString v then ''"${v}"''
237+ else if builtins.isInt v then builtins.toString v
238+ else ''<${builtins.typeOf v}>'';
239+ in
240+ mkOptionType {
241+ name = "one of ${concatMapStringsSep ", " show values}";
242+ check = flip elem values;
243+ merge = mergeOneOption;
244+ };
348245
349−
350− #
351− # Legacy types
352− #
246+ either = t1: t2: mkOptionType {
247+ name = "${t1.name} or ${t2.name}";
248+ check = x: t1.check x || t2.check x;
249+ merge = mergeOneOption;
250+ };
353251
354252 # Obsolete alternative to configOf. It takes its option
355253 # declarations from the ‘options’ attribute of containing option
356254 # declaration.
357255 optionSet = mkOptionType {
358256 name = /* builtins.trace "types.optionSet is deprecated; use types.submodule instead" */ "option set";
359− typerep = "(optionSet)";
360257 };
361258
362−
363− # Try to remove module options of that type wherever possible.
364− # A module option taking a function can not be introspected and documented properly.
365− functionTo = resultType:
366− mkOptionType {
367− name = "function to ${resultType.name}";
368− typerep = "(function${resultType.typerep})";
369− check = builtins.isFunction;
370− merge = mergeOneOption;
371− nestedTypes = resultType.nestedTypes;
372− defaultValues = map (x: {...}:x) resultType.nestedTypes; # INFO: It seems as nix can't compare functions, yet.
373− };
374−
375−
376− #
377− # misc
378− #
379−
380259 # Augment the given type with an additional type check function.
381260 addCheck = elemType: check: elemType // { check = x: elemType.check x && check x; };
382261
nixos/default.nix−2
@@ -34,8 +34,6 @@ in
3434
3535 system = eval.config.system.build.toplevel;
3636
37− typechecker = eval.config.system.build.typechecker;
38−
3937 vm = vmConfig.system.build.vm;
4038
4139 vmWithBootLoader = vmWithBootLoaderConfig.system.build.vm;
nixos/doc/manual/default.nix+2−4
@@ -1,4 +1,4 @@
1−{ pkgs, options, internalModule, version, revision, extraSources ? [] }:
1+{ pkgs, options, version, revision, extraSources ? [] }:
22
33with pkgs;
44with pkgs.lib;
@@ -6,10 +6,8 @@ with pkgs.lib;
66let
77
88 # Remove invisible and internal options.
9− optionsList = filter (opt: opt.visible && !opt.internal) (optionAttrSetToDocList internalModule options);
9+ optionsList = filter (opt: opt.visible && !opt.internal) (optionAttrSetToDocList options);
1010
11− # INFO: Please add 'defaultText' or 'literalExample' to the option
12− # definition to avoid this substitution!
1311 # Replace functions by the string <function>
1412 substFunction = x:
1513 if builtins.isAttrs x then mapAttrs (name: substFunction) x
nixos/doc/manual/development/option-declarations.xml+2−104
@@ -8,7 +8,7 @@
88
99<para>An option declaration specifies the name, type and description
1010of a NixOS configuration option. It is illegal to define an option
11−that has not been declared in any module. A option declaration
11+that hasn’t been declared in any module. A option declaration
1212generally looks like this:
1313
1414<programlisting>
@@ -145,108 +145,6 @@ options = {
145145
146146You can also create new types using the function
147147<varname>mkOptionType</varname>. See
148−<filename>lib/types.nix</filename> in Nixpkgs for details.
149−
150−An option declaration must follow the following rules:
151−<itemizedlist mark='bullet'>
152−
153− <listitem>
154− <para>A <varname>defaultText</varname> must be defined if and only if the type of the option
155− derives from <varname>package</varname>, <varname>packageSet</varname> or <varname>nixpkgsConfig
156− </varname>, and if and only if a <varname>default</varname> attribute is defined and if and only if
157− the value of the <varname>default</varname> attribute is not the default of the type of the
158− option declaration.
159−
160− For example, a <varname>defaultText</varname> must be defined for
161−<programlisting>
162−type = types.listOf types.package;
163−default = [ pkgs.foo; ];
164−defaultText = "[ pkgs.foo; ]";
165−</programlisting>.
166−
167− But no <varname>defaultText</varname> must be defined for
168−<programlisting>
169−type = types.listOf types.package;
170−default = [];
171−</programlisting>,
172− as <varname>[]</varname> is the default of <varname>types.listOf types.package</varname>.
173− </para>
174− </listitem>
175−
176− <listitem>
177− <para>A <varname>defaultText</varname> can be defined if the type of the option derives from
178− <varname>path</varname> and if a <varname>default</varname> attribute is defined.</para>
179− </listitem>
180−
181− <listitem>
182− <para>The value of the <varname>example</varname> attribute must be wrapped with <varname>
183− literalExample</varname> if the type of the option derives from <varname>package</varname>,
184− <varname>packageSet</varname> or <varname>nixpkgsConfig</varname>.</para>
185− </listitem>
186−
187− <listitem>
188− <para>The value of <varname>defaultText</varname> and <varname>literalExample</varname> must
189− be a string which contains a valid nix expression. The nix expression has to evaluate in
190− <code>{pkgs}: <replaceable>value</replaceable></code>.
191− For example:
192− <itemizedlist>
193− <listitem>
194− <para>A <varname>defaultText</varname> could, e.g., be:
195−<programlisting>
196−type = types.package;
197−default = pkgs.foo;
198−defaultText = "pkgs.foo";
199−</programlisting>
200− But not <code>defaultText = "pkgs.foo;";</code>, as that
201− corresponds to <code>{pkgs}: pkgs.foo;</code>, which is an
202− invalid nix expression due to the ending with <varname>;</varname>.</para>
203− </listitem>
204−
205− <listitem>
206− <para>A <varname>literalExample</varname> could be used as, e.g.:
207−<programlisting>
208−type = types.path;
209−example = literalExample "\"\${pkgs.bar}/bin/bar\"";
210−</programlisting>
211− But not <code>literalExample "\${pkgs.bar}/bin/bar";</code>, as that corresponds
212− to <code>{pkgs}: ${pkgs.bar}/bin/bar</code>, which is an invalid nix expression
213− as the <varname>path</varname> is not a <varname>string</varname> anymore.</para>
214− </listitem>
215− </itemizedlist></para>
216− </listitem>
217−
218− <listitem>
219− <para>The <varname>type</varname> attribute must be defined for every option declaration.</para>
220− </listitem>
221−
222−</itemizedlist>
223−
224−NixOS ships the tool <varname>nixos-typecheck</varname> that can check an option declaration to:
225−
226−<itemizedlist mark='bullet'>
227−
228− <listitem>
229− <para>Enforce that an option declaration has a <varname>defaultText</varname> if and only if the
230− type of the option derives from <varname>package</varname>, <varname>packageSet</varname> or
231− <varname>nixpkgsConfig</varname> and if a <varname>default</varname> attribute is defined.</para>
232− </listitem>
233−
234− <listitem>
235− <para>Enforce that the value of the <varname>example</varname> attribute is wrapped with <varname>
236− literalExample</varname> if the type of the option derives from <varname>package</varname>,
237− <varname>packageSet</varname> or <varname>nixpkgsConfig</varname>.</para>
238− </listitem>
239−
240− <listitem>
241− <para>Warn if a <varname>defaultText</varname> is defined in an option declaration if the type of
242− the option does not derive from <varname>package</varname>, <varname>packageSet</varname> or
243− <varname>nixpkgsConfig</varname>.</para>
244− </listitem>
245−
246− <listitem>
247− <para>Warn if no <varname>type</varname> is defined in an option declaration.</para>
248− </listitem>
249−
250−</itemizedlist></para>
148+<filename>lib/types.nix</filename> in Nixpkgs for details.</para>
251149
252150</section>
nixos/lib/eval-config.nix+3−12
@@ -20,13 +20,8 @@
2020, # !!! See comment about args in lib/modules.nix
2121 specialArgs ? {}
2222, modules
23−, # Pass through a configuration of the internal modules declared
24− # in lib/modules.nix.
25− _module ? {}
26−, # !!! See comment about typeInference in lib/modules.nix
27− typeInference ? null
2823, # !!! See comment about check in lib/modules.nix
29− check ? null
24+ check ? true
3025, prefix ? []
3126, lib ? import ../../lib
3227}:
@@ -46,17 +41,13 @@ let
4641 };
4742 };
4843
49− internalModule = { _module = (_module
50− // (if isNull check then {} else { inherit check; })
51− // (if isNull typeInference then {} else { inherit typeInference; })); };
52−
5344in rec {
5445
5546 # Merge the option definitions in all modules, forming the full
5647 # system configuration.
5748 inherit (lib.evalModules {
58− inherit prefix;
59− modules = modules ++ extraModules ++ baseModules ++ [ pkgsModule ] ++ [ internalModule ];
49+ inherit prefix check;
50+ modules = modules ++ extraModules ++ baseModules ++ [ pkgsModule ];
6051 args = extraArgs;
6152 specialArgs = { modulesPath = ../modules; } // specialArgs;
6253 }) config options;
nixos/lib/typechecker.nixdeleted−91
@@ -1,91 +0,0 @@
1−{ config, lib, pkgs, baseModules, ... }:
2−
3−with pkgs;
4−with pkgs.lib;
5−
6−let
7−
8− optionsSpecs = inferenceMode:
9− let
10− versionModule =
11− { system.nixosVersionSuffix = config.system.nixosVersionSuffix;
12− system.nixosRevision = config.system.nixosRevision;
13− nixpkgs.system = config.nixpkgs.system;
14− };
15−
16− internalModule = { _module = config._module; } // (if isNull inferenceMode then {} else { _module.typeInference = mkForce inferenceMode; });
17−
18− eval = evalModules {
19− modules = [ versionModule ] ++ baseModules ++ [ internalModule ];
20− args = (config._module.args) // { modules = [ ]; };
21− };
22−
23− # Remove invisible and internal options.
24− optionsSpecs' = filter (opt: opt.visible && !opt.internal) (optionAttrSetToParseableSpecifications config._module eval.options);
25−
26− # INFO: Please add 'defaultText' or 'literalExample' to the option
27− # definition to avoid this exception!
28− substFunction = key: decls: x:
29− if builtins.isAttrs x then mapAttrs (name: substFunction key decls) x
30− else if builtins.isList x then map (substFunction key decls) x
31− else if builtins.isFunction x then throw "Found an unexpected <function> in ${key} declared in ${concatStringsSep " and " decls}."
32− else x;
33−
34− prefix = toString ../..;
35−
36− stripPrefix = fn:
37− if substring 0 (stringLength prefix) fn == prefix then
38− substring (stringLength prefix + 1) 1000 fn
39− else
40− fn;
41−
42− # Clean up declaration sites to not refer to the NixOS source tree.
43− cleanupOptions = x: flip map x (opt:
44− let substFunction' = y: substFunction opt.name opt.declarations y;
45− in opt
46− // { declarations = map (fn: stripPrefix fn) opt.declarations; }
47− // optionalAttrs (opt ? example) { example = substFunction' opt.example; }
48− // optionalAttrs (opt ? default) { default = substFunction' opt.default; }
49− // optionalAttrs (opt ? type) { type = substFunction' opt.type; });
50−
51− in
52− cleanupOptions optionsSpecs';
53−
54−in
55−
56−{
57−
58− system.build.typechecker = {
59−
60− # The NixOS options as machine readable specifications in JSON format.
61− specifications = stdenv.mkDerivation {
62− name = "options-specs-json";
63−
64− buildCommand = ''
65− # Export list of options in different format.
66− dst=$out/share/doc/nixos
67− mkdir -p $dst
68−
69− cp ${builtins.toFile "options.json" (builtins.unsafeDiscardStringContext (builtins.toJSON
70− (listToAttrs (map (o: { name = o.name; value = removeAttrs o ["name" "visible" "internal"]; }) (optionsSpecs null)))))
71− } $dst/options-specs.json
72−
73− mkdir -p $out/nix-support
74− echo "file json $dst/options-specs.json" >> $out/nix-support/hydra-build-products
75− ''; # */
76−
77− meta.description = "List of NixOS options specifications in JSON format";
78− };
79−
80− silent = listToAttrs (map (o: { name = o.name; value = removeAttrs o ["name" "visible" "internal"]; }) (optionsSpecs "silent"));
81− printAll = listToAttrs (map (o: { name = o.name; value = removeAttrs o ["name" "visible" "internal"]; }) (optionsSpecs "printAll"));
82− printUnspecified = listToAttrs (map (o: { name = o.name; value = removeAttrs o ["name" "visible" "internal"]; }) (optionsSpecs "printUnspecified"));
83−
84− };
85−
86−}
87−
88−
89−
90−
91−
nixos/modules/config/i18n.nix−1
@@ -64,7 +64,6 @@ in
6464 consoleKeyMap = mkOption {
6565 type = mkOptionType {
6666 name = "string or path";
67− typerep = "(stringOrPath)";
6867 check = t: (isString t || types.path.check t);
6968 };
7069
nixos/modules/config/sysctl.nix−1
@@ -6,7 +6,6 @@ let
66
77 sysctlOption = mkOptionType {
88 name = "sysctl option value";
9− typerep = "(sysctl)";
109 check = val:
1110 let
1211 checkType = x: isBool x || isString x || isInt x || isNull x;
nixos/modules/installer/tools/nixos-option.sh+2−2
@@ -115,8 +115,8 @@ let
115115 let name = head attrsNames; rest = tail attrsNames; in
116116 if isOption result.options then
117117 walkOptions rest {
118− options = result.options.type.getSubOptionsPrefix "";
119− opt = ''(\${result.opt}.type.getSubOptionsPrefix "")'';
118+ options = result.options.type.getSubOptions "";
119+ opt = ''(\${result.opt}.type.getSubOptions "")'';
120120 cfg = ''\${result.cfg}."\${name}"'';
121121 }
122122 else
nixos/modules/installer/tools/nixos-typecheck.shdeleted−52
@@ -1,52 +0,0 @@
1−#! /bin/sh
2−#! @shell@
3−
4−if [ -x "@shell@" ]; then export SHELL="@shell@"; fi;
5−
6−set -e
7−
8−showSyntax() {
9−cat >&1 << EOF
10−nixos-typecheck
11−usage:
12− nixos-typecheck [action] [args]
13−where:
14− action = silent | printAll | printUnspecified | getSpecs
15− with default action: printUnspecified
16− args = any argument supported by nix-build
17−EOF
18−}
19−
20−
21−# Parse the command line.
22−extraArgs=()
23−action=printUnspecified
24−
25−while [ "$#" -gt 0 ]; do
26− i="$1"; shift 1
27− case "$i" in
28− --help)
29− showSyntax
30− ;;
31− silent|printAll|printUnspecified|getSpecs)
32− action="$i"
33− ;;
34− *)
35− extraArgs="$extraArgs $i"
36− ;;
37− esac
38−done
39−
40−
41−if [ "$action" = silent ]; then
42− nix-build --no-out-link '<nixpkgs/nixos>' -A typechecker.silent $extraArgs
43−elif [ "$action" = printAll ]; then
44− nix-build --no-out-link '<nixpkgs/nixos>' -A typechecker.printAll $extraArgs
45−elif [ "$action" = printUnspecified ]; then
46− nix-build --no-out-link '<nixpkgs/nixos>' -A typechecker.printUnspecified $extraArgs
47−elif [ "$action" = getSpecs ]; then
48− ln -s $(nix-build --no-out-link '<nixpkgs/nixos>' -A typechecker.specifications $extraArgs)/share/doc/nixos/options-specs.json specifications.json
49−else
50− showSyntax
51− exit 1
52−fi
nixos/modules/installer/tools/tools.nix+1−7
@@ -54,11 +54,6 @@ let
5454 inherit (config.system) nixosVersion nixosCodeName nixosRevision;
5555 };
5656
57− nixos-typecheck = makeProg {
58− name = "nixos-typecheck";
59− src = ./nixos-typecheck.sh;
60− };
61−
6257in
6358
6459{
@@ -72,11 +67,10 @@ in
7267 nixos-generate-config
7368 nixos-option
7469 nixos-version
75− nixos-typecheck
7670 ];
7771
7872 system.build = {
79− inherit nixos-install nixos-generate-config nixos-option nixos-rebuild nixos-typecheck;
73+ inherit nixos-install nixos-generate-config nixos-option nixos-rebuild;
8074 };
8175
8276 };
nixos/modules/misc/meta.nix−1
@@ -5,7 +5,6 @@ with lib;
55let
66 maintainer = mkOptionType {
77 name = "maintainer";
8− typerep = "(maintainer)";
98 check = email: elem email (attrValues lib.maintainers);
109 merge = loc: defs: listToAttrs (singleton (nameValuePair (last defs).file (last defs).value));
1110 };
nixos/modules/misc/nixpkgs.nix+23−26
@@ -3,35 +3,32 @@
33with lib;
44
55let
6− nixpkgsConfig = pkgs:
7− let
8− isConfig = x:
9− builtins.isAttrs x || builtins.isFunction x;
6+ isConfig = x:
7+ builtins.isAttrs x || builtins.isFunction x;
108
11− optCall = f: x:
12− if builtins.isFunction f
13− then f x
14− else f;
9+ optCall = f: x:
10+ if builtins.isFunction f
11+ then f x
12+ else f;
1513
16− mergeConfig = lhs_: rhs_:
17− let
18− lhs = optCall lhs_ { inherit pkgs; };
19− rhs = optCall rhs_ { inherit pkgs; };
20− in
21− lhs // rhs //
22− optionalAttrs (lhs ? packageOverrides) {
23− packageOverrides = pkgs:
24− optCall lhs.packageOverrides pkgs //
25− optCall (attrByPath ["packageOverrides"] ({}) rhs) pkgs;
26− };
14+ mergeConfig = lhs_: rhs_:
15+ let
16+ lhs = optCall lhs_ { inherit pkgs; };
17+ rhs = optCall rhs_ { inherit pkgs; };
2718 in
28− mkOptionType {
29− name = "nixpkgs config";
30− typerep = "(nixpkgsConfig)";
31− check = lib.traceValIfNot isConfig;
32− merge = config: args: fold (def: mergeConfig def.value) {};
33− defaultValues = [{}];
19+ lhs // rhs //
20+ optionalAttrs (lhs ? packageOverrides) {
21+ packageOverrides = pkgs:
22+ optCall lhs.packageOverrides pkgs //
23+ optCall (attrByPath ["packageOverrides"] ({}) rhs) pkgs;
3424 };
25+
26+ configType = mkOptionType {
27+ name = "nixpkgs config";
28+ check = traceValIfNot isConfig;
29+ merge = args: fold (def: mergeConfig def.value) {};
30+ };
31+
3532in
3633
3734{
@@ -49,7 +46,7 @@ in
4946 };
5047 }
5148 '';
52− type = nixpkgsConfig pkgs;
49+ type = configType;
5350 description = ''
5451 The configuration of the Nix Packages collection. (For
5552 details, see the Nixpkgs documentation.) It allows you to set
nixos/modules/module-list.nix−1
@@ -1,5 +1,4 @@
11[
2− ../lib/typechecker.nix
32 ./config/debug-info.nix
43 ./config/fonts/corefonts.nix
54 ./config/fonts/fontconfig-ultimate.nix
nixos/modules/services/misc/gitlab.nix−3
@@ -155,21 +155,18 @@ in {
155155 packages.gitlab = mkOption {
156156 type = types.package;
157157 default = pkgs.gitlab;
158− defaultText = "pkgs.gitlab";
159158 description = "Reference to the gitlab package";
160159 };
161160
162161 packages.gitlab-shell = mkOption {
163162 type = types.package;
164163 default = pkgs.gitlab-shell;
165− defaultText = "pkgs.gitlab-shell";
166164 description = "Reference to the gitlab-shell package";
167165 };
168166
169167 packages.gitlab-workhorse = mkOption {
170168 type = types.package;
171169 default = pkgs.gitlab-workhorse;
172− defaultText = "pkgs.gitlab-workhorse";
173170 description = "Reference to the gitlab-workhorse package";
174171 };
175172
nixos/modules/services/misc/ihaskell.nix−4
@@ -15,14 +15,12 @@ in
1515 options = {
1616 services.ihaskell = {
1717 enable = mkOption {
18− type = lib.types.bool;
1918 default = false;
2019 example = true;
2120 description = "Autostart an IHaskell notebook service.";
2221 };
2322
2423 haskellPackages = mkOption {
25− type = lib.types.packageSet;
2624 default = pkgs.haskellPackages;
2725 defaultText = "pkgs.haskellPackages";
2826 example = literalExample "pkgs.haskell.packages.ghc784";
@@ -35,9 +33,7 @@ in
3533 };
3634
3735 extraPackages = mkOption {
38− type = types.functionTo (types.listOf types.package);
3936 default = self: [];
40− defaultText = "self: []";
4137 example = literalExample ''
4238 haskellPackages: [
4339 haskellPackages.wreq
nixos/modules/services/misc/nixos-manual.nix+1−4
@@ -17,8 +17,6 @@ let
1717 nixpkgs.system = config.nixpkgs.system;
1818 };
1919
20− internalModule = { _module = config._module; };
21−
2220 /* For the purpose of generating docs, evaluate options with each derivation
2321 in `pkgs` (recursively) replaced by a fake with path "\${pkgs.attribute.path}".
2422 It isn't perfect, but it seems to cover a vast majority of use cases.
@@ -31,7 +29,7 @@ let
3129 options =
3230 let
3331 scrubbedEval = evalModules {
34− modules = [ versionModule ] ++ baseModules ++ [ internalModule ];
32+ modules = [ versionModule ] ++ baseModules;
3533 args = (config._module.args) // { modules = [ ]; };
3634 specialArgs = { pkgs = scrubDerivations "pkgs" pkgs; };
3735 };
@@ -45,7 +43,6 @@ let
4543 )
4644 pkgSet;
4745 in scrubbedEval.options;
48− internalModule = config._module;
4946 };
5047
5148 entry = "${manual.manual}/share/doc/nixos/index.html";
nixos/modules/services/web-servers/apache-httpd/default.nix+2−1
@@ -48,7 +48,8 @@ let
4848 if svc ? function then svc.function
4949 else import (toString "${toString ./.}/${if svc ? serviceType then svc.serviceType else svc.serviceName}.nix");
5050 config = (evalModules
51− { modules = [ { options = res.options; config = svc.config or svc; } ] ++ [ { _module.check = false; } ];
51+ { modules = [ { options = res.options; config = svc.config or svc; } ];
52+ check = false;
5253 }).config;
5354 defaults = {
5455 extraConfig = "";
nixos/modules/services/x11/window-managers/xmonad.nix−3
@@ -16,7 +16,6 @@ in
1616 services.xserver.windowManager.xmonad = {
1717 enable = mkEnableOption "xmonad";
1818 haskellPackages = mkOption {
19− type = lib.types.packageSet;
2019 default = pkgs.haskellPackages;
2120 defaultText = "pkgs.haskellPackages";
2221 example = literalExample "pkgs.haskell.packages.ghc784";
@@ -29,9 +28,7 @@ in
2928 };
3029
3130 extraPackages = mkOption {
32− type = lib.types.functionTo (lib.types.listOf lib.types.package);
3331 default = self: [];
34− defaultText = "self: []";
3532 example = literalExample ''
3633 haskellPackages: [
3734 haskellPackages.xmonad-contrib
nixos/modules/system/boot/kernel.nix−1
@@ -20,7 +20,6 @@ in
2020 options = {
2121
2222 boot.kernelPackages = mkOption {
23− type = types.packageSet;
2423 default = pkgs.linuxPackages;
2524 # We don't want to evaluate all of linuxPackages for the manual
2625 # - some of it might not even evaluate correctly.
nixos/modules/system/boot/systemd-unit-options.nix+2−3
@@ -17,15 +17,14 @@ in rec {
1717
1818 unitOption = mkOptionType {
1919 name = "systemd option";
20− typerep = "(systemdOption)";
21− merge = _module: loc: defs:
20+ merge = loc: defs:
2221 let
2322 defs' = filterOverrides defs;
2423 defs'' = getValues defs';
2524 in
2625 if isList (head defs'')
2726 then concatLists defs''
28− else mergeOneOption _module loc defs';
27+ else mergeOneOption loc defs';
2928 };
3029
3130 sharedOptions = {
nixos/release.nix−2
@@ -101,8 +101,6 @@ in rec {
101101 manpages = buildFromConfig ({ pkgs, ... }: { }) (config: config.system.build.manual.manpages);
102102 options = (buildFromConfig ({ pkgs, ... }: { }) (config: config.system.build.manual.optionsJSON)).x86_64-linux;
103103
104− optionsSpecs = (buildFromConfig ({ pkgs, ... }: { _module.typeInference = "silent"; }) (config: config.system.build.typechecker.specifications)).x86_64-linux;
105−
106104
107105 # Build the initial ramdisk so Hydra can keep track of its size over time.
108106 initialRamdisk = buildFromConfig ({ pkgs, ... }: { }) (config: config.system.build.initialRamdisk);