git.iko.soy/typeable/nixpkgs
on master help sign in
Revert "modules: add support for module replacement with disabledModules"

This reverts commit 3f2566689d14f1d7778d55ca807d1dad2f4695d1 for now. Evaluation of the tested job got broken, blocking nixos-unstable.

commitfcec3e1c72ad7ac7eaacd00c8fc87dc04696fdb0 authorVladimír Čunát <vcunat@gmail.com> dateWed 1 Mar 2017, 18:20 (10 years ago) parent4150920
9 files changed+7−127
lib/modules.nix+7−17 lib/tests/modules.sh−8 lib/tests/modules/default.nix−1 lib/tests/modules/disable-declare-enable.nix−5 lib/tests/modules/disable-define-enable.nix−5 lib/tests/modules/disable-enable-modules.nix−5 nixos/doc/manual/development/replace-modules.xml−75 nixos/doc/manual/development/writing-modules.xml−1 nixos/doc/manual/release-notes/rl-1703.xml−10
lib/modules.nix+7−17
@@ -20,8 +20,7 @@ rec {
2020 , prefix ? []
2121 , # This should only be used for special arguments that need to be evaluated
2222 # when resolving module structure (like in imports). For everything else,
23− # there's _module.args. If specialArgs.modulesPath is defined it will be
24− # used as the base path for disabledModules.
23+ # there's _module.args.
2524 specialArgs ? {}
2625 , # This would be remove in the future, Prefer _module.args option instead.
2726 args ? {}
@@ -59,7 +58,10 @@ rec {
5958
6059 closed = closeModules (modules ++ [ internalModule ]) ({ inherit config options; lib = import ./.; } // specialArgs);
6160
62− options = mergeModules prefix (filterModules (specialArgs.modulesPath or "") closed);
61+ # Note: the list of modules is reversed to maintain backward
62+ # compatibility with the old module system. Not sure if this is
63+ # the most sensible policy.
64+ options = mergeModules prefix (reverseList closed);
6365
6466 # Traverse options and extract the option values into the final
6567 # config set. At the same time, check whether all option
@@ -85,16 +87,6 @@ rec {
8587 result = { inherit options config; };
8688 in result;
8789
88−
89− # Filter disabled modules. Modules can be disabled allowing
90− # their implementation to be replaced.
91− filterModules = modulesPath: modules:
92− let
93− moduleKey = m: if isString m then toString modulesPath + "/" + m else toString m;
94− disabledKeys = map moduleKey (concatMap (m: m.disabledModules) modules);
95− in
96− filter (m: !(elem m.key disabledKeys)) modules;
97−
9890 /* Close a set of modules under the ‘imports’ relation. */
9991 closeModules = modules: args:
10092 let
@@ -119,13 +111,12 @@ rec {
119111 else {};
120112 in
121113 if m ? config || m ? options then
122− let badAttrs = removeAttrs m ["_file" "key" "disabledModules" "imports" "options" "config" "meta"]; in
114+ let badAttrs = removeAttrs m ["imports" "options" "config" "key" "_file" "meta"]; in
123115 if badAttrs != {} then
124116 throw "Module `${key}' has an unsupported attribute `${head (attrNames badAttrs)}'. This is caused by assignments to the top-level attributes `config' or `options'."
125117 else
126118 { file = m._file or file;
127119 key = toString m.key or key;
128− disabledModules = m.disabledModules or [];
129120 imports = m.imports or [];
130121 options = m.options or {};
131122 config = mkMerge [ (m.config or {}) metaSet ];
@@ -133,10 +124,9 @@ rec {
133124 else
134125 { file = m._file or file;
135126 key = toString m.key or key;
136− disabledModules = m.disabledModules or [];
137127 imports = m.require or [] ++ m.imports or [];
138128 options = {};
139− config = mkMerge [ (removeAttrs m ["_file" "key" "disabledModules" "require" "imports"]) metaSet ];
129+ config = mkMerge [ (removeAttrs m ["key" "_file" "require" "imports"]) metaSet ];
140130 };
141131
142132 applyIfFunction = key: f: args@{ config, options, lib, ... }: if isFunction f then
lib/tests/modules.sh−8
@@ -99,14 +99,6 @@ checkConfigOutput 'true' "$@" ./define-enable.nix ./define-loaOfSub-if-foo-enabl
9999checkConfigOutput 'true' "$@" ./define-enable.nix ./define-loaOfSub-foo-if-enable.nix
100100checkConfigOutput 'true' "$@" ./define-enable.nix ./define-loaOfSub-foo-enable-if.nix
101101
102−# Check disabledModules with config definitions and option declarations.
103−set -- config.enable ./define-enable.nix ./declare-enable.nix
104−checkConfigOutput "true" "$@"
105−checkConfigOutput "false" "$@" ./disable-define-enable.nix
106−checkConfigError "The option .*enable.* defined in .* does not exist" "$@" ./disable-declare-enable.nix
107−checkConfigError "attribute .*enable.* in selection path .*config.enable.* not found" "$@" ./disable-define-enable.nix ./disable-declare-enable.nix
108−checkConfigError "attribute .*enable.* in selection path .*config.enable.* not found" "$@" ./disable-enable-modules.nix
109−
110102# Check _module.args.
111103set -- config.enable ./declare-enable.nix ./define-enable-with-custom-arg.nix
112104checkConfigError 'while evaluating the module argument .*custom.* in .*define-enable-with-custom-arg.nix.*:' "$@"
lib/tests/modules/default.nix−1
@@ -3,6 +3,5 @@
33{
44 inherit (lib.evalModules {
55 inherit modules;
6− specialArgs.modulesPath = ./.;
76 }) config options;
87}
lib/tests/modules/disable-declare-enable.nixdeleted−5
@@ -1,5 +0,0 @@
1−{ lib, ... }:
2−
3−{
4− disabledModules = [ ./declare-enable.nix ];
5−}
lib/tests/modules/disable-define-enable.nixdeleted−5
@@ -1,5 +0,0 @@
1−{ lib, ... }:
2−
3−{
4− disabledModules = [ ./define-enable.nix ];
5−}
lib/tests/modules/disable-enable-modules.nixdeleted−5
@@ -1,5 +0,0 @@
1−{ lib, ... }:
2−
3−{
4− disabledModules = [ "define-enable.nix" "declare-enable.nix" ];
5−}
nixos/doc/manual/development/replace-modules.xmldeleted−75
@@ -1,75 +0,0 @@
1−<section xmlns="http://docbook.org/ns/docbook"
2− xmlns:xlink="http://www.w3.org/1999/xlink"
3− xmlns:xi="http://www.w3.org/2001/XInclude"
4− version="5.0"
5− xml:id="sec-replace-modules">
6−
7−<title>Replace Modules</title>
8−
9−<para>Modules that are imported can also be disabled. The option
10− declarations and config implementation of a disabled module will be
11− ignored, allowing another to take it's place. This can be used to
12− import a set of modules from another channel while keeping the rest
13− of the system on a stable release.</para>
14−<para><literal>disabledModules</literal> is a top level attribute like
15− <literal>imports</literal>, <literal>options</literal> and
16− <literal>config</literal>. It contains a list of modules that will
17− be disabled. This can either be the full path to the module or a
18− string with the filename relative to the modules path
19− (eg. &lt;nixpkgs/nixos/modules&gt; for nixos).
20− </para>
21−
22−<para>This example will replace the existing postgresql module with
23− the version defined in the nixos-unstable channel while keeping the
24− rest of the modules and packages from the original nixos channel.
25− This only overrides the module definition, this won't use postgresql
26− from nixos-unstable unless explicitly configured to do so.</para>
27−
28−<programlisting>
29−{ config, lib, pkgs, ... }:
30−
31−{
32− disabledModules = [ "services/databases/postgresql.nix" ];
33−
34− imports =
35− [ # Use postgresql service from nixos-unstable channel.
36− # sudo nix-channel --add http://nixos.org/channels/nixos-unstable nixos-unstable
37− &lt;nixos-unstable/nixos/modules/services/databases/postgresql.nix&gt;
38− ];
39−
40− services.postgresql.enable = true;
41−}
42−</programlisting>
43−
44−<para>This example shows how to define a custom module as a
45− replacement for an existing module. Importing this module will
46− disable the original module without having to know it's
47− implementation details.</para>
48−
49−<programlisting>
50−{ config, lib, pkgs, ... }:
51−
52−with lib;
53−
54−let
55− cfg = config.programs.man;
56−in
57−
58−{
59− disabledModules = [ "services/programs/man.nix" ];
60−
61− options = {
62− programs.man.enable = mkOption {
63− type = types.bool;
64− default = true;
65− description = "Whether to enable manual pages.";
66− };
67− };
68−
69− config = mkIf cfg.enabled {
70− warnings = [ "disabled manpages for production deployments." ];
71− };
72−}
73−</programlisting>
74−
75−</section>
nixos/doc/manual/development/writing-modules.xml−1
@@ -179,6 +179,5 @@ in {
179179<xi:include href="option-types.xml" />
180180<xi:include href="option-def.xml" />
181181<xi:include href="meta-attributes.xml" />
182−<xi:include href="replace-modules.xml" />
183182
184183</chapter>
nixos/doc/manual/release-notes/rl-1703.xml−10
@@ -261,16 +261,6 @@ following incompatible changes:</para>
261261 </para>
262262 </listitem>
263263
264− <listitem>
265− <para>
266− Modules can now be disabled by using <link
267− xlink:href="https://nixos.org/nixpkgs/manual/#sec-replace-modules">
268− disabledModules</link>, allowing another to take it's place. This can be
269− used to import a set of modules from another channel while keeping the
270− rest of the system on a stable release.
271− </para>
272− </listitem>
273−
274264 <listitem>
275265 <para>
276266 Python 2.7, 3.5 and 3.6 are now built deterministically and 3.4 mostly.