nixos/tsm-client: drop own checkIUnique for allUnique

This commit is contained in:
Yarny0 2023-11-18 12:22:46 +01:00
parent 363cf1e363
commit fe96d79adf

View File

@ -2,23 +2,13 @@
let let
inherit (builtins) length map;
inherit (lib.attrsets) attrNames filterAttrs hasAttr mapAttrs mapAttrsToList optionalAttrs; inherit (lib.attrsets) attrNames filterAttrs hasAttr mapAttrs mapAttrsToList optionalAttrs;
inherit (lib.lists) allUnique map;
inherit (lib.modules) mkDefault mkIf; inherit (lib.modules) mkDefault mkIf;
inherit (lib.options) literalExpression mkEnableOption mkOption mkPackageOption; inherit (lib.options) literalExpression mkEnableOption mkOption mkPackageOption;
inherit (lib.strings) concatLines optionalString toLower; inherit (lib.strings) concatLines optionalString toLower;
inherit (lib.types) addCheck attrsOf lines nonEmptyStr nullOr path port str strMatching submodule; inherit (lib.types) addCheck attrsOf lines nonEmptyStr nullOr path port str strMatching submodule;
# Checks if given list of strings contains unique
# elements when compared without considering case.
# Type: checkIUnique :: [string] -> bool
# Example: checkIUnique ["foo" "Foo"] => false
checkIUnique = lst:
let
lenUniq = l: length (lib.lists.unique l);
in
lenUniq lst == lenUniq (map toLower lst);
# TSM rejects servername strings longer than 64 chars. # TSM rejects servername strings longer than 64 chars.
servernameType = strMatching ".{1,64}"; servernameType = strMatching ".{1,64}";
@ -110,7 +100,7 @@ let
# differ only by upper and lower case. # differ only by upper and lower case.
type = addCheck type = addCheck
(attrsOf (nullOr str)) (attrsOf (nullOr str))
(attrs: checkIUnique (attrNames attrs)); (attrs: allUnique (map toLower (attrNames attrs)));
default = {}; default = {};
example.compression = "yes"; example.compression = "yes";
example.passwordaccess = null; example.passwordaccess = null;
@ -238,7 +228,7 @@ let
assertions = [ assertions = [
{ {
assertion = checkIUnique (mapAttrsToList (k: v: v.name) cfg.servers); assertion = allUnique (mapAttrsToList (k: v: toLower v.name) cfg.servers);
message = '' message = ''
TSM servernames contain duplicate name TSM servernames contain duplicate name
(note that case doesn't matter!) (note that case doesn't matter!)