Skip to content

Commit

Permalink
Revert "modules: add support for module replacement with disabledModu…
Browse files Browse the repository at this point in the history
…les"

This reverts commit 3f25666 for now.
Evaluation of the tested job got broken, blocking nixos-unstable.
  • Loading branch information
vcunat committed Mar 1, 2017
1 parent 4150920 commit fcec3e1
Show file tree
Hide file tree
Showing 9 changed files with 7 additions and 127 deletions.
24 changes: 7 additions & 17 deletions lib/modules.nix
Expand Up @@ -20,8 +20,7 @@ rec {
, prefix ? []
, # This should only be used for special arguments that need to be evaluated
# when resolving module structure (like in imports). For everything else,
# there's _module.args. If specialArgs.modulesPath is defined it will be
# used as the base path for disabledModules.
# there's _module.args.
specialArgs ? {}
, # This would be remove in the future, Prefer _module.args option instead.
args ? {}
Expand Down Expand Up @@ -59,7 +58,10 @@ rec {

closed = closeModules (modules ++ [ internalModule ]) ({ inherit config options; lib = import ./.; } // specialArgs);

options = mergeModules prefix (filterModules (specialArgs.modulesPath or "") closed);
# Note: the list of modules is reversed to maintain backward
# compatibility with the old module system. Not sure if this is
# the most sensible policy.
options = mergeModules prefix (reverseList closed);

# Traverse options and extract the option values into the final
# config set. At the same time, check whether all option
Expand All @@ -85,16 +87,6 @@ rec {
result = { inherit options config; };
in result;


# Filter disabled modules. Modules can be disabled allowing
# their implementation to be replaced.
filterModules = modulesPath: modules:
let
moduleKey = m: if isString m then toString modulesPath + "/" + m else toString m;
disabledKeys = map moduleKey (concatMap (m: m.disabledModules) modules);
in
filter (m: !(elem m.key disabledKeys)) modules;

/* Close a set of modules under the ‘imports’ relation. */
closeModules = modules: args:
let
Expand All @@ -119,24 +111,22 @@ rec {
else {};
in
if m ? config || m ? options then
let badAttrs = removeAttrs m ["_file" "key" "disabledModules" "imports" "options" "config" "meta"]; in
let badAttrs = removeAttrs m ["imports" "options" "config" "key" "_file" "meta"]; in
if badAttrs != {} then
throw "Module `${key}' has an unsupported attribute `${head (attrNames badAttrs)}'. This is caused by assignments to the top-level attributes `config' or `options'."
else
{ file = m._file or file;
key = toString m.key or key;
disabledModules = m.disabledModules or [];
imports = m.imports or [];
options = m.options or {};
config = mkMerge [ (m.config or {}) metaSet ];
}
else
{ file = m._file or file;
key = toString m.key or key;
disabledModules = m.disabledModules or [];
imports = m.require or [] ++ m.imports or [];
options = {};
config = mkMerge [ (removeAttrs m ["_file" "key" "disabledModules" "require" "imports"]) metaSet ];
config = mkMerge [ (removeAttrs m ["key" "_file" "require" "imports"]) metaSet ];
};

applyIfFunction = key: f: args@{ config, options, lib, ... }: if isFunction f then
Expand Down
8 changes: 0 additions & 8 deletions lib/tests/modules.sh
Expand Up @@ -99,14 +99,6 @@ checkConfigOutput 'true' "$@" ./define-enable.nix ./define-loaOfSub-if-foo-enabl
checkConfigOutput 'true' "$@" ./define-enable.nix ./define-loaOfSub-foo-if-enable.nix
checkConfigOutput 'true' "$@" ./define-enable.nix ./define-loaOfSub-foo-enable-if.nix

# Check disabledModules with config definitions and option declarations.
set -- config.enable ./define-enable.nix ./declare-enable.nix
checkConfigOutput "true" "$@"
checkConfigOutput "false" "$@" ./disable-define-enable.nix
checkConfigError "The option .*enable.* defined in .* does not exist" "$@" ./disable-declare-enable.nix
checkConfigError "attribute .*enable.* in selection path .*config.enable.* not found" "$@" ./disable-define-enable.nix ./disable-declare-enable.nix
checkConfigError "attribute .*enable.* in selection path .*config.enable.* not found" "$@" ./disable-enable-modules.nix

# Check _module.args.
set -- config.enable ./declare-enable.nix ./define-enable-with-custom-arg.nix
checkConfigError 'while evaluating the module argument .*custom.* in .*define-enable-with-custom-arg.nix.*:' "$@"
Expand Down
1 change: 0 additions & 1 deletion lib/tests/modules/default.nix
Expand Up @@ -3,6 +3,5 @@
{
inherit (lib.evalModules {
inherit modules;
specialArgs.modulesPath = ./.;
}) config options;
}
5 changes: 0 additions & 5 deletions lib/tests/modules/disable-declare-enable.nix

This file was deleted.

5 changes: 0 additions & 5 deletions lib/tests/modules/disable-define-enable.nix

This file was deleted.

5 changes: 0 additions & 5 deletions lib/tests/modules/disable-enable-modules.nix

This file was deleted.

75 changes: 0 additions & 75 deletions nixos/doc/manual/development/replace-modules.xml

This file was deleted.

1 change: 0 additions & 1 deletion nixos/doc/manual/development/writing-modules.xml
Expand Up @@ -179,6 +179,5 @@ in {
<xi:include href="option-types.xml" />
<xi:include href="option-def.xml" />
<xi:include href="meta-attributes.xml" />
<xi:include href="replace-modules.xml" />

</chapter>
10 changes: 0 additions & 10 deletions nixos/doc/manual/release-notes/rl-1703.xml
Expand Up @@ -261,16 +261,6 @@ following incompatible changes:</para>
</para>
</listitem>

<listitem>
<para>
Modules can now be disabled by using <link
xlink:href="https://nixos.org/nixpkgs/manual/#sec-replace-modules">
disabledModules</link>, allowing another to take it's place. This can be
used to import a set of modules from another channel while keeping the
rest of the system on a stable release.
</para>
</listitem>

<listitem>
<para>
Python 2.7, 3.5 and 3.6 are now built deterministically and 3.4 mostly.
Expand Down

0 comments on commit fcec3e1

Please sign in to comment.