mirror of
				https://github.com/Jokiller230/puzzlevision.git
				synced 2025-10-31 13:50:04 +00:00 
			
		
		
		
	🚧 Update user configuration loading and use formatter
This commit is contained in:
		
							parent
							
								
									cd32ad1c61
								
							
						
					
					
						commit
						54edba0070
					
				
					 12 changed files with 83 additions and 146 deletions
				
			
		
							
								
								
									
										6
									
								
								homes/x86_64-linux/cyn/default.nix
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								homes/x86_64-linux/cyn/default.nix
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,6 @@ | ||||||
|  | {pkgs, ...}: { | ||||||
|  |   home.packages = with pkgs; [ | ||||||
|  |     cowsay | ||||||
|  |     cmatrix | ||||||
|  |   ]; | ||||||
|  | } | ||||||
|  | @ -1,8 +1,13 @@ | ||||||
| { lib, self, ... }: { | { | ||||||
|  |   lib, | ||||||
|  |   self, | ||||||
|  |   ... | ||||||
|  | }: { | ||||||
|   # Create a NixOS module option on a single line. |   # Create a NixOS module option on a single line. | ||||||
|   mkOpt = type: default: description: |   mkOpt = type: default: description: | ||||||
|     lib.mkOption {inherit type default description;}; |     lib.mkOption {inherit type default description;}; | ||||||
| 
 | 
 | ||||||
|  |   # Create a simple bool options | ||||||
|   mkBool = default: description: |   mkBool = default: description: | ||||||
|     lib.mkOption { |     lib.mkOption { | ||||||
|       inherit default description; |       inherit default description; | ||||||
|  | @ -10,18 +15,15 @@ | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|   # Create a module compliant with the NixOS module system. |   # Create a module compliant with the NixOS module system. | ||||||
|   mkModule = |   mkModule = { | ||||||
|     { |  | ||||||
|     name ? "puzzlevision", |     name ? "puzzlevision", | ||||||
|     class, |     class, | ||||||
|     modules, |     modules, | ||||||
|   }: { |   }: { | ||||||
|     _class = class; |     _class = class; | ||||||
| 
 |  | ||||||
|     # Template: "[path-to-flake]/flake.nix#[class-name]Modules.[module-name]" |     # Template: "[path-to-flake]/flake.nix#[class-name]Modules.[module-name]" | ||||||
|     # Example: "[path-to-flake]/flake.nix#nixosModules.system.audio" |     # Example: "[path-to-flake]/flake.nix#nixosModules.system.audio" | ||||||
|     _file = "${self.outPath}/flake.nix#${class}Modules.${name}"; |     _file = "${self.outPath}/flake.nix#${class}Modules.${name}"; | ||||||
| 
 |  | ||||||
|     imports = modules; |     imports = modules; | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -6,13 +6,7 @@ | ||||||
|     # Automagically imports libs from "/lib/lib-name" and exposes them to the `flake.lib` output. |     # Automagically imports libs from "/lib/lib-name" and exposes them to the `flake.lib` output. | ||||||
|     ./lib.nix |     ./lib.nix | ||||||
| 
 | 
 | ||||||
|     # Recursively imports overlays from "/overlays/overlay-name" and exposes them to the `flake.overlays` output. |  | ||||||
|     #./overlays.nix |  | ||||||
| 
 |  | ||||||
|     # Automagically imports systems from "/systems/arch-classname/system-name". |     # Automagically imports systems from "/systems/arch-classname/system-name". | ||||||
|     ./systems.nix |     ./systems.nix | ||||||
| 
 |  | ||||||
|     # Automagically imports homes from "/homes/user-name". |  | ||||||
|     #./homes.nix |  | ||||||
|   ]; |   ]; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,10 +1,10 @@ | ||||||
| { self, ... }: | {self, ...}: { | ||||||
| { |  | ||||||
|   flake = { |   flake = { | ||||||
|     #nixosModules.puzzlevision = self.lib.mkModule { |     # TODO: figure out why this isn't working correctly | ||||||
|     #  class = "nixos"; |     nixosModules.puzzlevision = self.lib.mkModule { | ||||||
|     #  modules = self.lib.dirToModuleList ../nixos; |       class = "nixos"; | ||||||
|     #}; |       modules = self.lib.dirToModuleList ../nixos; | ||||||
|  |     }; | ||||||
| 
 | 
 | ||||||
|     homeModules.puzzlevision = self.lib.mkModule { |     homeModules.puzzlevision = self.lib.mkModule { | ||||||
|       class = "home"; |       class = "home"; | ||||||
|  |  | ||||||
|  | @ -1,10 +1,12 @@ | ||||||
| { | { | ||||||
|   lib, |   lib, | ||||||
|   inputs, |  | ||||||
|   self, |   self, | ||||||
|  |   inputs, | ||||||
|   ... |   ... | ||||||
| }: { | }: { | ||||||
|   imports = [ inputs.easy-hosts.flakeModule ]; |   imports = [ | ||||||
|  |     inputs.easy-hosts.flakeModule | ||||||
|  |   ]; | ||||||
| 
 | 
 | ||||||
|   easyHosts = { |   easyHosts = { | ||||||
|     autoConstruct = true; |     autoConstruct = true; | ||||||
|  |  | ||||||
							
								
								
									
										2
									
								
								modules/home/default.nix
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								modules/home/default.nix
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,2 @@ | ||||||
|  | {...}: { | ||||||
|  | } | ||||||
|  | @ -1,33 +0,0 @@ | ||||||
| { |  | ||||||
|   lib, |  | ||||||
|   pkgs, |  | ||||||
|   self, |  | ||||||
|   config, |  | ||||||
|   osConfig, |  | ||||||
|   ... |  | ||||||
| }: let |  | ||||||
|   inherit (lib) mkIf mkOption; |  | ||||||
|   inherit (self) namespace; |  | ||||||
| 
 |  | ||||||
|   cfg = config.${namespace}.desktop.gnome; |  | ||||||
| in { |  | ||||||
|   options.${namespace}.desktop.gnome = with lib.types; { |  | ||||||
|     enabled-extensions = mkOption { |  | ||||||
|       type = listOf package; |  | ||||||
|       default = with pkgs.gnomeExtensions; [dash-to-dock user-themes blur-my-shell appindicator unite color-picker clipboard-history]; |  | ||||||
|       example = [dash-to-dock blur-my-shell]; |  | ||||||
|       description = "Specify gnome extensions to install."; |  | ||||||
|     }; |  | ||||||
|   }; |  | ||||||
| 
 |  | ||||||
|   config = mkIf osConfig.${namespace}.desktop.gnome.enable { |  | ||||||
|     home.packages = cfg.enabled-extensions; |  | ||||||
| 
 |  | ||||||
|     dconf.settings = { |  | ||||||
|       "org/gnome/shell" = { |  | ||||||
|         enabled-extensions = lib.forEach cfg.enabled-extensions (x: x.extensionUuid); |  | ||||||
|         disabled-extensions = []; # Make sure none of our extensions are disabled on system rebuild |  | ||||||
|       }; |  | ||||||
|     }; |  | ||||||
|   }; |  | ||||||
| } |  | ||||||
|  | @ -9,7 +9,9 @@ | ||||||
| 
 | 
 | ||||||
|   cfg = config.${namespace}.desktop.gnome; |   cfg = config.${namespace}.desktop.gnome; | ||||||
| in { | 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 { |   config = mkIf cfg.enable { | ||||||
|     services.xserver.enable = true; |     services.xserver.enable = true; | ||||||
|  |  | ||||||
|  | @ -3,14 +3,15 @@ | ||||||
|   self, |   self, | ||||||
|   config, |   config, | ||||||
|   ... |   ... | ||||||
| }: | }: let | ||||||
| let |  | ||||||
|   inherit (lib) mkEnableOption mkIf; |   inherit (lib) mkEnableOption mkIf; | ||||||
|   inherit (self) namespace; |   inherit (self) namespace; | ||||||
| 
 | 
 | ||||||
|   cfg = config.${namespace}.common.grub; |   cfg = config.${namespace}.system.grub; | ||||||
| in { | in { | ||||||
|   options.${namespace}.common.grub = { enable = mkEnableOption "grub"; }; |   options.${namespace}.system.grub = { | ||||||
|  |     enable = mkEnableOption "the grub bootloader."; | ||||||
|  |   }; | ||||||
| 
 | 
 | ||||||
|   config = mkIf cfg.enable { |   config = mkIf cfg.enable { | ||||||
|     boot.loader.systemd-boot.enable = false; |     boot.loader.systemd-boot.enable = false; | ||||||
|  | @ -1,81 +1,75 @@ | ||||||
| { | { | ||||||
|   lib, |   lib, | ||||||
|   config, |  | ||||||
|   self, |   self, | ||||||
|   pkgs, |   pkgs, | ||||||
|  |   config, | ||||||
|   ... |   ... | ||||||
| }: let | }: let | ||||||
|   inherit (lib) mkEnableOption mkIf mkOption types; |   inherit (lib) types mkEnableOption mkOption mkIf; | ||||||
|   inherit (self) namespace; |   inherit (self) namespace; | ||||||
|   inherit (self.lib) mkOpt dirToModuleList; |   inherit (self.lib) dirToModuleList; | ||||||
| 
 |  | ||||||
|   cfg = config.${namespace}.users; |  | ||||||
| 
 | 
 | ||||||
|   # The identifier of the current system type, e.g. "x86_64-linux" or "aarch64-darwin" |   # The identifier of the current system type, e.g. "x86_64-linux" or "aarch64-darwin" | ||||||
|   system = pkgs.system; |   system = pkgs.system; | ||||||
|  |   cfg = config.${namespace}.users; | ||||||
| 
 | 
 | ||||||
|   # Type for a user configuration |   userSubmodule = types.submodule { | ||||||
|   userType = types.submodule { |  | ||||||
|     options = { |     options = { | ||||||
|       enable = mkEnableOption "this user"; |       enable = mkEnableOption "this user."; | ||||||
|       initialPassword = mkOpt (types.nullOr types.str) null "Initial password for the user"; |       isNormalUser = self.lib.mkBool true "Whether this user is considered a normal user."; | ||||||
|       password = mkOpt (types.nullOr types.str) null "Plaintext password for the user"; |       isSystemUser = self.lib.mkBool false "Whether this user is considered a system user."; | ||||||
|       hashedPassword = mkOpt (types.nullOr types.str) null "Hashed password for the user"; |       initialPassword = self.lib.mkOpt (types.nullOr types.str) null "Plaintext insecure initial user password, only recommended for testing."; | ||||||
|       isNormalUser = mkOpt types.bool true "Whether this user is a normal user"; |       password = self.lib.mkOpt (types.nullOr types.str) null "Plaintext insecure user password, only recommended for testing."; | ||||||
|       extraGroups = mkOpt (types.listOf types.str) [] "Extra groups for the user"; |       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}"; |   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"; |   homeModules = dirToModuleList "${self.outPath}/modules/home"; | ||||||
| in { | in { | ||||||
|   options.${namespace}.users = mkOption { |   options.${namespace}.users = mkOption { | ||||||
|     type = types.attrsOf userType; |     type = types.attrsOf userSubmodule; | ||||||
|     default = {}; |     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 = { |   config = { | ||||||
|     # Ensure users are fully managed by NixOS |     # Manage users declaratively and map userConfig to users.users by name; | ||||||
|     users.mutableUsers = false; |     users.mutableUsers = false; | ||||||
| 
 |  | ||||||
|     # Create the actual system users |  | ||||||
|     users.users = lib.mapAttrs (username: userConfig: |     users.users = lib.mapAttrs (username: userConfig: | ||||||
|       mkIf userConfig.enable { |       mkIf userConfig.enable { | ||||||
|         name = username; |         name = username; | ||||||
|         inherit (userConfig) extraGroups initialPassword hashedPassword isNormalUser password; |         inherit (userConfig) isNormalUser isSystemUser initialPassword password extraGroups; | ||||||
|       } |       }) | ||||||
|     ) cfg; |     cfg; | ||||||
| 
 | 
 | ||||||
|     # Configure home-manager with auto-imported user configuration |  | ||||||
|     home-manager = { |     home-manager = { | ||||||
|       useGlobalPkgs = true; |       useGlobalPkgs = true; | ||||||
|       useUserPackages = true; |       useUserPackages = true; | ||||||
| 
 | 
 | ||||||
|       extraSpecialArgs = { |       extraSpecialArgs = { | ||||||
|         inherit self; |         inherit self system; | ||||||
|         namespace = self.namespace; |         namespace = self.namespace; | ||||||
|       }; |       }; | ||||||
| 
 | 
 | ||||||
|       users = lib.mapAttrs (username: userConfig: |       users = | ||||||
|  |         lib.mapAttrs ( | ||||||
|  |           username: userConfig: | ||||||
|             mkIf (userConfig.enable && homeConfigExists username) ( |             mkIf (userConfig.enable && homeConfigExists username) ( | ||||||
|           { ... }: { |               {osConfig, ...}: { | ||||||
|             imports = [ |                 # Import user home configuration and general home modules | ||||||
|               (getHomeConfigPath username) # Import the user's specific home configuration |                 imports = [(getHomeConfigPath username)] ++ homeModules; | ||||||
|             ]; #++ homeModules; # Include all generalized home modules |  | ||||||
| 
 | 
 | ||||||
|             home.stateVersion = lib.mkDefault config.system.stateVersion; |                 home.stateVersion = lib.mkDefault osConfig.system.stateVersion; | ||||||
|               } |               } | ||||||
|             ) |             ) | ||||||
|       ) cfg; |         ) | ||||||
|  |         cfg; | ||||||
|     }; |     }; | ||||||
|   }; |   }; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -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; |  | ||||||
|       }; |  | ||||||
|     }; |  | ||||||
|   }; |  | ||||||
| } |  | ||||||
|  | @ -1,24 +1,17 @@ | ||||||
| { | {pkgs, ...}: { | ||||||
|   pkgs, |  | ||||||
|   ... |  | ||||||
| }: { |  | ||||||
|   imports = [ |   imports = [ | ||||||
|     ./hardware.nix |     ./hardware.nix | ||||||
|   ]; |   ]; | ||||||
| 
 | 
 | ||||||
|   puzzlevision = { |   puzzlevision = { | ||||||
|     # TODO: improve home-manager configuration loading as development continues and make sure everything works correctly. |     users.cyn = { | ||||||
|     users = { |  | ||||||
|       jo = { |  | ||||||
|       enable = true; |       enable = true; | ||||||
|         initialPassword = "balls"; |       password = "cynical"; # For testing only, replace with sops secret before production use | ||||||
|       extraGroups = ["wheel"]; |       extraGroups = ["wheel"]; | ||||||
|     }; |     }; | ||||||
|     }; |  | ||||||
| 
 | 
 | ||||||
|     desktop.gnome.enable = true; |     desktop.gnome.enable = true; | ||||||
|     utils.vm.enable = true; |     system.grub.enable = true; | ||||||
|     common.grub.enable = true; |  | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   environment.systemPackages = with pkgs; [ |   environment.systemPackages = with pkgs; [ | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue