Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 16 additions & 29 deletions lib/modules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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’.
Expand Down Expand Up @@ -362,7 +364,6 @@ rec {
values = defs''';
inherit (defs'') highestPrio;
};

defsFinal = defsFinal'.values;

# Type-check the remaining definitions, and merge them.
Expand Down Expand Up @@ -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 = []; };


Expand Down
2 changes: 0 additions & 2 deletions lib/options.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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"; };

Expand Down
8 changes: 2 additions & 6 deletions lib/types.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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; };
Expand Down
8 changes: 8 additions & 0 deletions nixos/doc/manual/release-notes/rl-1903.xml
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,14 @@
for details.
</para>
</listitem>
<listitem>
<para>
Support for NixOS module system type <literal>types.optionSet</literal> and
<literal>lib.mkOption</literal> argument <literal>options</literal> is removed.
Use <literal>types.submodule</literal> instead.
(<link xlink:href="https://github.com/NixOS/nixpkgs/pull/54637">#54637</link>)
</para>
</listitem>
</itemizedlist>
</section>

Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/profiles/minimal.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ with lib;

documentation.enable = mkDefault false;

services.nixosManual.enable = mkDefault false;
documentation.nixos.enable = mkDefault false;
}
1 change: 0 additions & 1 deletion nixos/modules/services/networking/nylon.nix
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ in
description = "Collection of named nylon instances";
type = with types; loaOf (submodule nylonOpts);
internal = true;
options = [ nylonOpts ];
};

};
Expand Down
4 changes: 2 additions & 2 deletions nixos/modules/services/networking/ssh/sshd.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let

userOptions = {

openssh.authorizedKeys = {
options.openssh.authorizedKeys = {
keys = mkOption {
type = types.listOf types.str;
default = [];
Expand Down Expand Up @@ -320,7 +320,7 @@ in
};

users.users = mkOption {
options = [ userOptions ];
type = with types; loaOf (submodule userOptions);
};

};
Expand Down
22 changes: 12 additions & 10 deletions nixos/modules/system/boot/stage-1.nix
Original file line number Diff line number Diff line change
Expand Up @@ -525,16 +525,18 @@ in
};

fileSystems = mkOption {
options.neededForBoot = mkOption {
default = false;
type = types.bool;
description = ''
If set, this file system will be mounted in the initial
ramdisk. By default, this applies to the root file system
and to the file system containing
<filename>/nix/store</filename>.
'';
};
type = with lib.types; loaOf (submodule {
options.neededForBoot = mkOption {
default = false;
type = types.bool;
description = ''
If set, this file system will be mounted in the initial
ramdisk. By default, this applies to the root file system
and to the file system containing
<filename>/nix/store</filename>.
'';
};
});
};

};
Expand Down
12 changes: 6 additions & 6 deletions nixos/modules/tasks/encrypted-devices.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@ let

encryptedFSOptions = {

encrypted = {
options.encrypted = {
enable = mkOption {
default = false;
type = types.bool;
description = "The block device is backed by an encrypted one, adds this device as a initrd luks entry.";
};

blkDev = mkOption {
options.blkDev = mkOption {
default = null;
example = "/dev/sda1";
type = types.nullOr types.str;
description = "Location of the backing encrypted device.";
};

label = mkOption {
options.label = mkOption {
default = null;
example = "rootfs";
type = types.nullOr types.str;
description = "Label of the unlocked encrypted device. Set <literal>fileSystems.&lt;name?&gt;.device</literal> to <literal>/dev/mapper/&lt;label&gt;</literal> to mount the unlocked device.";
};

keyFile = mkOption {
options.keyFile = mkOption {
default = null;
example = "/mnt-root/root/.swapkey";
type = types.nullOr types.str;
Expand All @@ -47,10 +47,10 @@ in

options = {
fileSystems = mkOption {
options = [encryptedFSOptions];
type = with lib.types; loaOf (submodule encryptedFSOptions);
};
swapDevices = mkOption {
options = [encryptedFSOptions];
type = with lib.types; listOf (submodule encryptedFSOptions);
};
};

Expand Down
25 changes: 13 additions & 12 deletions nixos/modules/testing/service-runner.nix
Original file line number Diff line number Diff line change
Expand Up @@ -92,23 +92,24 @@ let
exit($mainRes & 127 ? 255 : $mainRes << 8);
'';

opts = { config, name, ... }: {
options.runner = mkOption {
internal = true;
description = ''
A script that runs the service outside of systemd,
useful for testing or for using NixOS services outside
of NixOS.
'';
};
config.runner = makeScript name config;
};

in

{
options = {
systemd.services = mkOption {
options =
{ config, name, ... }:
{ options.runner = mkOption {
internal = true;
description = ''
A script that runs the service outside of systemd,
useful for testing or for using NixOS services outside
of NixOS.
'';
};
config.runner = makeScript name config;
};
type = with types; attrsOf (submodule opts);
};
};
}