mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-11-13 21:32:23 +03:00
nixos/tsm-client: drop own checkIUnique
for allUnique
This commit is contained in:
parent
363cf1e363
commit
fe96d79adf
@ -2,23 +2,13 @@
|
||||
|
||||
let
|
||||
|
||||
inherit (builtins) length map;
|
||||
inherit (lib.attrsets) attrNames filterAttrs hasAttr mapAttrs mapAttrsToList optionalAttrs;
|
||||
inherit (lib.lists) allUnique map;
|
||||
inherit (lib.modules) mkDefault mkIf;
|
||||
inherit (lib.options) literalExpression mkEnableOption mkOption mkPackageOption;
|
||||
inherit (lib.strings) concatLines optionalString toLower;
|
||||
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.
|
||||
servernameType = strMatching ".{1,64}";
|
||||
|
||||
@ -110,7 +100,7 @@ let
|
||||
# differ only by upper and lower case.
|
||||
type = addCheck
|
||||
(attrsOf (nullOr str))
|
||||
(attrs: checkIUnique (attrNames attrs));
|
||||
(attrs: allUnique (map toLower (attrNames attrs)));
|
||||
default = {};
|
||||
example.compression = "yes";
|
||||
example.passwordaccess = null;
|
||||
@ -238,7 +228,7 @@ let
|
||||
|
||||
assertions = [
|
||||
{
|
||||
assertion = checkIUnique (mapAttrsToList (k: v: v.name) cfg.servers);
|
||||
assertion = allUnique (mapAttrsToList (k: v: toLower v.name) cfg.servers);
|
||||
message = ''
|
||||
TSM servernames contain duplicate name
|
||||
(note that case doesn't matter!)
|
||||
|
Loading…
Reference in New Issue
Block a user