diff options
author | Vladimír Čunát <vcunat@gmail.com> | 2019-02-01 09:42:53 +0100 |
---|---|---|
committer | Vladimír Čunát <vcunat@gmail.com> | 2019-02-01 09:42:53 +0100 |
commit | 8ba516664bf367889b06b06e4122372f82f24feb (patch) | |
tree | 01b691a7e1ad4797843b4c93d8a9d74fd16311d7 /lib | |
parent | d00ca4476cd91bae052e8ded4d94e124a353d091 (diff) | |
parent | 5effa4e0f98b317fe4607b1a6548811017c3325d (diff) |
Merge branch 'staging-next' into staging
Diffstat (limited to 'lib')
-rw-r--r-- | lib/kernel.nix | 62 | ||||
-rw-r--r-- | lib/modules.nix | 45 | ||||
-rw-r--r-- | lib/options.nix | 2 | ||||
-rw-r--r-- | lib/systems/default.nix | 1 | ||||
-rw-r--r-- | lib/types.nix | 8 |
5 files changed, 32 insertions, 86 deletions
diff --git a/lib/kernel.nix b/lib/kernel.nix index 45b33aea7b871..5923011774b15 100644 --- a/lib/kernel.nix +++ b/lib/kernel.nix @@ -1,57 +1,21 @@ -{ lib -# we pass the kernel version here to keep a nice syntax `whenOlder "4.13"` -# kernelVersion, e.g., config.boot.kernelPackages.version -, version -, mkValuePreprocess ? null -}: +{ lib, version }: with lib; rec { - # Common patterns - when = cond: opt: if cond then opt else null; - whenAtLeast = ver: when (versionAtLeast version ver); - whenOlder = ver: when (versionOlder version ver); - whenBetween = verLow: verHigh: when (versionAtLeast version verLow && versionOlder version verHigh); + # Common patterns/legacy + whenAtLeast = ver: mkIf (versionAtLeast version ver); + whenOlder = ver: mkIf (versionOlder version ver); + # range is (inclusive, exclusive) + whenBetween = verLow: verHigh: mkIf (versionAtLeast version verLow && versionOlder version verHigh); - # Keeping these around in case we decide to change this horrible implementation :) - option = x: if x == null then null else "?${x}"; - yes = "y"; - no = "n"; - module = "m"; - mkValue = val: - let - isNumber = c: elem c ["0" "1" "2" "3" "4" "5" "6" "7" "8" "9"]; - in - if val == "" then "\"\"" - else if val == yes || val == module || val == no then val - else if all isNumber (stringToCharacters val) then val - else if substring 0 2 val == "0x" then val - else val; # FIXME: fix quoting one day + # Keeping these around in case we decide to change this horrible implementation :) + option = x: + x // { optional = true; }; + yes = { tristate = "y"; }; + no = { tristate = "n"; }; + module = { tristate = "m"; }; + freeform = x: { freeform = x; }; - # generate nix intermediate kernel config file of the form - # - # VIRTIO_MMIO m - # VIRTIO_BLK y - # VIRTIO_CONSOLE n - # NET_9P_VIRTIO? y - # - # Use mkValuePreprocess to preprocess option values, aka mark 'modules' as - # 'yes' or vice-versa - # Borrowed from copumpkin https://github.com/NixOS/nixpkgs/pull/12158 - # returns a string, expr should be an attribute set - generateNixKConf = exprs: mkValuePreprocess: - let - mkConfigLine = key: rawval: - let - val = if builtins.isFunction mkValuePreprocess then mkValuePreprocess rawval else rawval; - in - if val == null - then "" - else if hasPrefix "?" val - then "${key}? ${mkValue (removePrefix "?" val)}\n" - else "${key} ${mkValue val}\n"; - mkConf = cfg: concatStrings (mapAttrsToList mkConfigLine cfg); - in mkConf exprs; } diff --git a/lib/modules.nix b/lib/modules.nix index 9f8e196ee0f73..5c9d66d8f97b9 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -214,23 +214,25 @@ rec { qux = [ "module.hidden=baz,value=bar" "module.hidden=fli,value=gne" ]; } */ - byName = attr: f: modules: foldl' (acc: module: - foldl' (inner: name: - inner // { ${name} = (acc.${name} or []) ++ (f module module.${attr}.${name}); } - ) acc (attrNames module.${attr}) - ) {} modules; + byName = attr: f: modules: + foldl' (acc: module: + acc // (mapAttrs (n: v: + (acc.${n} or []) ++ f module v + ) module.${attr} + ) + ) {} modules; # an attrset 'name' => list of submodules that declare ‘name’. - declsByName = byName "options" - (module: option: [{ inherit (module) file; options = option; }]) - options; + declsByName = byName "options" (module: option: + [{ inherit (module) file; options = option; }] + ) options; # an attrset 'name' => list of submodules that define ‘name’. defnsByName = byName "config" (module: value: - map (config: { inherit (module) file; inherit config; }) (pushDownProperties value) + map (config: { inherit (module) file; inherit config; }) (pushDownProperties value) ) configs; # extract the definitions for each loc - defnsByName' = byName "config" - (module: value: [{ inherit (module) file; inherit value; }]) - configs; + defnsByName' = byName "config" (module: value: + [{ inherit (module) file; inherit value; }] + ) configs; in (flip mapAttrs declsByName (name: decls: # We're descending into attribute ‘name’. @@ -362,7 +364,6 @@ rec { values = defs'''; inherit (defs'') highestPrio; }; - defsFinal = defsFinal'.values; # Type-check the remaining definitions, and merge them. @@ -475,22 +476,8 @@ rec { optionSet to options of type submodule. FIXME: remove eventually. */ fixupOptionType = loc: opt: - let - options = opt.options or - (throw "Option `${showOption loc'}' has type optionSet but has no option attribute, in ${showFiles opt.declarations}."); - f = tp: - let optionSetIn = type: (tp.name == type) && (tp.functor.wrapped.name == "optionSet"); - in - if tp.name == "option set" || tp.name == "submodule" then - throw "The option ${showOption loc} uses submodules without a wrapping type, in ${showFiles opt.declarations}." - else if optionSetIn "attrsOf" then types.attrsOf (types.submodule options) - else if optionSetIn "loaOf" then types.loaOf (types.submodule options) - else if optionSetIn "listOf" then types.listOf (types.submodule options) - else if optionSetIn "nullOr" then types.nullOr (types.submodule options) - else tp; - in - if opt.type.getSubModules or null == null - then opt // { type = f (opt.type or types.unspecified); } + if opt.type.getSubModules or null == null + then opt // { type = opt.type or types.unspecified; } else opt // { type = opt.type.substSubModules opt.options; options = []; }; diff --git a/lib/options.nix b/lib/options.nix index 791930eafbd0f..5cea99067aaba 100644 --- a/lib/options.nix +++ b/lib/options.nix @@ -48,8 +48,6 @@ rec { visible ? null, # Whether the option can be set only once readOnly ? null, - # Obsolete, used by types.optionSet. - options ? null } @ attrs: attrs // { _type = "option"; }; diff --git a/lib/systems/default.nix b/lib/systems/default.nix index 9b25052ab88d9..77f200952958b 100644 --- a/lib/systems/default.nix +++ b/lib/systems/default.nix @@ -58,6 +58,7 @@ rec { "netbsd" = "NetBSD"; "freebsd" = "FreeBSD"; "openbsd" = "OpenBSD"; + "wasm" = "Wasm"; }.${final.parsed.kernel.name} or null; # uname -p diff --git a/lib/types.nix b/lib/types.nix index d1ece2402ad7f..7a88e1b9e36be 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -284,8 +284,7 @@ rec { (mergeDefinitions (loc ++ [name]) elemType defs).optionalValue ) # Push down position info. - (map (def: listToAttrs (mapAttrsToList (n: def': - { name = n; value = { inherit (def) file; value = def'; }; }) def.value)) defs))); + (map (def: mapAttrs (n: v: { inherit (def) file; value = v; }) def.value) defs))); getSubOptions = prefix: elemType.getSubOptions (prefix ++ ["<name>"]); getSubModules = elemType.getSubModules; substSubModules = m: attrsOf (elemType.substSubModules m); @@ -470,10 +469,7 @@ rec { # Obsolete alternative to configOf. It takes its option # declarations from the ‘options’ attribute of containing option # declaration. - optionSet = mkOptionType { - name = builtins.trace "types.optionSet is deprecated; use types.submodule instead" "optionSet"; - description = "option set"; - }; + optionSet = builtins.throw "types.optionSet is deprecated; use types.submodule instead" "optionSet"; # Augment the given type with an additional type check function. addCheck = elemType: check: elemType // { check = x: elemType.check x && check x; }; |