🚧 Update user configuration loading and use formatter

This commit is contained in:
Jo 2025-04-26 23:08:11 +02:00
parent cd32ad1c61
commit 54edba0070
12 changed files with 83 additions and 146 deletions

View file

@ -9,7 +9,9 @@
cfg = config.${namespace}.desktop.gnome;
in {
options.${namespace}.desktop.gnome = {enable = mkEnableOption "Enable the gnome desktop environment ${namespace}";};
options.${namespace}.desktop.gnome = {
enable = mkEnableOption "the gnome desktop environment";
};
config = mkIf cfg.enable {
services.xserver.enable = true;

View file

@ -3,21 +3,22 @@
self,
config,
...
}:
let
}: let
inherit (lib) mkEnableOption mkIf;
inherit (self) namespace;
cfg = config.${namespace}.common.grub;
cfg = config.${namespace}.system.grub;
in {
options.${namespace}.common.grub = { enable = mkEnableOption "grub"; };
options.${namespace}.system.grub = {
enable = mkEnableOption "the grub bootloader.";
};
config = mkIf cfg.enable {
boot.loader.systemd-boot.enable = false;
boot.loader.grub = {
enable = true;
devices = [ "nodev" ];
devices = ["nodev"];
efiInstallAsRemovable = true;
efiSupport = true;

View file

@ -1,81 +1,75 @@
{
lib,
config,
self,
pkgs,
config,
...
}: let
inherit (lib) mkEnableOption mkIf mkOption types;
inherit (lib) types mkEnableOption mkOption mkIf;
inherit (self) namespace;
inherit (self.lib) mkOpt dirToModuleList;
cfg = config.${namespace}.users;
inherit (self.lib) dirToModuleList;
# The identifier of the current system type, e.g. "x86_64-linux" or "aarch64-darwin"
system = pkgs.system;
cfg = config.${namespace}.users;
# Type for a user configuration
userType = types.submodule {
userSubmodule = types.submodule {
options = {
enable = mkEnableOption "this user";
initialPassword = mkOpt (types.nullOr types.str) null "Initial password for the user";
password = mkOpt (types.nullOr types.str) null "Plaintext password for the user";
hashedPassword = mkOpt (types.nullOr types.str) null "Hashed password for the user";
isNormalUser = mkOpt types.bool true "Whether this user is a normal user";
extraGroups = mkOpt (types.listOf types.str) [] "Extra groups for the user";
enable = mkEnableOption "this user.";
isNormalUser = self.lib.mkBool true "Whether this user is considered a normal user.";
isSystemUser = self.lib.mkBool false "Whether this user is considered a system user.";
initialPassword = self.lib.mkOpt (types.nullOr types.str) null "Plaintext insecure initial user password, only recommended for testing.";
password = self.lib.mkOpt (types.nullOr types.str) null "Plaintext insecure user password, only recommended for testing.";
extraGroups = self.lib.mkOpt (types.listOf types.str) [] "List of additional groups this user belongs to.";
};
};
# Function to get home configuration path for a username
getHomeConfigPath = username: "${self.outPath}/homes/${system}/${username}";
homeConfigExists = username: let
path = getHomeConfigPath username;
in
builtins.pathExists "${path}/default.nix";
# Function to check if a home configuration exists for a username
homeConfigExists = username:
let path = getHomeConfigPath username;
in builtins.pathExists "${path}/default.nix";
# Import all home-manager modules
homeModules = dirToModuleList "${self.outPath}/modules/home";
in {
options.${namespace}.users = mkOption {
type = types.attrsOf userType;
type = types.attrsOf userSubmodule;
default = {};
description = "User configurations with auto-imported home-manager setup";
description = "List of users to create. Also handles home configurations, placed in self.outPath/homes/[x86_64-linux, aarch64-linux, etc...], through home-manager.";
};
config = {
# Ensure users are fully managed by NixOS
# Manage users declaratively and map userConfig to users.users by name;
users.mutableUsers = false;
# Create the actual system users
users.users = lib.mapAttrs (username: userConfig:
mkIf userConfig.enable {
name = username;
inherit (userConfig) extraGroups initialPassword hashedPassword isNormalUser password;
}
) cfg;
inherit (userConfig) isNormalUser isSystemUser initialPassword password extraGroups;
})
cfg;
# Configure home-manager with auto-imported user configuration
home-manager = {
useGlobalPkgs = true;
useUserPackages = true;
extraSpecialArgs = {
inherit self;
inherit self system;
namespace = self.namespace;
};
users = lib.mapAttrs (username: userConfig:
mkIf (userConfig.enable && homeConfigExists username) (
{ ... }: {
imports = [
(getHomeConfigPath username) # Import the user's specific home configuration
]; #++ homeModules; # Include all generalized home modules
users =
lib.mapAttrs (
username: userConfig:
mkIf (userConfig.enable && homeConfigExists username) (
{osConfig, ...}: {
# Import user home configuration and general home modules
imports = [(getHomeConfigPath username)] ++ homeModules;
home.stateVersion = lib.mkDefault config.system.stateVersion;
}
home.stateVersion = lib.mkDefault osConfig.system.stateVersion;
}
)
)
) cfg;
cfg;
};
};
}

View file

@ -1,26 +0,0 @@
{
lib,
config,
self,
...
}: let
inherit (lib) mkIf;
inherit (self) namespace;
cfg = config.${namespace}.utils.vm;
in {
options.${namespace}.utils.vm = {
enable = self.lib.mkBool true "Whether to enable custom vm presets";
preset = self.lib.mkOpt lib.types.str "performance" "Specify the prefered vm settings preset: performance, balance or powersave";
};
config = mkIf cfg.enable {
virtualisation.vmVariant = {
virtualisation = {
cores = 6;
memorySize = 4096;
graphics = true;
};
};
};
}