mirror of
				https://github.com/Jokiller230/puzzlevision.git
				synced 2025-10-31 13:50:04 +00:00 
			
		
		
		
	✨ (modules/flake) implement recursively loaded libraries
This commit is contained in:
		
							parent
							
								
									e54b87a835
								
							
						
					
					
						commit
						c322461fe1
					
				
					 4 changed files with 56 additions and 2 deletions
				
			
		|  | @ -1,13 +1,44 @@ | |||
| { | ||||
|   lib, | ||||
|   inputs, | ||||
|   config, | ||||
|   ... | ||||
| }: | ||||
| let | ||||
|   # Recursive function to load all `default.nix` files and merge them into a single attr. set | ||||
|   loadLibs = directory: | ||||
|     builtins.foldl' (acc: name: | ||||
|       let | ||||
|         path = "${directory}/${name}"; | ||||
|         isDir = (builtins.getAttr name (builtins.readDir directory)) == "directory"; | ||||
|       in | ||||
|         if isDir then | ||||
|           lib.mergeAttrs acc (loadLibs path) | ||||
|         else if name == "default.nix" then | ||||
|           lib.mergeAttrs acc (import path { inherit lib; }) | ||||
|         else | ||||
|           acc | ||||
|     ) {} (builtins.attrNames (builtins.readDir directory)); | ||||
| in | ||||
| { | ||||
|   # Overwrite and add new arguments to all flake modules. | ||||
|   _module.args = { | ||||
|     namespace = config.flake.namespace; | ||||
| 
 | ||||
|     ## Recursive loading of libraries, similar to snowfall lib. | ||||
|     ## Logical flow: read files => merge all file outputs to single attr. set | ||||
|     ## The directory in question is flake-root => lib | ||||
|     ## The directory structure is: | ||||
|     ## lib/ | ||||
|     ##   => libname | ||||
|     ##     => default.nix | ||||
|     ##   => libname2 | ||||
|     ##     => default.nix | ||||
|     ## | ||||
|     ## The structure of multiple libs is simply for organization and the attrs. of all default.nix files should still be merged | ||||
|     ## into a single set. | ||||
|     puzzlelib = loadLibs ../../lib; | ||||
| 
 | ||||
|     # Initialize nixpkgs instance with custom overlays. | ||||
|     pkgs = import inputs.nixpkgs { | ||||
|       overlays = [ | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue