Skip to content

Commit

Permalink
treewide: completely remove types.loaOf
Browse files Browse the repository at this point in the history
  • Loading branch information
rnhmjoj committed Sep 1, 2020
1 parent bfd7069 commit 20d491a
Show file tree
Hide file tree
Showing 26 changed files with 52 additions and 147 deletions.
1 change: 0 additions & 1 deletion lib/modules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,6 @@ rec {
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;
Expand Down
117 changes: 11 additions & 106 deletions lib/types.nix
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ rec {
merge = mergeEqualOption;
};

# drop this in the future:
list = builtins.trace "`types.list` is deprecated; use `types.listOf` instead" types.listOf;
# TODO: drop this in the future:
list = builtins.trace "`types.list` has been removed; please use `types.listOf` instead" types.listOf;

listOf = elemType: mkOptionType rec {
name = "listOf";
Expand Down Expand Up @@ -326,110 +326,15 @@ rec {
functor = (defaultFunctor name) // { wrapped = elemType; };
};

# List or attribute set of ...
loaOf = elemType:
let
convertAllLists = loc: defs:
let
padWidth = stringLength (toString (length defs));
unnamedPrefix = i: "unnamed-" + fixedWidthNumber padWidth i + ".";
in
imap1 (i: convertIfList loc (unnamedPrefix i)) defs;
convertIfList = loc: unnamedPrefix: def:
if isList def.value then
let
padWidth = stringLength (toString (length def.value));
unnamed = i: unnamedPrefix + fixedWidthNumber padWidth i;
anyString = placeholder "name";
nameAttrs = [
{ path = [ "environment" "etc" ];
name = "target";
}
{ path = [ "containers" anyString "bindMounts" ];
name = "mountPoint";
}
{ path = [ "programs" "ssh" "knownHosts" ];
# hostNames is actually a list so we would need to handle it only when singleton
name = "hostNames";
}
{ path = [ "fileSystems" ];
name = "mountPoint";
}
{ path = [ "boot" "specialFileSystems" ];
name = "mountPoint";
}
{ path = [ "services" "znapzend" "zetup" ];
name = "dataset";
}
{ path = [ "services" "znapzend" "zetup" anyString "destinations" ];
name = "label";
}
{ path = [ "services" "geoclue2" "appConfig" ];
name = "desktopID";
}
];
matched = let
equals = a: b: b == anyString || a == b;
fallback = { name = "name"; };
in findFirst ({ path, ... }: all (v: v == true) (zipListsWith equals loc path)) fallback nameAttrs;
nameAttr = matched.name;
nameValueOld = value:
if isList value then
if length value > 0 then
"[ " + concatMapStringsSep " " escapeNixString value + " ]"
else
"[ ]"
else
escapeNixString value;
nameValueNew = value: unnamed:
if isList value then
if length value > 0 then
head value
else
unnamed
else
value;
res =
{ inherit (def) file;
value = listToAttrs (
imap1 (elemIdx: elem:
{ name = nameValueNew (elem.${nameAttr} or (unnamed elemIdx)) (unnamed elemIdx);
value = elem;
}) def.value);
};
option = concatStringsSep "." loc;
sample = take 3 def.value;
more = lib.optionalString (length def.value > 3) "... ";
list = concatMapStrings (x: ''{ ${nameAttr} = ${nameValueOld (x.${nameAttr} or "unnamed")}; ...} '') sample;
set = concatMapStrings (x: ''${nameValueNew (x.${nameAttr} or "unnamed") "unnamed"} = {...}; '') sample;
msg = ''
In file ${def.file}
a list is being assigned to the option config.${option}.
This will soon be an error as type loaOf is deprecated.
See https://github.com/NixOS/nixpkgs/pull/63103 for more information.
Do
${option} =
{ ${set}${more}}
instead of
${option} =
[ ${list}${more}]
'';
in
lib.warn msg res
else
def;
attrOnly = attrsOf elemType;
in mkOptionType rec {
name = "loaOf";
description = "list or attribute set of ${elemType.description}s";
check = x: isList x || isAttrs x;
merge = loc: defs: attrOnly.merge loc (convertAllLists loc defs);
emptyValue = { value = {}; };
getSubOptions = prefix: elemType.getSubOptions (prefix ++ ["<name?>"]);
getSubModules = elemType.getSubModules;
substSubModules = m: loaOf (elemType.substSubModules m);
functor = (defaultFunctor name) // { wrapped = elemType; };
};
# TODO: drop this in the future:
loaOf =
let msg =
''
`types.loaOf` has been removed and mixing lists with attribute values
is no longer possible; please use `types.attrsOf` instead.
See https://github.com/NixOS/nixpkgs/issues/1800 for the motivation.
'';
in builtins.trace msg types.attrsOf;

# Value of given type but with no merging (i.e. `uniq list`s are not concatenated).
uniq = elemType: mkOptionType rec {
Expand Down
11 changes: 0 additions & 11 deletions nixos/doc/manual/development/option-types.xml
Original file line number Diff line number Diff line change
Expand Up @@ -385,17 +385,6 @@
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<varname>types.loaOf</varname> <replaceable>t</replaceable>
</term>
<listitem>
<para>
An attribute set or a list of <replaceable>t</replaceable> type. Multiple
definitions are merged according to the value.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<varname>types.nullOr</varname> <replaceable>t</replaceable>
Expand Down
12 changes: 12 additions & 0 deletions nixos/doc/manual/release-notes/rl-2009.xml
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,18 @@ CREATE ROLE postgres LOGIN SUPERUSER;
See <link xlink:href="https://github.com/NixOS/nixpkgs/pull/82743#issuecomment-674520472">the PR that changed this</link> for more info.
</para>
</listitem>
<listitem>
<para>
For NixOS configuration options, the type <literal>loaOf</literal>, after
its initial deprecation in release 20.03, has been removed. In NixOS and
Nixpkgs options using this type have been converted to <literal>attrsOf</literal>.
</para>
<para>
For more information on this change have look at these links:
<link xlink:href="https://github.com/NixOS/nixpkgs/issues/1800">issue #1800</link>,
<link xlink:href="https://github.com/NixOS/nixpkgs/pull/63103">PR #63103</link>.
</para>
</listitem>
</itemizedlist>
</section>

Expand Down
4 changes: 2 additions & 2 deletions nixos/modules/config/users-groups.nix
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ in {

users.users = mkOption {
default = {};
type = with types; loaOf (submodule userOpts);
type = with types; attrsOf (submodule userOpts);
example = {
alice = {
uid = 1234;
Expand All @@ -487,7 +487,7 @@ in {
{ students.gid = 1001;
hackers = { };
};
type = with types; loaOf (submodule groupOpts);
type = with types; attrsOf (submodule groupOpts);
description = ''
Additional groups to be created automatically by the system.
'';
Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/installer/cd-dvd/sd-image-raspberrypi4.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
};

fileSystems."/boot/firmware" = {
# This effectively "renames" the loaOf entry set in sd-image.nix
# This effectively "renames" the attrsOf entry set in sd-image.nix
mountPoint = "/boot";
neededForBoot = true;
};
Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/installer/tools/nixos-option/nixos-option.cc
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ bool optionTypeIs(Context & ctx, Value & v, const std::string & soughtType)

bool isAggregateOptionType(Context & ctx, Value & v)
{
return optionTypeIs(ctx, v, "attrsOf") || optionTypeIs(ctx, v, "listOf") || optionTypeIs(ctx, v, "loaOf");
return optionTypeIs(ctx, v, "attrsOf") || optionTypeIs(ctx, v, "listOf");
}

MakeError(OptionPathError, EvalError);
Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/programs/ssh.nix
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ in

knownHosts = mkOption {
default = {};
type = types.loaOf (types.submodule ({ name, ... }: {
type = types.attrsOf (types.submodule ({ name, ... }: {
options = {
certAuthority = mkOption {
type = types.bool;
Expand Down
4 changes: 2 additions & 2 deletions nixos/modules/programs/tsm-client.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let
inherit (lib.modules) mkDefault mkIf;
inherit (lib.options) literalExample mkEnableOption mkOption;
inherit (lib.strings) concatStringsSep optionalString toLower;
inherit (lib.types) addCheck attrsOf lines loaOf nullOr package path port str strMatching submodule;
inherit (lib.types) addCheck attrsOf lines nullOr package path port str strMatching submodule;

# Checks if given list of strings contains unique
# elements when compared without considering case.
Expand Down Expand Up @@ -178,7 +178,7 @@ let
client system-options file "dsm.sys"
'';
servers = mkOption {
type = loaOf (submodule [ serverOptions ]);
type = attrsOf (submodule [ serverOptions ]);
default = {};
example.mainTsmServer = {
server = "tsmserver.company.com";
Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/security/pam.nix
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ in

security.pam.services = mkOption {
default = [];
type = with types; loaOf (submodule pamOpts);
type = with types; attrsOf (submodule pamOpts);
description =
''
This option defines the PAM services. A service typically
Expand Down
4 changes: 2 additions & 2 deletions nixos/modules/services/backup/znapzend.nix
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ let
};

destinations = mkOption {
type = loaOf (destType config);
type = attrsOf (destType config);
description = "Additional destinations.";
default = {};
example = literalExample ''
Expand Down Expand Up @@ -328,7 +328,7 @@ in
};

zetup = mkOption {
type = loaOf srcType;
type = attrsOf srcType;
description = "Znapzend configuration.";
default = {};
example = literalExample ''
Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/services/desktops/geoclue2.nix
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ in
};

appConfig = mkOption {
type = types.loaOf appConfigModule;
type = types.attrsOf appConfigModule;
default = {};
example = literalExample ''
"com.github.app" = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ in
{ office1 = { model = "MFC-7860DW"; ip = "192.168.1.2"; };
office2 = { model = "MFC-7860DW"; nodename = "BRW0080927AFBCE"; };
};
type = with types; loaOf (submodule netDeviceOpts);
type = with types; attrsOf (submodule netDeviceOpts);
description = ''
The list of network devices that will be registered against the brscan4
sane backend.
Expand Down
4 changes: 2 additions & 2 deletions nixos/modules/services/networking/hylafax/options.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
let

inherit (lib.options) literalExample mkEnableOption mkOption;
inherit (lib.types) bool enum int lines loaOf nullOr path str submodule;
inherit (lib.types) bool enum int lines attrsOf nullOr path str submodule;
inherit (lib.modules) mkDefault mkIf mkMerge;

commonDescr = ''
Expand Down Expand Up @@ -248,7 +248,7 @@ in
};

modems = mkOption {
type = loaOf (submodule [ modemConfigOptions ]);
type = attrsOf (submodule [ modemConfigOptions ]);
default = {};
example.ttyS1 = {
type = "cirrus";
Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/services/networking/nylon.nix
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ in
services.nylon = mkOption {
default = {};
description = "Collection of named nylon instances";
type = with types; loaOf (submodule nylonOpts);
type = with types; attrsOf (submodule nylonOpts);
internal = true;
};

Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/services/networking/prosody.nix
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ in

description = "Define the virtual hosts";

type = with types; loaOf (submodule vHostOpts);
type = with types; attrsOf (submodule vHostOpts);

example = {
myhost = {
Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/services/networking/ssh/sshd.nix
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ in
};

users.users = mkOption {
type = with types; loaOf (submodule userOptions);
type = with types; attrsOf (submodule userOptions);
};

};
Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/services/security/tor.nix
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ in
];
}
'';
type = types.loaOf (types.submodule ({name, ...}: {
type = types.attrsOf (types.submodule ({name, ...}: {
options = {

name = mkOption {
Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/system/boot/luksroot.nix
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ in
<filename>/dev/mapper/<replaceable>name</replaceable></filename>.
'';

type = with types; loaOf (submodule (
type = with types; attrsOf (submodule (
{ name, ... }: { options = {

name = mkOption {
Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/system/boot/stage-1.nix
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ in
};

fileSystems = mkOption {
type = with lib.types; loaOf (submodule {
type = with lib.types; attrsOf (submodule {
options.neededForBoot = mkOption {
default = false;
type = types.bool;
Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/system/etc/etc.nix
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ in
Set of files that have to be linked in <filename>/etc</filename>.
'';

type = with types; loaOf (submodule (
type = with types; attrsOf (submodule (
{ name, config, ... }:
{ options = {

Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/tasks/encrypted-devices.nix
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ in

options = {
fileSystems = mkOption {
type = with lib.types; loaOf (submodule encryptedFSOptions);
type = with lib.types; attrsOf (submodule encryptedFSOptions);
};
swapDevices = mkOption {
type = with lib.types; listOf (submodule encryptedFSOptions);
Expand Down
4 changes: 2 additions & 2 deletions nixos/modules/tasks/filesystems.nix
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ in
"/bigdisk".label = "bigdisk";
}
'';
type = types.loaOf (types.submodule [coreFileSystemOpts fileSystemOpts]);
type = types.attrsOf (types.submodule [coreFileSystemOpts fileSystemOpts]);
description = ''
The file systems to be mounted. It must include an entry for
the root directory (<literal>mountPoint = "/"</literal>). Each
Expand Down Expand Up @@ -193,7 +193,7 @@ in

boot.specialFileSystems = mkOption {
default = {};
type = types.loaOf (types.submodule coreFileSystemOpts);
type = types.attrsOf (types.submodule coreFileSystemOpts);
internal = true;
description = ''
Special filesystems that are mounted very early during boot.
Expand Down
Loading

0 comments on commit 20d491a

Please sign in to comment.