WIP refactor
This commit is contained in:
parent
6381cb0ea1
commit
7e7f04574b
13 changed files with 1150 additions and 166 deletions
58
common/users/default.nix
Normal file
58
common/users/default.nix
Normal file
|
@ -0,0 +1,58 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
let
|
||||
ccfg = import ../config.nix;
|
||||
cfg_path = [
|
||||
ccfg.custom_config_key
|
||||
"users"
|
||||
];
|
||||
cfg = lib.attrsets.getAttrFromPath cfg_path config;
|
||||
top_cfg = config.${ccfg.custom_config_key};
|
||||
in
|
||||
{
|
||||
options =
|
||||
{ }
|
||||
// lib.attrsets.setAttrByPath cfg_path {
|
||||
admins = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.str;
|
||||
default = [ ];
|
||||
example = [ "josh" ];
|
||||
description = ''
|
||||
List of users to be added to the system.
|
||||
'';
|
||||
};
|
||||
primary = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = lib.optionalString (cfg.admins != [ ] && cfg.admins != null) (
|
||||
builtins.elemAt cfg.admins 0
|
||||
);
|
||||
description = "The primary user of the system.";
|
||||
};
|
||||
users = lib.mkOption {
|
||||
type = lib.types.attrsOf lib.types.attrs;
|
||||
default = { };
|
||||
description = "Normal users to configure (not for system users). Should match nix options of users.userser.<name>.*";
|
||||
};
|
||||
};
|
||||
config = {
|
||||
users.users = lib.mapAttrs (
|
||||
name: userConfig:
|
||||
userConfig
|
||||
// {
|
||||
inherit name;
|
||||
isNormalUser = true;
|
||||
# TODO
|
||||
# initialPassword = lib.mkIf (
|
||||
# userConfig.initialPassword != null
|
||||
# ) userConfig.initialPassword "password1";
|
||||
extraGroups =
|
||||
lib.optionals (builtins.elem name cfg.admins) [ "wheel" ] ++ (userConfig.extraGroups or [ ]);
|
||||
}
|
||||
) cfg.users;
|
||||
|
||||
programs.nh.flake = lib.mkIf (lib.hasAttr "primary" cfg) "/home/${cfg.primary}/.config/nixos-config/hosts/${top_cfg.systemName}";
|
||||
};
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
{
|
||||
username,
|
||||
}:
|
||||
{ config, ... }:
|
||||
{
|
||||
users.user.${username} = {
|
||||
|
||||
};
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
let
|
||||
ccfg = import ../config.nix;
|
||||
cfg_path = "${ccfg.custom_config_key}".users;
|
||||
cfg = config.${cfg_path};
|
||||
top_cfg = config."${ccfg.custom_config_key}";
|
||||
in
|
||||
{
|
||||
option.${cfg_path} = {
|
||||
adminUsers = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.str;
|
||||
default = [ ];
|
||||
example = [ "josh" ];
|
||||
description = ''
|
||||
List of users to be added to the system.
|
||||
'';
|
||||
};
|
||||
primaryUser = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = lib.optionalString (cfg.adminUsers != [ ] && cfg.adminUsers != null) (
|
||||
builtins.elemAt cfg.adminUsers 0
|
||||
);
|
||||
description = "The primary user of the system.";
|
||||
};
|
||||
users = lib.mkOption {
|
||||
type = lib.types.attrsOf lib.types.attrs;
|
||||
default = { };
|
||||
description = "Normal* users to configure (not for system users). Should match nix options of users.userser.<name>.*";
|
||||
};
|
||||
};
|
||||
config =
|
||||
{
|
||||
users.users = lib.mapAttrs (
|
||||
name: config:
|
||||
{
|
||||
inherit name;
|
||||
isNormalUser = true;
|
||||
}
|
||||
// config
|
||||
) cfg.users;
|
||||
|
||||
programs.nh.flake = "/home/${cfg.primaryUser}/.config/nixos-config/hosts/${top_cfg.systemName}";
|
||||
}
|
||||
// lib.map (name: {
|
||||
users.users.${name} = {
|
||||
extraGroups = [ "wheel" ];
|
||||
};
|
||||
}) cfg.adminUsers;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue