Merge remote-tracking branch 'origin/user-module-redesign' into user-module-redesign

This commit is contained in:
2025-12-17 16:19:14 -05:00
4 changed files with 32 additions and 30 deletions

View File

@@ -154,7 +154,7 @@ dotfiles/
{
# User account options (imported as NixOS module)
ugaif.users.myusername = {
ugaif.users.myuser = {
description = "My Full Name";
extraGroups = [ "wheel" "docker" ];
shell = pkgs.zsh;

View File

@@ -36,37 +36,37 @@ let
&& builtins.pathExists path;
# Extract ugaif.users options from external user.nix modules
externalUserOptions = lib.foldl' (
acc: item:
# First, build a cache of options per user from their external user.nix (if any).
externalUserModuleOptions = lib.genAttrs (lib.attrNames accounts) (
name:
let
name = item.name;
user = item.user;
user = accounts.${name};
externalPath = resolveExternalPath (user.external or null);
userNixPath = if externalPath != null then externalPath + "/user.nix" else null;
# Load the module and extract its ugaif.users options
moduleOptions =
if isValidPath userNixPath then
let
# Import and evaluate the module with minimal args
outerModule = import userNixPath { inherit inputs; };
evaluatedModule = outerModule {
config = { };
inherit lib pkgs;
osConfig = null;
};
# Extract just the ugaif.users.<name> options
ugaifUsers = evaluatedModule.ugaif.users or { };
userOptions = ugaifUsers.${name} or { };
in
userOptions
else
{ };
in
if moduleOptions != { } then acc // { ${name} = moduleOptions; } else acc
) { } (lib.mapAttrsToList (name: user: { inherit name user; }) accounts);
if isValidPath userNixPath then
let
# Import and evaluate the module with minimal args
outerModule = import userNixPath { inherit inputs; };
evaluatedModule = outerModule {
config = { };
inherit lib pkgs;
osConfig = null;
};
# Extract just the ugaif.users.<name> options
ugaifUsers = evaluatedModule.ugaif.users or { };
in
ugaifUsers.${name} or { }
else
{ }
);
# externalUserOptions only contains users that actually have options defined
externalUserOptions = lib.filterAttrs (_: moduleOptions: moduleOptions != { }) externalUserModuleOptions;
# Submodule defining the structure of a user account
userSubmodule = lib.types.submodule {
options = {
userSubmodule = lib.types.submodule {
options = {
isNormalUser = lib.mkOption {
@@ -245,7 +245,7 @@ in
;
};
in
lib.filterAttrs (name: _: name != "ugaif") evaluated
lib.filterAttrs (attrName: _: attrName != "ugaif") evaluated
else
{ };

View File

@@ -12,7 +12,8 @@
# - Installing system packages that require root
#
# Note: User options (description, shell, extraGroups, etc.) should be set
# in the main users.nix file, not here.
# in your external module's user.nix or in the main users.nix file, not in
# this nixos.nix.
#
# This module receives the same `inputs` flake inputs as the main
# nixos-systems configuration.

View File

@@ -8,8 +8,9 @@
# 2. Home-manager configuration (home.*, programs.*, services.*) when imported
# into home-manager
#
# This file is optional - if not present, these options should be set
# directly in the main users.nix file.
# This file is optional - if not present, the system will use the defaults
# from the main users.nix file. Use this file to override or extend those
# default user and home-manager options for this user.
#
# This module receives the same `inputs` flake inputs as the main
# nixos-systems configuration (nixpkgs, home-manager, etc.).