Merge remote-tracking branch 'origin/user-module-redesign' into user-module-redesign
This commit is contained in:
@@ -154,7 +154,7 @@ dotfiles/
|
|||||||
|
|
||||||
{
|
{
|
||||||
# User account options (imported as NixOS module)
|
# User account options (imported as NixOS module)
|
||||||
ugaif.users.myusername = {
|
ugaif.users.myuser = {
|
||||||
description = "My Full Name";
|
description = "My Full Name";
|
||||||
extraGroups = [ "wheel" "docker" ];
|
extraGroups = [ "wheel" "docker" ];
|
||||||
shell = pkgs.zsh;
|
shell = pkgs.zsh;
|
||||||
|
|||||||
@@ -36,37 +36,37 @@ let
|
|||||||
&& builtins.pathExists path;
|
&& builtins.pathExists path;
|
||||||
|
|
||||||
# Extract ugaif.users options from external user.nix modules
|
# Extract ugaif.users options from external user.nix modules
|
||||||
externalUserOptions = lib.foldl' (
|
# First, build a cache of options per user from their external user.nix (if any).
|
||||||
acc: item:
|
externalUserModuleOptions = lib.genAttrs (lib.attrNames accounts) (
|
||||||
|
name:
|
||||||
let
|
let
|
||||||
name = item.name;
|
user = accounts.${name};
|
||||||
user = item.user;
|
|
||||||
externalPath = resolveExternalPath (user.external or null);
|
externalPath = resolveExternalPath (user.external or null);
|
||||||
userNixPath = if externalPath != null then externalPath + "/user.nix" else 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
|
in
|
||||||
if moduleOptions != { } then acc // { ${name} = moduleOptions; } else acc
|
if isValidPath userNixPath then
|
||||||
) { } (lib.mapAttrsToList (name: user: { inherit name user; }) accounts);
|
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
|
# Submodule defining the structure of a user account
|
||||||
|
userSubmodule = lib.types.submodule {
|
||||||
|
options = {
|
||||||
userSubmodule = lib.types.submodule {
|
userSubmodule = lib.types.submodule {
|
||||||
options = {
|
options = {
|
||||||
isNormalUser = lib.mkOption {
|
isNormalUser = lib.mkOption {
|
||||||
@@ -245,7 +245,7 @@ in
|
|||||||
;
|
;
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
lib.filterAttrs (name: _: name != "ugaif") evaluated
|
lib.filterAttrs (attrName: _: attrName != "ugaif") evaluated
|
||||||
else
|
else
|
||||||
{ };
|
{ };
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,8 @@
|
|||||||
# - Installing system packages that require root
|
# - Installing system packages that require root
|
||||||
#
|
#
|
||||||
# Note: User options (description, shell, extraGroups, etc.) should be set
|
# 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
|
# This module receives the same `inputs` flake inputs as the main
|
||||||
# nixos-systems configuration.
|
# nixos-systems configuration.
|
||||||
|
|||||||
@@ -8,8 +8,9 @@
|
|||||||
# 2. Home-manager configuration (home.*, programs.*, services.*) when imported
|
# 2. Home-manager configuration (home.*, programs.*, services.*) when imported
|
||||||
# into home-manager
|
# into home-manager
|
||||||
#
|
#
|
||||||
# This file is optional - if not present, these options should be set
|
# This file is optional - if not present, the system will use the defaults
|
||||||
# directly in the main users.nix file.
|
# 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
|
# This module receives the same `inputs` flake inputs as the main
|
||||||
# nixos-systems configuration (nixpkgs, home-manager, etc.).
|
# nixos-systems configuration (nixpkgs, home-manager, etc.).
|
||||||
|
|||||||
Reference in New Issue
Block a user