Merge pull request #179002 from klemensn/move-passwdEntry-type

move passwdEntry type
This commit is contained in:
Florian Klink 2022-07-22 14:16:57 +07:00 committed by GitHub
commit 7c119675a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 12 deletions

View file

@ -55,6 +55,7 @@ let
concatMapStringsSep
concatStringsSep
escapeNixString
hasInfix
isCoercibleToString
;
inherit (lib.trivial)
@ -360,6 +361,11 @@ rec {
deprecationMessage = "See https://github.com/NixOS/nixpkgs/pull/66346 for better alternative types.";
};
passwdEntry = entryType: addCheck entryType (str: !(hasInfix ":" str || hasInfix "\n" str)) // {
name = "passwdEntry ${entryType.name}";
description = "${entryType.description}, not containing newlines or colons";
};
attrs = mkOptionType {
name = "attrs";
description = "attribute set";

View file

@ -6,12 +6,6 @@ let
ids = config.ids;
cfg = config.users;
isPasswdCompatible = str: !(hasInfix ":" str || hasInfix "\n" str);
passwdEntry = type: lib.types.addCheck type isPasswdCompatible // {
name = "passwdEntry ${type.name}";
description = "${type.description}, not containing newlines or colons";
};
# Check whether a password hash will allow login.
allowsLogin = hash:
hash == "" # login without password
@ -60,7 +54,7 @@ let
options = {
name = mkOption {
type = passwdEntry types.str;
type = types.passwdEntry types.str;
apply = x: assert (builtins.stringLength x < 32 || abort "Username '${x}' is longer than 31 characters which is not allowed!"); x;
description = ''
The name of the user account. If undefined, the name of the
@ -69,7 +63,7 @@ let
};
description = mkOption {
type = passwdEntry types.str;
type = types.passwdEntry types.str;
default = "";
example = "Alice Q. User";
description = ''
@ -134,7 +128,7 @@ let
};
home = mkOption {
type = passwdEntry types.path;
type = types.passwdEntry types.path;
default = "/var/empty";
description = "The user's home directory.";
};
@ -169,7 +163,7 @@ let
};
shell = mkOption {
type = types.nullOr (types.either types.shellPackage (passwdEntry types.path));
type = types.nullOr (types.either types.shellPackage (types.passwdEntry types.path));
default = pkgs.shadow;
defaultText = literalExpression "pkgs.shadow";
example = literalExpression "pkgs.bashInteractive";
@ -349,7 +343,7 @@ let
options = {
name = mkOption {
type = passwdEntry types.str;
type = types.passwdEntry types.str;
description = ''
The name of the group. If undefined, the name of the attribute set
will be used.

View file

@ -192,7 +192,7 @@ in {
};
emergencyAccess = mkOption {
type = with types; oneOf [ bool singleLineStr ];
type = with types; oneOf [ bool (nullOr (passwdEntry str)) ];
visible = false;
description = ''
Set to true for unauthenticated emergency access, and false for