nixos-config/components/mainUser.nix
2024-08-02 14:42:11 +02:00

83 lines
1.6 KiB
Nix

{ config, pkgs, lib, ... }:
with lib;
with types;
let
cfg = config.components.mainUser;
dockerGroup =
if (config.virtualisation.docker.enable) then [ "docker" ] else [ ];
vboxGroup =
if (config.virtualisation.virtualbox.host.enable) then
[ "vboxusers" ]
else
[ ];
in
{
options.components.mainUser = {
enable = mkEnableOption "enable mainUser for a system";
userName = mkOption {
type = str;
default = "palo";
description = ''
name of the main user
'';
};
uid = mkOption {
type = int;
default = 1337;
description = ''
uid of main user
'';
};
extraGroups = mkOption {
default = [ ];
type = listOf str;
description = ''
list of groups the main user should also be in
'';
};
authorizedKeyFiles = mkOption {
default = [ ];
type = listOf str;
description = ''
list of keys allowed to login as this user
'';
};
};
config = mkIf cfg.enable {
users = {
mutableUsers = lib.mkDefault true;
defaultUserShell = pkgs.zsh;
groups.mainUser.name = cfg.userName;
users.mainUser = {
isNormalUser = true;
name = cfg.userName;
uid = cfg.uid;
home = "/home/${cfg.userName}";
initialPassword = cfg.userName;
extraGroups = [ "wheel" "networkmanager" "transmission" "wireshark" "audio" "pipewire" "input" "dialout" ]
++ dockerGroup ++ vboxGroup ++ cfg.extraGroups;
openssh.authorizedKeys.keyFiles = cfg.authorizedKeyFiles;
group = config.users.groups.mainUser.name;
};
};
};
}