NixOSConfig/lib/modules/my-users.nix

58 lines
1.4 KiB
Nix
Raw Normal View History

2024-05-07 20:02:12 +00:00
{ config, lib, ... }:
let
userType = lib.types.submodule {
options = {
fullName = lib.mkOption {
type = lib.types.nullOr lib.types.str;
description = lib.mdDoc "The full name of the user.";
default = null;
};
2024-05-08 23:56:30 +00:00
mail = lib.mkOption {
type = lib.types.nullOr lib.types.mail;
description = lib.mdDoc "The mail address of the user.";
default = null;
};
2024-05-07 20:02:12 +00:00
defaultShell = lib.mkOption {
type = lib.types.anything;
description = "The default shell of the user.";
default = null;
};
sudoer = lib.mkOption {
type = lib.types.bool;
description = lib.mdDoc "Enable `sudo` commands for this user.";
default = false;
};
};
};
in {
options = {
users.myUsers = lib.mkOption {
type = lib.types.attrsOf userType;
description = lib.mdDoc "The users for the system to create.";
default = {};
};
};
config = {
users.users = builtins.mapAttrs
(
name: user: {
description = lib.mkIf
(user.fullName != null)
user.fullName;
isNormalUser = true;
shell = lib.mkIf
(user.defaultShell != null)
user.defaultShell;
2024-05-02 02:23:57 +00:00
hashedPasswordFile = config.sops.secrets.default_password.path;
2024-05-07 20:02:12 +00:00
extraGroups = lib.mkIf user.sudoer [
"wheel"
];
})
config.users.myUsers;
};
}