Simplify configuring users
This commit is contained in:
parent
bdea1aa785
commit
47802f7450
3 changed files with 54 additions and 0 deletions
|
@ -50,6 +50,7 @@
|
|||
keyMap = "us";
|
||||
keyboardLayout = "us";
|
||||
localeSettings = { };
|
||||
users = { };
|
||||
};
|
||||
systems = {
|
||||
nixos.config = { ... }: {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
imports = [
|
||||
./modules/custom-build-vm.nix
|
||||
./modules/custom-sops-nix.nix
|
||||
./modules/my-users.nix
|
||||
];
|
||||
|
||||
config = {
|
||||
|
@ -23,6 +24,8 @@
|
|||
vmVariantWithBootLoader = vmConfig;
|
||||
};
|
||||
|
||||
users.myUsers = machineConfig.users;
|
||||
|
||||
# Networking
|
||||
networking.hostName = machineConfig.name;
|
||||
|
||||
|
|
50
lib/modules/my-users.nix
Normal file
50
lib/modules/my-users.nix
Normal file
|
@ -0,0 +1,50 @@
|
|||
{ 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;
|
||||
};
|
||||
|
||||
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;
|
||||
extraGroups = lib.mkIf user.sudoer [
|
||||
"wheel"
|
||||
];
|
||||
})
|
||||
config.users.myUsers;
|
||||
};
|
||||
}
|
Loading…
Reference in a new issue