diff options
Diffstat (limited to 'nixos')
21 files changed, 38 insertions, 325 deletions
diff --git a/nixos/default.nix b/nixos/default.nix index 117a7b5d6038..5d69b79e13a6 100644 --- a/nixos/default.nix +++ b/nixos/default.nix @@ -34,8 +34,6 @@ in system = eval.config.system.build.toplevel; - typechecker = eval.config.system.build.typechecker; - vm = vmConfig.system.build.vm; vmWithBootLoader = vmWithBootLoaderConfig.system.build.vm; diff --git a/nixos/doc/manual/default.nix b/nixos/doc/manual/default.nix index ea8601497361..4ce6ea1c1118 100644 --- a/nixos/doc/manual/default.nix +++ b/nixos/doc/manual/default.nix @@ -1,4 +1,4 @@ -{ pkgs, options, internalModule, version, revision, extraSources ? [] }: +{ pkgs, options, version, revision, extraSources ? [] }: with pkgs; with pkgs.lib; @@ -6,10 +6,8 @@ with pkgs.lib; let # Remove invisible and internal options. - optionsList = filter (opt: opt.visible && !opt.internal) (optionAttrSetToDocList internalModule options); + optionsList = filter (opt: opt.visible && !opt.internal) (optionAttrSetToDocList options); - # INFO: Please add 'defaultText' or 'literalExample' to the option - # definition to avoid this substitution! # Replace functions by the string <function> substFunction = x: if builtins.isAttrs x then mapAttrs (name: substFunction) x diff --git a/nixos/doc/manual/development/option-declarations.xml b/nixos/doc/manual/development/option-declarations.xml index 08bde4a275d9..ea5d1241876e 100644 --- a/nixos/doc/manual/development/option-declarations.xml +++ b/nixos/doc/manual/development/option-declarations.xml @@ -8,7 +8,7 @@ <para>An option declaration specifies the name, type and description of a NixOS configuration option. It is illegal to define an option -that has not been declared in any module. A option declaration +that hasn’t been declared in any module. A option declaration generally looks like this: <programlisting> @@ -145,108 +145,6 @@ options = { You can also create new types using the function <varname>mkOptionType</varname>. See -<filename>lib/types.nix</filename> in Nixpkgs for details. - -An option declaration must follow the following rules: -<itemizedlist mark='bullet'> - - <listitem> - <para>A <varname>defaultText</varname> must be defined if and only if the type of the option - derives from <varname>package</varname>, <varname>packageSet</varname> or <varname>nixpkgsConfig - </varname>, and if and only if a <varname>default</varname> attribute is defined and if and only if - the value of the <varname>default</varname> attribute is not the default of the type of the - option declaration. - - For example, a <varname>defaultText</varname> must be defined for -<programlisting> -type = types.listOf types.package; -default = [ pkgs.foo; ]; -defaultText = "[ pkgs.foo; ]"; -</programlisting>. - - But no <varname>defaultText</varname> must be defined for -<programlisting> -type = types.listOf types.package; -default = []; -</programlisting>, - as <varname>[]</varname> is the default of <varname>types.listOf types.package</varname>. - </para> - </listitem> - - <listitem> - <para>A <varname>defaultText</varname> can be defined if the type of the option derives from - <varname>path</varname> and if a <varname>default</varname> attribute is defined.</para> - </listitem> - - <listitem> - <para>The value of the <varname>example</varname> attribute must be wrapped with <varname> - literalExample</varname> if the type of the option derives from <varname>package</varname>, - <varname>packageSet</varname> or <varname>nixpkgsConfig</varname>.</para> - </listitem> - - <listitem> - <para>The value of <varname>defaultText</varname> and <varname>literalExample</varname> must - be a string which contains a valid nix expression. The nix expression has to evaluate in - <code>{pkgs}: <replaceable>value</replaceable></code>. - For example: - <itemizedlist> - <listitem> - <para>A <varname>defaultText</varname> could, e.g., be: -<programlisting> -type = types.package; -default = pkgs.foo; -defaultText = "pkgs.foo"; -</programlisting> - But not <code>defaultText = "pkgs.foo;";</code>, as that - corresponds to <code>{pkgs}: pkgs.foo;</code>, which is an - invalid nix expression due to the ending with <varname>;</varname>.</para> - </listitem> - - <listitem> - <para>A <varname>literalExample</varname> could be used as, e.g.: -<programlisting> -type = types.path; -example = literalExample "\"\${pkgs.bar}/bin/bar\""; -</programlisting> - But not <code>literalExample "\${pkgs.bar}/bin/bar";</code>, as that corresponds - to <code>{pkgs}: ${pkgs.bar}/bin/bar</code>, which is an invalid nix expression - as the <varname>path</varname> is not a <varname>string</varname> anymore.</para> - </listitem> - </itemizedlist></para> - </listitem> - - <listitem> - <para>The <varname>type</varname> attribute must be defined for every option declaration.</para> - </listitem> - -</itemizedlist> - -NixOS ships the tool <varname>nixos-typecheck</varname> that can check an option declaration to: - -<itemizedlist mark='bullet'> - - <listitem> - <para>Enforce that an option declaration has a <varname>defaultText</varname> if and only if the - type of the option derives from <varname>package</varname>, <varname>packageSet</varname> or - <varname>nixpkgsConfig</varname> and if a <varname>default</varname> attribute is defined.</para> - </listitem> - - <listitem> - <para>Enforce that the value of the <varname>example</varname> attribute is wrapped with <varname> - literalExample</varname> if the type of the option derives from <varname>package</varname>, - <varname>packageSet</varname> or <varname>nixpkgsConfig</varname>.</para> - </listitem> - - <listitem> - <para>Warn if a <varname>defaultText</varname> is defined in an option declaration if the type of - the option does not derive from <varname>package</varname>, <varname>packageSet</varname> or - <varname>nixpkgsConfig</varname>.</para> - </listitem> - - <listitem> - <para>Warn if no <varname>type</varname> is defined in an option declaration.</para> - </listitem> - -</itemizedlist></para> +<filename>lib/types.nix</filename> in Nixpkgs for details.</para> </section> diff --git a/nixos/lib/eval-config.nix b/nixos/lib/eval-config.nix index 79890e0add7d..a87b285c5b7b 100644 --- a/nixos/lib/eval-config.nix +++ b/nixos/lib/eval-config.nix @@ -20,13 +20,8 @@ , # !!! See comment about args in lib/modules.nix specialArgs ? {} , modules -, # Pass through a configuration of the internal modules declared - # in lib/modules.nix. - _module ? {} -, # !!! See comment about typeInference in lib/modules.nix - typeInference ? null , # !!! See comment about check in lib/modules.nix - check ? null + check ? true , prefix ? [] , lib ? import ../../lib }: @@ -46,17 +41,13 @@ let }; }; - internalModule = { _module = (_module - // (if isNull check then {} else { inherit check; }) - // (if isNull typeInference then {} else { inherit typeInference; })); }; - in rec { # Merge the option definitions in all modules, forming the full # system configuration. inherit (lib.evalModules { - inherit prefix; - modules = modules ++ extraModules ++ baseModules ++ [ pkgsModule ] ++ [ internalModule ]; + inherit prefix check; + modules = modules ++ extraModules ++ baseModules ++ [ pkgsModule ]; args = extraArgs; specialArgs = { modulesPath = ../modules; } // specialArgs; }) config options; diff --git a/nixos/lib/typechecker.nix b/nixos/lib/typechecker.nix deleted file mode 100644 index b4d8277f8fe9..000000000000 --- a/nixos/lib/typechecker.nix +++ /dev/null @@ -1,91 +0,0 @@ -{ config, lib, pkgs, baseModules, ... }: - -with pkgs; -with pkgs.lib; - -let - - optionsSpecs = inferenceMode: - let - versionModule = - { system.nixosVersionSuffix = config.system.nixosVersionSuffix; - system.nixosRevision = config.system.nixosRevision; - nixpkgs.system = config.nixpkgs.system; - }; - - internalModule = { _module = config._module; } // (if isNull inferenceMode then {} else { _module.typeInference = mkForce inferenceMode; }); - - eval = evalModules { - modules = [ versionModule ] ++ baseModules ++ [ internalModule ]; - args = (config._module.args) // { modules = [ ]; }; - }; - - # Remove invisible and internal options. - optionsSpecs' = filter (opt: opt.visible && !opt.internal) (optionAttrSetToParseableSpecifications config._module eval.options); - - # INFO: Please add 'defaultText' or 'literalExample' to the option - # definition to avoid this exception! - substFunction = key: decls: x: - if builtins.isAttrs x then mapAttrs (name: substFunction key decls) x - else if builtins.isList x then map (substFunction key decls) x - else if builtins.isFunction x then throw "Found an unexpected <function> in ${key} declared in ${concatStringsSep " and " decls}." - else x; - - prefix = toString ../..; - - stripPrefix = fn: - if substring 0 (stringLength prefix) fn == prefix then - substring (stringLength prefix + 1) 1000 fn - else - fn; - - # Clean up declaration sites to not refer to the NixOS source tree. - cleanupOptions = x: flip map x (opt: - let substFunction' = y: substFunction opt.name opt.declarations y; - in opt - // { declarations = map (fn: stripPrefix fn) opt.declarations; } - // optionalAttrs (opt ? example) { example = substFunction' opt.example; } - // optionalAttrs (opt ? default) { default = substFunction' opt.default; } - // optionalAttrs (opt ? type) { type = substFunction' opt.type; }); - - in - cleanupOptions optionsSpecs'; - -in - -{ - - system.build.typechecker = { - - # The NixOS options as machine readable specifications in JSON format. - specifications = stdenv.mkDerivation { - name = "options-specs-json"; - - buildCommand = '' - # Export list of options in different format. - dst=$out/share/doc/nixos - mkdir -p $dst - - cp ${builtins.toFile "options.json" (builtins.unsafeDiscardStringContext (builtins.toJSON - (listToAttrs (map (o: { name = o.name; value = removeAttrs o ["name" "visible" "internal"]; }) (optionsSpecs null))))) - } $dst/options-specs.json - - mkdir -p $out/nix-support - echo "file json $dst/options-specs.json" >> $out/nix-support/hydra-build-products - ''; # */ - - meta.description = "List of NixOS options specifications in JSON format"; - }; - - silent = listToAttrs (map (o: { name = o.name; value = removeAttrs o ["name" "visible" "internal"]; }) (optionsSpecs "silent")); - printAll = listToAttrs (map (o: { name = o.name; value = removeAttrs o ["name" "visible" "internal"]; }) (optionsSpecs "printAll")); - printUnspecified = listToAttrs (map (o: { name = o.name; value = removeAttrs o ["name" "visible" "internal"]; }) (optionsSpecs "printUnspecified")); - - }; - -} - - - - - diff --git a/nixos/modules/config/i18n.nix b/nixos/modules/config/i18n.nix index 3d21bda5734f..b20fac6ad3e2 100644 --- a/nixos/modules/config/i18n.nix +++ b/nixos/modules/config/i18n.nix @@ -64,7 +64,6 @@ in consoleKeyMap = mkOption { type = mkOptionType { name = "string or path"; - typerep = "(stringOrPath)"; check = t: (isString t || types.path.check t); }; diff --git a/nixos/modules/config/sysctl.nix b/nixos/modules/config/sysctl.nix index 174d7014ca8a..61b02c5ffa6a 100644 --- a/nixos/modules/config/sysctl.nix +++ b/nixos/modules/config/sysctl.nix @@ -6,7 +6,6 @@ let sysctlOption = mkOptionType { name = "sysctl option value"; - typerep = "(sysctl)"; check = val: let checkType = x: isBool x || isString x || isInt x || isNull x; diff --git a/nixos/modules/installer/tools/nixos-option.sh b/nixos/modules/installer/tools/nixos-option.sh index dd21dc71ee2b..17c17d05e288 100644 --- a/nixos/modules/installer/tools/nixos-option.sh +++ b/nixos/modules/installer/tools/nixos-option.sh @@ -115,8 +115,8 @@ let let name = head attrsNames; rest = tail attrsNames; in if isOption result.options then walkOptions rest { - options = result.options.type.getSubOptionsPrefix ""; - opt = ''(\${result.opt}.type.getSubOptionsPrefix "")''; + options = result.options.type.getSubOptions ""; + opt = ''(\${result.opt}.type.getSubOptions "")''; cfg = ''\${result.cfg}."\${name}"''; } else diff --git a/nixos/modules/installer/tools/nixos-typecheck.sh b/nixos/modules/installer/tools/nixos-typecheck.sh deleted file mode 100644 index f9557be0c50e..000000000000 --- a/nixos/modules/installer/tools/nixos-typecheck.sh +++ /dev/null @@ -1,52 +0,0 @@ -#! /bin/sh -#! @shell@ - -if [ -x "@shell@" ]; then export SHELL="@shell@"; fi; - -set -e - -showSyntax() { -cat >&1 << EOF -nixos-typecheck -usage: - nixos-typecheck [action] [args] -where: - action = silent | printAll | printUnspecified | getSpecs - with default action: printUnspecified - args = any argument supported by nix-build -EOF -} - - -# Parse the command line. -extraArgs=() -action=printUnspecified - -while [ "$#" -gt 0 ]; do - i="$1"; shift 1 - case "$i" in - --help) - showSyntax - ;; - silent|printAll|printUnspecified|getSpecs) - action="$i" - ;; - *) - extraArgs="$extraArgs $i" - ;; - esac -done - - -if [ "$action" = silent ]; then - nix-build --no-out-link '<nixpkgs/nixos>' -A typechecker.silent $extraArgs -elif [ "$action" = printAll ]; then - nix-build --no-out-link '<nixpkgs/nixos>' -A typechecker.printAll $extraArgs -elif [ "$action" = printUnspecified ]; then - nix-build --no-out-link '<nixpkgs/nixos>' -A typechecker.printUnspecified $extraArgs -elif [ "$action" = getSpecs ]; then - ln -s $(nix-build --no-out-link '<nixpkgs/nixos>' -A typechecker.specifications $extraArgs)/share/doc/nixos/options-specs.json specifications.json -else - showSyntax - exit 1 -fi diff --git a/nixos/modules/installer/tools/tools.nix b/nixos/modules/installer/tools/tools.nix index 69bd0d26b773..9ac3b7a5b16f 100644 --- a/nixos/modules/installer/tools/tools.nix +++ b/nixos/modules/installer/tools/tools.nix @@ -54,11 +54,6 @@ let inherit (config.system) nixosVersion nixosCodeName nixosRevision; }; - nixos-typecheck = makeProg { - name = "nixos-typecheck"; - src = ./nixos-typecheck.sh; - }; - in { @@ -72,11 +67,10 @@ in nixos-generate-config nixos-option nixos-version - nixos-typecheck ]; system.build = { - inherit nixos-install nixos-generate-config nixos-option nixos-rebuild nixos-typecheck; + inherit nixos-install nixos-generate-config nixos-option nixos-rebuild; }; }; diff --git a/nixos/modules/misc/meta.nix b/nixos/modules/misc/meta.nix index 9a453172c63a..22622706f2c8 100644 --- a/nixos/modules/misc/meta.nix +++ b/nixos/modules/misc/meta.nix @@ -5,7 +5,6 @@ with lib; let maintainer = mkOptionType { name = "maintainer"; - typerep = "(maintainer)"; check = email: elem email (attrValues lib.maintainers); merge = loc: defs: listToAttrs (singleton (nameValuePair (last defs).file (last defs).value)); }; diff --git a/nixos/modules/misc/nixpkgs.nix b/nixos/modules/misc/nixpkgs.nix index 511831ae5cd2..5eb38c510b48 100644 --- a/nixos/modules/misc/nixpkgs.nix +++ b/nixos/modules/misc/nixpkgs.nix @@ -3,35 +3,32 @@ with lib; let - nixpkgsConfig = pkgs: - let - isConfig = x: - builtins.isAttrs x || builtins.isFunction x; + isConfig = x: + builtins.isAttrs x || builtins.isFunction x; - optCall = f: x: - if builtins.isFunction f - then f x - else f; + optCall = f: x: + if builtins.isFunction f + then f x + else f; - mergeConfig = lhs_: rhs_: - let - lhs = optCall lhs_ { inherit pkgs; }; - rhs = optCall rhs_ { inherit pkgs; }; - in - lhs // rhs // - optionalAttrs (lhs ? packageOverrides) { - packageOverrides = pkgs: - optCall lhs.packageOverrides pkgs // - optCall (attrByPath ["packageOverrides"] ({}) rhs) pkgs; - }; + mergeConfig = lhs_: rhs_: + let + lhs = optCall lhs_ { inherit pkgs; }; + rhs = optCall rhs_ { inherit pkgs; }; in - mkOptionType { - name = "nixpkgs config"; - typerep = "(nixpkgsConfig)"; - check = lib.traceValIfNot isConfig; - merge = config: args: fold (def: mergeConfig def.value) {}; - defaultValues = [{}]; + lhs // rhs // + optionalAttrs (lhs ? packageOverrides) { + packageOverrides = pkgs: + optCall lhs.packageOverrides pkgs // + optCall (attrByPath ["packageOverrides"] ({}) rhs) pkgs; }; + + configType = mkOptionType { + name = "nixpkgs config"; + check = traceValIfNot isConfig; + merge = args: fold (def: mergeConfig def.value) {}; + }; + in { @@ -49,7 +46,7 @@ in }; } ''; - type = nixpkgsConfig pkgs; + type = configType; description = '' The configuration of the Nix Packages collection. (For details, see the Nixpkgs documentation.) It allows you to set diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 88e01069b264..ad1636e002d8 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -1,5 +1,4 @@ [ - ../lib/typechecker.nix ./config/debug-info.nix ./config/fonts/corefonts.nix ./config/fonts/fontconfig-ultimate.nix diff --git a/nixos/modules/services/misc/gitlab.nix b/nixos/modules/services/misc/gitlab.nix index e6ebcd6dc145..cc50bfbea531 100644 --- a/nixos/modules/services/misc/gitlab.nix +++ b/nixos/modules/services/misc/gitlab.nix @@ -155,21 +155,18 @@ in { packages.gitlab = mkOption { type = types.package; default = pkgs.gitlab; - defaultText = "pkgs.gitlab"; description = "Reference to the gitlab package"; }; packages.gitlab-shell = mkOption { type = types.package; default = pkgs.gitlab-shell; - defaultText = "pkgs.gitlab-shell"; description = "Reference to the gitlab-shell package"; }; packages.gitlab-workhorse = mkOption { type = types.package; default = pkgs.gitlab-workhorse; - defaultText = "pkgs.gitlab-workhorse"; description = "Reference to the gitlab-workhorse package"; }; diff --git a/nixos/modules/services/misc/ihaskell.nix b/nixos/modules/services/misc/ihaskell.nix index c177d68c8fe0..d0e9b839e754 100644 --- a/nixos/modules/services/misc/ihaskell.nix +++ b/nixos/modules/services/misc/ihaskell.nix @@ -15,14 +15,12 @@ in options = { services.ihaskell = { enable = mkOption { - type = lib.types.bool; default = false; example = true; description = "Autostart an IHaskell notebook service."; }; haskellPackages = mkOption { - type = lib.types.packageSet; default = pkgs.haskellPackages; defaultText = "pkgs.haskellPackages"; example = literalExample "pkgs.haskell.packages.ghc784"; @@ -35,9 +33,7 @@ in }; extraPackages = mkOption { - type = types.functionTo (types.listOf types.package); default = self: []; - defaultText = "self: []"; example = literalExample '' haskellPackages: [ haskellPackages.wreq diff --git a/nixos/modules/services/misc/nixos-manual.nix b/nixos/modules/services/misc/nixos-manual.nix index 7ba1c319add4..37ea339300d4 100644 --- a/nixos/modules/services/misc/nixos-manual.nix +++ b/nixos/modules/services/misc/nixos-manual.nix @@ -17,8 +17,6 @@ let nixpkgs.system = config.nixpkgs.system; }; - internalModule = { _module = config._module; }; - /* For the purpose of generating docs, evaluate options with each derivation in `pkgs` (recursively) replaced by a fake with path "\${pkgs.attribute.path}". It isn't perfect, but it seems to cover a vast majority of use cases. @@ -31,7 +29,7 @@ let options = let scrubbedEval = evalModules { - modules = [ versionModule ] ++ baseModules ++ [ internalModule ]; + modules = [ versionModule ] ++ baseModules; args = (config._module.args) // { modules = [ ]; }; specialArgs = { pkgs = scrubDerivations "pkgs" pkgs; }; }; @@ -45,7 +43,6 @@ let ) pkgSet; in scrubbedEval.options; - internalModule = config._module; }; entry = "${manual.manual}/share/doc/nixos/index.html"; diff --git a/nixos/modules/services/web-servers/apache-httpd/default.nix b/nixos/modules/services/web-servers/apache-httpd/default.nix index 8340287df453..60ec49c9e66e 100644 --- a/nixos/modules/services/web-servers/apache-httpd/default.nix +++ b/nixos/modules/services/web-servers/apache-httpd/default.nix @@ -48,7 +48,8 @@ let if svc ? function then svc.function else import (toString "${toString ./.}/${if svc ? serviceType then svc.serviceType else svc.serviceName}.nix"); config = (evalModules - { modules = [ { options = res.options; config = svc.config or svc; } ] ++ [ { _module.check = false; } ]; + { modules = [ { options = res.options; config = svc.config or svc; } ]; + check = false; }).config; defaults = { extraConfig = ""; diff --git a/nixos/modules/services/x11/window-managers/xmonad.nix b/nixos/modules/services/x11/window-managers/xmonad.nix index d8acb824f7df..6af88d4f645b 100644 --- a/nixos/modules/services/x11/window-managers/xmonad.nix +++ b/nixos/modules/services/x11/window-managers/xmonad.nix @@ -16,7 +16,6 @@ in services.xserver.windowManager.xmonad = { enable = mkEnableOption "xmonad"; haskellPackages = mkOption { - type = lib.types.packageSet; default = pkgs.haskellPackages; defaultText = "pkgs.haskellPackages"; example = literalExample "pkgs.haskell.packages.ghc784"; @@ -29,9 +28,7 @@ in }; extraPackages = mkOption { - type = lib.types.functionTo (lib.types.listOf lib.types.package); default = self: []; - defaultText = "self: []"; example = literalExample '' haskellPackages: [ haskellPackages.xmonad-contrib diff --git a/nixos/modules/system/boot/kernel.nix b/nixos/modules/system/boot/kernel.nix index 5b11a3fc61c3..a6bbca9b30bb 100644 --- a/nixos/modules/system/boot/kernel.nix +++ b/nixos/modules/system/boot/kernel.nix @@ -20,7 +20,6 @@ in options = { boot.kernelPackages = mkOption { - type = types.packageSet; default = pkgs.linuxPackages; # We don't want to evaluate all of linuxPackages for the manual # - some of it might not even evaluate correctly. diff --git a/nixos/modules/system/boot/systemd-unit-options.nix b/nixos/modules/system/boot/systemd-unit-options.nix index 16d0e098b8c8..d4cab93b26b8 100644 --- a/nixos/modules/system/boot/systemd-unit-options.nix +++ b/nixos/modules/system/boot/systemd-unit-options.nix @@ -17,15 +17,14 @@ in rec { unitOption = mkOptionType { name = "systemd option"; - typerep = "(systemdOption)"; - merge = _module: loc: defs: + merge = loc: defs: let defs' = filterOverrides defs; defs'' = getValues defs'; in if isList (head defs'') then concatLists defs'' - else mergeOneOption _module loc defs'; + else mergeOneOption loc defs'; }; sharedOptions = { diff --git a/nixos/release.nix b/nixos/release.nix index 521cae760aef..d8ef23199cb2 100644 --- a/nixos/release.nix +++ b/nixos/release.nix @@ -101,8 +101,6 @@ in rec { manpages = buildFromConfig ({ pkgs, ... }: { }) (config: config.system.build.manual.manpages); options = (buildFromConfig ({ pkgs, ... }: { }) (config: config.system.build.manual.optionsJSON)).x86_64-linux; - optionsSpecs = (buildFromConfig ({ pkgs, ... }: { _module.typeInference = "silent"; }) (config: config.system.build.typechecker.specifications)).x86_64-linux; - # Build the initial ramdisk so Hydra can keep track of its size over time. initialRamdisk = buildFromConfig ({ pkgs, ... }: { }) (config: config.system.build.initialRamdisk); |