change how enabled users are handled

This commit is contained in:
UGA Innovation Factory
2025-12-16 14:35:02 -05:00
parent a43dfea615
commit adb98c4136
3 changed files with 30 additions and 32 deletions

View File

@@ -43,7 +43,7 @@ let
# Load users.nix to find external user flakes # Load users.nix to find external user flakes
pkgs = nixpkgs.legacyPackages.${system}; pkgs = nixpkgs.legacyPackages.${system};
usersData = import ../users.nix { inherit pkgs; }; usersData = import ../users.nix { inherit pkgs; };
accounts = usersData.ugaif.users.accounts or { }; accounts = usersData.ugaif.users or { };
# Extract flakeUrls and convert to modules # Extract flakeUrls and convert to modules
userFlakeModules = lib.mapAttrsToList ( userFlakeModules = lib.mapAttrsToList (
@@ -87,7 +87,8 @@ let
]; ];
specialConfig = lib.mkMerge [ specialConfig = lib.mkMerge [
(lib.optionalAttrs (configOverrides ? extraUsers) { (lib.optionalAttrs (configOverrides ? extraUsers) {
ugaif.users.enabledUsers = configOverrides.extraUsers; # Enable each user in the extraUsers list
ugaif.users = lib.genAttrs configOverrides.extraUsers (_: { enable = true; });
}) })
(lib.optionalAttrs (configOverrides ? buildMethods) { (lib.optionalAttrs (configOverrides ? buildMethods) {
ugaif.host.buildMethods = configOverrides.buildMethods; ugaif.host.buildMethods = configOverrides.buildMethods;

View File

@@ -64,6 +64,11 @@ let
default = null; default = null;
description = "The shell for this user."; description = "The shell for this user.";
}; };
editor = lib.mkOption {
type = lib.types.nullOr lib.types.package;
default = null;
description = "The default editor for this user.";
};
useZshTheme = lib.mkOption { useZshTheme = lib.mkOption {
type = lib.types.bool; type = lib.types.bool;
default = true; default = true;
@@ -74,42 +79,31 @@ let
default = true; default = true;
description = "Whether to apply the system Neovim configuration."; description = "Whether to apply the system Neovim configuration.";
}; };
enable = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether this user account is enabled on this system.";
};
}; };
}; };
in in
{ {
options.ugaif.users = { options.ugaif.users = lib.mkOption {
shell = lib.mkOption { type = lib.types.attrsOf userSubmodule;
type = lib.types.package; default = { };
default = pkgs.bash; description = "User accounts configuration. Set enable=true for users that should exist on this system.";
description = "The default shell for users.";
};
accounts = lib.mkOption {
type = lib.types.attrsOf userSubmodule;
default = { };
description = "User accounts configuration.";
};
enabledUsers = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ ];
description = "List of users to enable on this system.";
};
}; };
config = { config = {
# Default enabled users (always present) # Enable forUser if specified
ugaif.users.enabledUsers = [ ugaif.users = lib.mkIf (config.ugaif.forUser != null) {
"root" ${config.ugaif.forUser}.enable = true;
"engr-ugaif" };
]
++ lib.optional (config.ugaif.forUser != null) config.ugaif.forUser;
# Generate NixOS users # Generate NixOS users
users.users = users.users =
let let
enabledAccounts = lib.filterAttrs ( enabledAccounts = lib.filterAttrs (_: user: user.enable) config.ugaif.users;
name: _: lib.elem name config.ugaif.users.enabledUsers
) config.ugaif.users.accounts;
in in
lib.mapAttrs ( lib.mapAttrs (
name: user: name: user:
@@ -123,7 +117,7 @@ in
description = if user.description != null then user.description else lib.mkDefault ""; description = if user.description != null then user.description else lib.mkDefault "";
openssh.authorizedKeys.keys = user.opensshKeys; openssh.authorizedKeys.keys = user.opensshKeys;
packages = finalPackages; packages = finalPackages;
shell = if user.shell != null then user.shell else config.ugaif.users.shell; shell = if user.shell != null then user.shell else pkgs.bash;
} }
) enabledAccounts; ) enabledAccounts;
@@ -138,9 +132,7 @@ in
users = users =
let let
enabledAccounts = lib.filterAttrs ( enabledAccounts = lib.filterAttrs (_: user: user.enable) config.ugaif.users;
name: _: lib.elem name config.ugaif.users.enabledUsers
) config.ugaif.users.accounts;
in in
lib.mapAttrs ( lib.mapAttrs (
name: user: name: user:

View File

@@ -9,10 +9,12 @@
# Define the users here using the new option # Define the users here using the new option
# To generate a password hash, run: mkpasswd -m sha-512 # To generate a password hash, run: mkpasswd -m sha-512
ugaif.users.accounts = { # Set enabled = true on systems where the user should exist
ugaif.users = {
root = { root = {
isNormalUser = false; isNormalUser = false;
hashedPassword = "!"; hashedPassword = "!";
enable = true; # Root is always enabled
}; };
engr-ugaif = { engr-ugaif = {
description = "UGA Innovation Factory"; description = "UGA Innovation Factory";
@@ -26,6 +28,7 @@
opensshKeys = [ opensshKeys = [
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBC7xzHxY2BfFUybMvG4wHSF9oEAGzRiLTFEndLvWV/X hdh20267@engr733847d.engr.uga.edu" "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBC7xzHxY2BfFUybMvG4wHSF9oEAGzRiLTFEndLvWV/X hdh20267@engr733847d.engr.uga.edu"
]; ];
enable = true; # Default user, enabled everywhere
}; };
hdh20267 = { hdh20267 = {
description = "Hunter Halloran"; description = "Hunter Halloran";
@@ -37,6 +40,7 @@
shell = pkgs.zsh; shell = pkgs.zsh;
# Example of using an external flake for configuration: # Example of using an external flake for configuration:
# flakeUrl = "github:hdh20267/dotfiles"; # flakeUrl = "github:hdh20267/dotfiles";
# enable = false by default, set to true per-system
}; };
sv22900 = { sv22900 = {
description = "Alireza Vaezi"; description = "Alireza Vaezi";
@@ -45,6 +49,7 @@
"wheel" "wheel"
]; ];
shell = pkgs.zsh; shell = pkgs.zsh;
# enable = false by default, set to true per-system
}; };
}; };
} }