nixos-config/components/mainUser.nix

98 lines
1.8 KiB
Nix
Raw Normal View History

2024-08-29 03:26:04 +02:00
{
config,
pkgs,
lib,
...
}:
2019-10-24 02:20:38 +02:00
with lib;
2023-06-01 14:02:57 +02:00
with types;
2019-10-24 02:20:38 +02:00
let
2023-06-01 14:02:57 +02:00
cfg = config.components.mainUser;
2019-10-24 02:20:38 +02:00
2024-08-11 14:46:03 +02:00
# todo : use optionalList
2024-08-29 03:26:04 +02:00
dockerGroup = if (config.virtualisation.docker.enable) then [ "docker" ] else [ ];
2019-10-24 02:20:38 +02:00
2024-08-11 14:46:03 +02:00
# todo : use optionalList
2024-08-29 03:26:04 +02:00
vboxGroup = if (config.virtualisation.virtualbox.host.enable) then [ "vboxusers" ] else [ ];
2021-11-01 09:20:42 +01:00
in
{
2019-10-24 02:20:38 +02:00
2023-06-01 14:02:57 +02:00
options.components.mainUser = {
2019-10-24 02:20:38 +02:00
2023-06-01 14:02:57 +02:00
enable = mkEnableOption "enable mainUser for a system";
2019-10-24 02:20:38 +02:00
userName = mkOption {
2023-06-01 14:02:57 +02:00
type = str;
default = "palo";
2019-10-24 02:20:38 +02:00
description = ''
name of the main user
'';
};
uid = mkOption {
2023-06-01 14:02:57 +02:00
type = int;
2019-10-24 02:20:38 +02:00
default = 1337;
description = ''
uid of main user
'';
};
extraGroups = mkOption {
2019-12-20 05:54:26 +01:00
default = [ ];
2023-06-01 14:02:57 +02:00
type = listOf str;
2019-10-24 02:20:38 +02:00
description = ''
list of groups the main user should also be in
'';
};
authorizedKeyFiles = mkOption {
2019-12-20 05:54:26 +01:00
default = [ ];
2023-06-01 14:02:57 +02:00
type = listOf str;
2019-10-24 02:20:38 +02:00
description = ''
list of keys allowed to login as this user
'';
};
};
config = mkIf cfg.enable {
users = {
2024-02-16 22:21:05 +01:00
mutableUsers = lib.mkDefault true;
2023-06-01 12:08:59 +02:00
2019-10-24 02:20:38 +02:00
defaultUserShell = pkgs.zsh;
2023-06-01 12:08:59 +02:00
groups.mainUser.name = cfg.userName;
2019-10-24 02:20:38 +02:00
users.mainUser = {
2019-12-20 05:54:26 +01:00
isNormalUser = true;
name = cfg.userName;
uid = cfg.uid;
home = "/home/${cfg.userName}";
2019-10-24 02:20:38 +02:00
initialPassword = cfg.userName;
2024-12-06 15:57:35 +01:00
extraGroups =
[
"wheel"
"networkmanager"
"transmission"
"wireshark"
"audio"
"pipewire"
"input"
"dialout"
]
++ dockerGroup
++ vboxGroup
++ cfg.extraGroups;
2019-12-20 05:54:26 +01:00
openssh.authorizedKeys.keyFiles = cfg.authorizedKeyFiles;
2023-01-07 21:11:25 +01:00
group = config.users.groups.mainUser.name;
};
2019-10-24 02:20:38 +02:00
};
2023-07-02 20:56:42 +02:00
2019-10-24 02:20:38 +02:00
};
}